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

[REBOL] Re: About Attempt

From: al:bri:xtra at: 27-Dec-2002 9:06

Patrick wrote:
> attempt a > > However when 'a is not defined an error is rised. > > >> attempt a > ** Script Error: a has no value > ** Where: do-boot > ** Near: attempt a > > obviously the right syntax is more like > > attempt [a] > or > attempt [1 / 0] > > Do you think it's worth sending this to RT feedback?
The evaluation of 'a happens "outside" of the value (function!) referred to by 'attempt. But you have found a problem with 'attempt.
>> attempt 123
** Script Error: try expected block argument of type: block ** Where: attempt ** Near: if not error? set/any 'value
>> source attempt
attempt: func [ {Tries to evaluate and returns result or NONE on error.} value ][ if not error? set/any 'value try :value [get/any 'value] ]
>> source try
try: native [ {Tries to DO a block and returns its value or an error.} block [block!] ] 'attempt should have the same function input type as 'try. That's easy to correct. Just insert the following into your %user.r file (or get my %Patches.r script): attempt: func [ {Tries to evaluate and returns result or NONE on error.} value [block!] ][ if not error? set/any 'value try value [get/any 'value] ] Note that I've changed the get-word ":value" to a word "value" as the 'get isn't needed. Now 'attempt works properly:
>> attempt [1 / 0]
== none
>> attempt [1 / 2]
== 0.5
>> attempt a
** Script Error: a has no value ** Near: attempt a
>> attempt 123
** Script Error: attempt expected value argument of type: block ** Near: attempt 123 I'll fill out the feedback form as well. Andrew Martin ICQ: 26227169 http://valley.150m.com/