| Karim Belabas on Sat, 01 Nov 2025 13:19:16 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Comments between lines raise syntax error |
* Ewan Delanoy [2025-11-01 11:07]:
> I have an a small array which I prefer to write line by line for
> readability, and I also would like to insert a few comments in-between
> some lines.
I advise to use { ... } for complicated multi-line statements instead of a
line continuation \. The latter works best for a very small number of lines.
> The following naive trial raises a syntax error in PARI-GP. How can I modify it a little bit to turn it into valid syntax ?
>
> level4=([\
>
> e4,\
>
> /* Level 1 multiplied by Level 3 */
[...]
{
level4 = [
e4,
/* Level 1 multiplied by Level 3 */
z1*z5,
z1*z6,
z1*z7,
/* Level 2 multiplied by itself */
z2*z2,
z2*z3,
z3*z3
];
}
N.B.
- I removed the unnecessary parentheses
- I added a ; at the end to suppress output
Cheers
K.B.
P.S. A trailing = creates a line continuation by itself. Although this
is usually reserved to function definitions. One could equally write
level4 =
{
[
e4,
/* Level 1 multiplied by Level 3 */
z1*z5,
z1*z6,
z1*z7,
/* Level 2 multiplied by itself */
z2*z2,
z2*z3,
z3*z3
];
}
The above is still parsed as
level4 = [ e4, z1*z5, z1*z6, z1*z7, z2*z2, z2*z3, z3*z3 ];
Other more compact forms are a possibility, such as
level4 =
{
[ e4,
/* Level 1 multiplied by Level 3 */
z1*z5, z1*z6, z1*z7,
/* Level 2 multiplied by itself */
z2*z2, z2*z3, z3*z3 ];
}
or
level4 =
{ [ e4,
/* Level 1 multiplied by Level 3 */
z1*z5, z1*z6, z1*z7,
/* Level 2 multiplied by itself */
z2*z2, z2*z3, z3*z3 ]; }
Etc.
--
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/