Hello [EMAIL PROTECTED],
Actually you can almost use your original function, you just got to be carefull not to
evaluate the error! value.
(As Andrew pointed out).
Some REBOL values defaults to being evaluated on retrival, functions and errors are
examples. Others don't - blocks, etc.
to safely pass error values around you could use a colon in front of the word.
Here's a slightly modified Connect:
Connect: Func [ ip port ] [
error? Gp: try [
Open/direct/binary probe To-url join "tcp://" [ Ip ":" port ]
]
if not error? :gp [
insert gp "GNUTELLA CONNECT/0.4^/^/"
print to-string data: copy gp
]
return :gp
]
Note the additional colons and the error? in the second line.
Now you can do stuff like:
## error? connect "localhost" 1000
tcp://localhost:1000
== true
BTW.
I once started on a REBOL implementation of the Gnutella protocol, so if you're
interested in some marshalling functions, etc - just let me know...
Best regards
Thomas Jensen
On 02-Oct-00, [EMAIL PROTECTED] wrote:
>>
>> e wrote:
>>> It looks like both would work, according to 'help try'...
>>> DESCRIPTION:
>>> Tries to DO a block and returns its value or an error.
>>
>>> gp: try [ open/... ]
>>> and
>>> try [ gp: open/... ]
>>>
>>> should be equivalent, no?
>
> Let me follow with what I think is going on, and you can correct me...
>
>> You're slightly misreading the description. Have a look at the simple
>> example below:
>>
>>>> try [1 / 0]
>> ** Math Error: Attempt to divide by zero.
>> ** Where: 1 / 0
>
> This actually reduces to an error, no surprise
>
>>>> error? try [1 / 0]
>> == true
>>>> error? err: try [1 / 0]
>> == true
>
> as demonstrated here...
> But if I didn't catch the error with 'error? it would ab-end?
>
>>>> probe err
>> ** Math Error: Attempt to divide by zero.
>> ** Where: 1 / 0
>>>> err: none
>> == none
>>>> error? try [err: 1 / 0]
>> == true
>>>> probe err
>> none
>> == none
>
> I think I get it... When the expression is reduced down, if the result is
> type error!, it ab ends. So I could have said:
>
> if not error? try [gp: open/direct/binary probe join tcp:// [ip ":" port]] [
> insert gp "GNUTELLA CONNECT/0.4^/^/"]
>
> And indeed, it works... Man this language is addictive!!!
>
>
>