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

Binding operators

 [1/6] from: karlr20:home at: 9-Sep-2001 22:48


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. On Saturday 08 September 2001 11:51, Gabriele Santilli wrote:
> 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. I guess I should report this as a bug. -Karl

 [2/6] 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
<<quoted lines omitted: 4>>
> 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
<<quoted lines omitted: 3>>
> 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

 [3/6] from: lmecir:mbox:vol:cz at: 10-Sep-2001 16:06


Hi Frank,
> 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!.
I respectfully disagree. The safety can be addressed in a better way than it is now even with the detection of infix operators by their words.
> CU, > Frank
Cheers Ladislav

 [4/6] from: karlr20:home at: 8-Sep-2001 10:06


When using bind on code with operators (and, xor, etc) the operators *sometimes* cause a script error. Below is code which demonstrates the problem. Can anyone explain this? REBOL [ Purpose: {Shows inconsistent behavior of re-binding operators.} ] c: context [ and: 16 reportA: func [ n ] [ print n ] reportB: func [ n x ] [ print n ] reportC: func [ x n ] [ print n ] run: func [ prog ] [ do bind load prog 'run ] ] c/run [ reportA and reportB and 1 reportC 1 and ; Why does this fail? ] quit ouput: { 16 16 ** Script Error: Invalid operator: and ** Where: run ** Near: reportC 1 and } -Karl Robillard

 [5/6] from: fsievert:uos at: 9-Sep-2001 10:26


When REBOL finds a Value it has to look behind it to see if an operator is following. REBOL does this at the moment (different to FREEBELL) by looking, if a word called [+ | - | * | / | // | and | or ....] if following. If an operator-word is following, it trys to use it as an operator. See the following example: compose [1 (:+) 2 3] == [1 op 2 3] do compose [1 (:+) 2 3) == 5 -> When the interpreter evaluates the "1" it does not detect the following operator to be one (because it is not an operator-word) and so it does not work. -> When there is an operator-word, but it does not hold an operator, the interpreter will throw an error. Frank On Sat, 8 Sep 2001, Karl Robillard wrote:

 [6/6] from: g:santilli:tiscalinet:it at: 8-Sep-2001 20:51


Hello Karl! On 08-Set-01, you wrote: KR> When using bind on code with operators (and, xor, etc) the KR> operators *sometimes* cause a script error. Below is code KR> which demonstrates the problem. Can anyone explain this? I'm afraid infix operators are almost a kludge in REBOL. Words such as +, *, AND etc. are probably handled before the actual execution. Personally, I would vote for having prefix notation only, and a dialect that handles precedence etc. for doing math (I posted an example of this on the list some time ago --- I can repost if people is interested, or maybe I can add it to the script library...). Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

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