Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

to-string do question?

 [1/13] from: bry::itnisk::com at: 22-Jul-2003 12:10


I would like to do a string, the result of that do operation I would then like to convert to-string. From the console
>> thisstring: "1 + 5"
== "1 + 5"
>> do thisstring
== 6
>> thisstring: "write %newfile.txt read %result.txt"
== "write %newfile.txt read %result.txt"
>> do thisstring >> thisstring: "1 + 5"
== "1 + 5"
>> to-string do thisstring
== "6"
>> thisstring: "write %newfile.txt read %result.txt"
== "write %newfile.txt read %result.txt"
>> to-string do thisstring
** Script Error: to-string is missing its value argument ** Where: halt-view ** Near: to-string do thisstring
>>
so what I would like is someway of having do return "True" or "False" if do does not produce any output. I was thinking it might be possible to have a function that did the following: if do returns error returnstring = "False" else if to-string do thisstring returns error then returnstring = "True" else returnstring = to-string do thisstring. However I wanted to ask before I start writing the code as I thought I might be missing something.

 [2/13] from: g:santilli:tiscalinet:it at: 22-Jul-2003 12:23


Hi Bryan, On Tuesday, July 22, 2003, 12:10:15 PM, you wrote:
>>> to-string do thisstring
b> ** Script Error: to-string is missing its value argument b> ** Where: halt-view b> ** Near: to-string do thisstring Try with: to string! do thisstring Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [3/13] from: bry:itnisk at: 22-Jul-2003 13:38


>Try with: > to string! do thisstring
actually I tried with: if error? try[returnstring: to-string do f1/text][returnstring: "True" [if/else error? try[do f1/text][returnstring: False ]] is that wrong anywhere?

 [4/13] from: g:santilli:tiscalinet:it at: 22-Jul-2003 14:14


Hi Bryan, On Tuesday, July 22, 2003, 1:38:58 PM, you wrote: b> actually I tried with: b> if error? try[returnstring: to-string do f1/text][returnstring: "True" b> [if/else error? try[do f1/text][returnstring: b> "False"]] b> is that wrong anywhere? I think you have IF and IF/ELSE swapped. Anyway, I'd do it as: returnstring: either error? try [set/any 'value do f1/text] [ "False" ] [ either value? 'value [to string! :value] ["True"] ] (BTW, why do you need it that way?) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [5/13] from: carl::cybercraft::co::nz at: 24-Dec-2003 22:24


On 23-Jul-03, bryan wrote:
>> Try with: >> to string! do thisstring
<<quoted lines omitted: 3>>
> "False"]] > is that wrong anywhere?
I'm not sure what the... [if/else error? try[do f1/text][returnstring: "False"] block is for, as I can't see that it'd ever be evaluated. Blocks within a block being evaluated are not evaluated in REBOL unless forced to by a do or other means. ie...
>> do [print 1 [print 2] print 3]
1 3
>> do [print 1 do [print 2] print 3]
1 2 3 If you want to capture true or false as well as returnstring (when there's no error), I'd use something like this... err: error? try[returnstring: to-string do f1/text] err would then contain true or false and returnstring whatever the result of the do is if there wasn't an error. (Incidentally, if/else is deprecated in REBOL - 'either is the prefered word to use.) -- Carl Read

 [6/13] from: bry:itnisk at: 22-Jul-2003 14:58


[ I'm not sure what the... [if/else error? try[do f1/text][returnstring: "False"] block is for, as I can't see that it'd ever be evaluated. Blocks within a block being evaluated are not evaluated in REBOL unless forced to by a do or other means. ie... If you want to capture true or false as well as returnstring (when there's no error), I'd use something like this... err: error? try[returnstring: to-string do f1/text] err would then contain true or false and returnstring whatever the result of the do is if there wasn't an error. ] okay I've tried that, seems to have a problem though, if what is being done is write %newfile.txt read %rlt.txt and rlt.txt does not exist then err does not have a value. Gabriele asked what I was trying to do, this goes back to my discussion a long time ago about asynchronous pluggable protocols(windows) and using them from rebol. I'm implementing and writing a little article on such a protocol, so what happens is that one calls the protocol from a link on a html page, for example <a href="reb://write %newfile.txt read %result.txt/">read local file</a> the protocol gets passed to a rebol script loaded by rebol.exe for evaluation, the script has a view layout and an area(f1) in it for display of the protocol body, if you click a do button I want the following sequence to happen: the result of doing f1/text is written to the field f2. If the protocol is reb://1 + 7 then what gets written to field f2 is 8. So if f1/text = read dsisdfa that should raise an error because dsisdfa is not a file url object or block, and of course dsisdfa has no value whatsoever, not having been declared anywhere. If on the other hand the string I have is doable but the output from it is not something that can be written to f2 then I need to return the string true, i.e we did the script but there is no output. I have most of this implemented, just not the proper error handling for the case if someone sends nonsense such as read dsisdfa in the protocol. Using the above err seems to return true for read dsisdfa.

 [7/13] from: g:santilli:tiscalinet:it at: 22-Jul-2003 15:22


