[REBOL] Re: if and parens
From: carl:cybercraft at: 6-Oct-2002 11:13
On 06-Oct-02, Laurent Giroud wrote:
> Hi everyone again,
> I have a little "problem" that I encounter quite frequently with 'if
> : in certain cases I need to use parens to make sure that the
> expression tested is correctly evaluated.
> While I understand that in some cases parens may be necessary to
> avoid ambiguities, in the following example I fail to see why they
> are needed :
> this simply prints the list of files in the current folder and works
> quite fine :
>>> foreach elt read %. [if (get in info? to-file elt 'type) = 'file
>>> [print elt]]
> ...
> but when removing the parens we get :
>>> foreach elt read %. [if get in info? to-file elt 'type = 'file
>>> [print elt]]
> ** Script Error: in expected word argument of type: word
> ** Where: halt-view
> ** Near: if get in info? to-file
> The code looks quite unambiguous to me since all the part beetween
> the 'if and the "=" character evaluates without problem if isolated
> :
>>> elt: %afile ; "afile" being an existing file
>>> get in info? to-file elt 'type
> == file
> Would anyone have an explanation ?
Others can have a go at the explaination, but as you say, the problem
(if it is one) can be solved in may cases by swapping the operator's
values around. ie...
foreach elt read %. [if 'file = get in info? to-file elt 'type [print
elt]]
--
Carl Read