jed-users mailing list

[2002 Date Index] [2002 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Template function


Paul Boekholt <p.boekholt@xxxxxxxxx> wrote:
>However this
>  1;2;5; ()+()-(); sprintf ("%d"); message;
>will output -6.
>So first it adds 2 to 5 then it subtracts that from 1, getting the order of
>operands in the subtraction all wrong?

It is important to point out that you should always explicitly pass
arguments to functions that take a variable number of arguments.
"sprintf" is one such example.  I am surprised that sprintf("%d")
worked.

>If I use RPN notation it seems to be more consistent
>
>1;2;5;
>. - -
>
>gives me 1 - (2-5) = 4, which is consistent with what a rpn calculator will
>tell you.

Yes.  When dealing with the stack, always think in RPN.   Since "+"
and "-" are at the same level of precedence, slang carries out the
operations in left to right order, and each of the binary operations
use what happens to be on the stack.

>> > then the following code will get generated:
>> > 
>> >     PUSH a
>> >     PUSH b
>> >     PUSH c
>
>is this assembly language?

The parser generates byte-code that gets executed by the slang VM.
The above is merely a simplified description of the byte-code that
gets generated.

I hope this helps.
--John

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2002 date index] [2002 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]