Maxima – 18 – Tipi di dati e strutture – stringhe

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.61.

Strings (quoted character sequences) are enclosed in double quote marks " for input, and displayed with or without the quote marks, depending on the global variable stringdisp.

Strings may contain any characters, including embedded tab, newline, and carriage return characters. The sequence \" is recognized as a literal double quote, and \\ as a literal backslash. When backslash appears at the end of a line, the backslash and the line termination (either newline or carriage return and newline) are ignored, so that the string continues with the next line. No other special combinations of backslash with another character are recognized; when backslash appears before any character other than ", \, or a line termination, the backslash is ignored. There is no way to represent a special character (such as tab, newline, or carriage return) except by embedding the literal character in the string.

There is no character type in Maxima; a single character is represented as a one-character string.

The stringproc add-on package contains many functions for working with strings.

(%i1) s_1 : "This is a string.";
(%o1)                          This is a string.
(%i2) s_2 : "Embedded \"double quotes\" and backslash \\ characters.";
(%o2)        Embedded "double quotes" and backslash \ characters.
(%i3) s_3 : "Embedded line termination
in this string.";
(%o3) Embedded line termination
in this string.
(%i4) s_4 : "Ignore the \
line termination \
characters in \
this string.";
(%o4)       Ignore the line termination characters in this string.

concat(arg_1, arg_2, ...)
Concatenates its arguments. The arguments must evaluate to atoms. The return value is a symbol if the first argument is a symbol and a string otherwise.

concat evaluates its arguments. The single quote ' prevents evaluation.

See also sconcat and eval_string.

(%i6) y: 7$

(%i7) z: 88$

(%i8) concat (y, z/2);
(%o8)                                 744
(%i9) concat ('y, z/2);
(%o9)                                 y44

A symbol constructed by concat may be assigned a value and appear in expressions. The :: (double colon) assignment operator evaluates its left-hand side.

(%i10) a: concat ('y, z/2);
(%o10)                                y44
(%i11) a:: 123;
(%o11)                                123
(%i12) y44;
(%o12)                                123
(%i13) b^a;
(%o13)                               b
(%i14) %, numer;
(%o14)                               b

sì 🧐 bisogna fare attenzione, sempre; forse poi :: lo ritroverò nel debug.

Note that although concat(1, 2) looks like a number, it is a string.

(%i15) concat (1, 2) + 3;
(%o15)                              12 + 3

sconcat(arg_1, arg_2, ...)
Concatenates its arguments into a string. Unlike concat, the arguments do not need to be atoms.

(%i1) sconcat ("xx[", 3, "]:", expand ((x+y)^3));
(%o1)                    xx[3]:y^3+3*x*y^2+3*x^2*y+x^3

Converts expr to Maxima’s linear notation just as if it had been typed in. The return value of string is a string, and thus it cannot be used in a computation.

Default value: false
When stringdisp is true, strings are displayed enclosed in double quote marks. Otherwise, quote marks are not displayed.

stringdisp is always true when displaying a function definition.

(%i2) stringdisp: false$

(%i3) "This is an example string.";
(%o3)                     This is an example string.
(%i4) foo () :=
      print ("This is a string in a function definition.");
(%o4)    foo() := print("This is a string in a function definition.")
(%i5) stringdisp: true$

(%i6) "This is an example string.";
(%o6)                    "This is an example string."

Nota per me: sì, Maxima è case-sensitive:

(%i1) stringdisp;
(%o1)                                false

(%i3) stringdisp;
(%o3)                                false
(%o4)                                TRUE


Posta un commento o usa questo indirizzo per il trackback.



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di

Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: