Karim BELABAS on Mon, 10 Mar 2003 20:49:42 +0100 (MET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: problem


On Mon, 10 Mar 2003, James G. McLaughlin wrote:
> I am using version 2.1.3 for Windows.
>
> I do not understand why the following code does not work (it is a stripped
> down version of a program I was trying to run, stripped as much as
> possible to still produce the problem):
>
> {
> k=3;
> print (k);
> d(n)=n^3+n^2+5;
> print (d(5));
> N=10;
> for(i = 3,N, print (i);    );
> }
>
> It prints "3" as the value for "k" but then does nothing else - it will
> print neither d(5) or any of the "i" values in the "for" loop.
>
> However, if I remove the braces {} from the ends, it works as it should,
> printing both the value for d(5) and all the values in the "for" loop.
>
> In the original program, I need the braces because of the program's
> length.
>
> Does anyone have any suggestions?

Use more pairs of braces. Braces simply mean: disregard newline characters in
between, and treat as if a single line had been input.

The code above is translated to

k=3; print (k); d(n)=n^3+n^2+5; print (d(5)); N=10; for(i = 3,N, print (i);  );

Which sets k = 3, prints it, then defines a function d(n) whose body is
  n^3+n^2+5; print (d(5)); N=10; for(i = 3,N, print (i);  );

>From your original way of writing it, I don't think this is the intended
effect.  If you insist on having if all on a single line as above, you need
... (d(n)=n^3+n^2+5;) ...

where the parentheses force the evaluation of the function definition
to the enclosed text.

Cheers,

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425   Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://www.parigp-home.de/  [PARI/GP]