[REBOL] Re: Binding operators
From: fsievert::uos::de at: 10-Sep-2001 9:06
> On Sunday 09 September 2001 01:26, Frank Sievertsen wrote:
> > -> When there is an operator-word, but it does not hold an operator, the
> > interpreter will throw an error.
>
> If the interpreter always throws an error when an operator word is not
> actually an operator then the 'and' argument to the reportA function should
> fail as well, should it not?
>
> I've tried another test and it looks like the operator word will only work as
> the first argument to a function.
There = behind an evaluated value.
The interpreter is looking for op!s, after it evaluted something. One
example:
reporta
-> function -> searching for one argument
reporta and
-> evaluating and (integer!)
-> looking if there is an op!-word folliwing, no
evaluating reporta.
But:
reportc
-> function -> searching for one argument
reportc 9
-> evaluating 9
-> looking if there is an op!-word following, YES:
reportc 9 and
-> invalid operator and!
It has nothing to do with "second" or "first" argument. Example:
reportc (9) (and)
should work, because there is no following op!-word. And
(9 and)
will fail.
> > I'm afraid infix operators are almost a kludge in REBOL. Words
> > such as +, *, AND etc. are probably handled before the actual
> > execution.
>
> Yeah, that's what I've done with my own scripting language. I move the
> operator to make it prefix for the interpreter. REBOL must work a little
> differently otherwise none of the report functions would work, but perhaps
> the infix fiddling interacts badly with the argument fetching.
The reason, why 'and works as an prefix, too, is that op!s are
any-function!s, too. They are not handled as an op!, but as an
any-function! in that case.
I don't see a bug here, but I think it is not a good idea to detect op!s
by the word! that holds them. It would be better (but slower) to detect
them by the datatype!.
CU,
Frank