Hi Bryan, On Tuesday, July 22, 2003, 2:58:47 PM, you wrote: b> If the protocol is reb://1 + 7 then what gets written to field f2 is 8. b> So if f1/text = read dsisdfa that should raise an error because dsisdfa b> is not a file url object or block, and of course dsisdfa has no value b> whatsoever, not having been declared anywhere. Try this: form-error: func [errobj /local txt] [ txt: get in get in system/error errobj/type errobj/id either block? txt [ txt: bind/copy txt in errobj 'self reform txt ] [txt] ] view layout [ inp: field 500 [ out/text: either error? set/any 'err try [do inp/text] [ form-error disarm err ] [ to string! get/any 'err ] show out ] out: info 500x300 ] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [8/13] from: bry:itnisk at: 22-Jul-2003 15:53


>Try this: >form-error: func [errobj /local txt] [
<<quoted lines omitted: 15>>
> out: info 500x300 >]
that's cool, but a little bit too intense for an article on asynchronous pluggable protocols that also has uses some simple rebol scripting in it :) I guess I'm gonna go with: err: error? try[returnstring: to-string do f1/text] either err = true[ append f2/text "No string output returned" show f2][append f2/text returnstring show f2] and say that's it. After all I'm already showing how to extend any url aware windows app with rebol, so I can slip a bit on the application.

 [9/13] from: bry:itnisk at: 22-Jul-2003 16:10


As Carl pointed out -> err: error? try[returnstring: to-string do f1/text]

 [10/13] from: carl:cybercraft at: 24-Dec-2003 22:24


On 23-Jul-03, bryan wrote:
> [ > I'm not sure what the...
<<quoted lines omitted: 11>>
> being done is write %newfile.txt read %rlt.txt and rlt.txt does not > exist then err does not have a value.
Are you sure?
>> read %rlt.txt
** Access Error: Cannot open /rebol/rlt.txt ** Near: read %rlt.txt (just to show %rlt.txt doesn't exist. So...)
>> err: error? try [
[ returnstring: to-string do "write %newfile.txt read %rlt.txt" [ ] == true
>> ? err
ERR is a logic of value: true Isn't that what you get? Or have I misunderstood something? -- Carl Read

 [11/13] from: carl:cybercraft at: 24-Dec-2003 22:24


On 23-Jul-03, bryan wrote:
> I guess I'm gonna go with: > err: error? try[returnstring: to-string do f1/text]
<<quoted lines omitted: 5>>
> url aware windows app with rebol, so I can slip a bit on the > application.
You could shorten the above to... either error? try [returnstring: to-string do f1/text][ append f2/text "No string output returned" show f2 ][ append f2/text returnstring show f2 ] assuming you don't need to keep the 'err value. If you do, you could still capture it using... either err: error? try [returnstring: to-string do f1/text][ ...etc... Hmm - and shorter still... append f2/text either error? try [returnstring: to-string do f1/text][ "No string output returned" ][ returnstring ] show f2 Cuts out the duplication of 'append and 'show. -- Carl Read

 [12/13] from: bry:itnisk at: 23-Jul-2003 11:15


[>> err: error? try [ [ returnstring: to-string do "write %newfile.txt read %rlt.txt" [ ] == true
>> ? err
ERR is a logic of value: true Isn't that what you get? Or have I misunderstood something? ] yeah that is what I was getting but the error handling I was looking for was a little finer grained. Basically what I want to do is to: do thestring thestring could be many different things, it could be nonsense such as uauiouasdhis which is an error because I have not set that word to be anything or it could be "write %newfile.txt read %rlt.txt" which is an error because %rlt.txt doesn't exist or it could be "write %newfile.txt read %oldfile.txt" which is not an error but does not allow one to change the result of do to-string and it could be "1 + 4" which is correct and does allow one to change the result of the do to a string. See the problem is that the error 'to-string do thestring' can be a different error than 'do thestring'. I obviously don't want to check to see if 'do thestring' raises an error and if it does not then check if 'to-string do thestring' raises an error. Of course Gabriele came with an answer, but it seemed way to complex for an article the main focus on which is Asynchronous Pluggable Protocols, and uses simple Rebol to show how one can extend Windows via an APP.

 [13/13] from: carl:cybercraft at: 24-Dec-2003 22:24


On 23-Jul-03, bryan wrote:
> [>> err: error? try [ > [ returnstring: to-string do "write %newfile.txt read %rlt.txt" [ ]
<<quoted lines omitted: 18>>
> to see if 'do thestring' raises an error and if it does not then > check if 'to-string do thestring' raises an error.
Ah - with you now. You could include the other checks in the try block and use... make error! "error name" if an error does occur. That would then be treated just like the file-not-found error.
> Of course Gabriele came with an answer, but it seemed way to complex > for an article the main focus on which is Asynchronous Pluggable > Protocols, and uses simple Rebol to show how one can extend Windows > via an APP.
Yes - examples should include as little unrelated code as possible. -- Carl Read

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted