[RPL/2] Please explain this behaviour

DEMAINE Benoit-Pierre benoit at demaine.info
Jeu 13 Déc 12:13:52 CET 2007


Adrian Blake wrote:
> RPL/2> clear
> RPL/2> { 2 3 + } list-> drop eval
> 
> as expected, good

Yes.

> RPL/2> { 3 4 * } list-> drop eval
> 
> also as expected, good

yes.

> RPL/2> { 2 3 { 3 4 * } + + } list-> drop eval
> +++Error : Invalid argument type for << { 2 3 { 3 4 * } + + } list-> drop eval >> command
> result should be 17

No. You are wrong, the error is right.

> or should it be this
> { 2 3 { 3 4 * } list-> drop eval + + } list-> drop eval
> 
> no ..fails
> 
> So what is the correct syntax?

A list is not a program.

It may work if you wrote
<< 2 3 { 3 4 * } + + >>
because this way, you put things in stack, and evaluate them one after
the other.

But, perform steps one by one, by hand in CLI, put the list, then
execute list->, and you will see that after DROP, the first 2 elements
of the stack are the last two objets of the list, twice a plus.

Since a plus takes as argument "two values", givving this command as
argument a command can not work: you can not add the plus sign to a
value. You can only add '+' to an array.

In the best case, you could hope to EVAL

3: { 3
     4
     * }
2: +
1: +

and get

1: { 3
     4
     *
     + }

Thats would make sense to me. But, in any case, you can NOT hope getting
a number as result to this.

Bcause when you arrive at the EVAL step, the stack has at the bottom two
'+' operators.

It's not a syntax problem, but a design problem (or, YOU not
understanding the RPL objects).

RPL is somehow commutative. But, not the way you think.

{ 2 3 { 3 4 * } + + } list-> drop eval
has NO WAY to ever work.

Any way, type just
2 3 { 3 4 * } + +
and you will also get an error.

I dont really guess what you intend to do; I can not see your point, or
guess how any modification of your example could lead to anything
interesting.

Before posting the ML, please, try manually your commands. If you had type
{ 2 3 { 3 4 * } + + } list-> drop eval
manually step by step, you would have seen the problem immediately:
evaluating:
3: { 3
     4
     * }
2: +
1: +
CAN NOT lead to what you had in mind, what ever it was.

Did you ever use HP calculators ? Maybe you should read some RPL
tutorial on the web if there is any; maybe on http://www.hpcalc.org/ You
are having a very basic problem, generic to RPL, not specific to the
implementation by Bertrand. Your thing should faile the same way on HP
machines (I just would have expecte the result to be a list containing
'+' in the end).

-- 
 >o_/ DEMAINE Benoit-Pierre (aka DoubleHP) http://benoit.demaine.info/
If computing were an exact science, IT engineers would not have work \_o<

"So all that's left, Is the proof that love's not only blind but deaf."
(FAKE TALES OF SAN FRANCISCO, Arctic Monkeys)


Plus d'informations sur la liste de diffusion RPL2