The question is whether % refers to the value of the last line (A) or to the
value of the last evaluated expression (B).
Mathematica and Axiom use semantics (A), Maple uses (B).

I expected (B), i.e. x3=102.

Well, 'x2 := 2*%; x3 := 100+%;' is a single expression, so really
no difference in this case if you say "expression" or "line".  In
fact, in files you may have multiline expressions, so saying
"expression" is more precise.

Well, I know that there are compound expressions, but up to now an expression for me ended at ";".

In fact, what you describe is

  (x2 := 2*%; x3 := 100+%)

with the parentheses to make it into a compound expression.
But even with parens I wouldn't have a clue what % refers to if it is not precisely specified. It is not necessarily clear, that the second % refers to the same value as the first %, except if one claims that a compound statement basically behaves like a function with % as a parameter.

Looks like this is exactly what FriCAS does.

%%% (10) -> x1 := 1

   (10)  1
                                    Type: PositiveInteger
%%% (11) -> for i in 1..2 repeat (x2:=x1+%;x3:=5*%)
                                    Type: Void
%%% (12) -> [x1,x2,x3]

   (12)  [1, 2, 5]

Maple gives something else.

> x1:=1;
                                    x1 := 1

> for i from 1 to 2 do x2:=x1+%; x3:=5*%; end do;
                                    x2 := 2

                                   x3 := 10

                                   x2 := 11

                                   x3 := 55

> [x1,x2,x3];
                                  [1, 11, 55]


I just say, such example should be added to the book.

I would prefer:

x1 := 1
x2 := 2*%; x3 := 100 + %

with explantation that the second line is a compound expression.

So basically when pressing enter, then the whole thing that FriCAS receives is counted as one (maybe compound) expression and this whole thing is evaluated and its value is that of the last subexpression (in case it is compound). And % refers to the last evaluation, i.e. the value that was computed when the user pressed ENTER previously (with a non-trivial input).

Maybe also

for i in 1..2 repeat x2 := i*x2

as example of Void result.

Good as an example, but I think that loops create Void values is described already somewhere.

Ralf

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ed761367-0c10-451d-9970-312b8c46496a%40hemmecke.org.

Reply via email to