FullForm | Print an expression in LISP-format |
Echo | High-level printing routine |
PrettyForm | Print an expression nicely with ASCII art |
EvalFormula | Print an evaluation nicely with ASCII art |
Write | Low-level printing routine |
WriteString | Low-level printing routine for strings |
Space | Print one or more spaces |
NewLine | Print one or more newline characters |
FromFile | Connect current input to a file |
FromString | Connect current input to a string |
ToFile | Connect current output to a file |
ToString | Connect current output to a string |
Read | Read an expression from current input |
LispRead | Read an expression in LISP-syntax |
ReadToken | Read an token from current input |
Load | Evaluate all expressions in a file |
Use | Load a file, but not twice |
DefLoad | Load a .def file |
FindFile | Find a file in the current path |
PatchLoad | Execute commands between <? and ?> in file |
Nl | A newline character |
In> FullForm(a+b+c); (+ (+ a b )c ) Out> a+b+c; In> FullForm(2*I*b^2); (* (Complex 0 2 )(^ b 2 )) Out> Complex(0,2)*b^2; |
If the second calling sequence is used, Echo will print all the entries in the list subsequently to the current output, followed by a newline. Any strings in the list are printed without quotation marks. All other entries are followed by a space.
Echo always returns True.
In> Echo(5+3); 8 Out> True; In> Echo({"The square of two is ", 2*2}); The square of two is 4 Out> True; |
Note that one must use the second calling sequence if one wishes to print a list:
In> Echo({a,b,c}); a b c Out> True; In> Echo({{a,b,c}}); {a,b,c} Out> True; |
In> Taylor(x,0,9)Sin(x) Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880; In> PrettyForm(%) 3 5 7 9 x x x x x - -- + --- - ---- + ------ 6 120 5040 362880 Out> True; |
In> EvalFormula(Taylor(x,0,7)Sin(x)) 3 5 7 x x x Taylor( x , 0 , 7 , Sin( x ) ) = x - -- + --- - ---- 6 120 5040 Out> True |
In> Write(1); 1Out> True; In> Write(1,2); 1 2Out> True; |
In> Write("Hello, world!"); "Hello, world!"Out> True; In> WriteString("Hello, world!"); Hello, world!Out> True; |
In> Space(5); Out> True; |
In> NewLine(); Out> True; |
2 + 5; |
Then we can have the following dialogue:
In> FromFile("foo") res := Read(); Out> 2+5; In> FromFile("foo") res := ReadToken(); Out> 2; |
In> FromString("2+5; this is never read") res := Read(); Out> 2+5; In> FromString("2+5; this is never read") res := Eval(Read()); Out> 7; |
In> [ Echo("Result:"); PrettyForm(Taylor(x,0,9) Sin(x)); ]; Result: 3 5 7 9 x x x x x - -- + --- - ---- + ------ 6 120 5040 362880 Out> True; |
Now suppose one wants to send the output of this command to a file. This can be achieved as follows:
In> ToFile("out") [ Echo("Result:"); PrettyForm(Taylor(x,0,9) Sin(x)); ]; Out> True; |
After this command the file out contains:
Result: 3 5 7 9 x x x x x - -- + --- - ---- + ------ 6 120 5040 362880 |
In> str := ToString() \ In> [ WriteString("The square of 8 is "); Write(8^2); ]; Out> "The square of 8 is 64"; |
In> FromString("2+5;") Read(); Out> 2+5; In> FromString("") Read(); Out> EndOfFile; |
The expression a+b is written in LISP syntax as (+ a b). The advantage of this syntax is that it is less ambiguous than the infix operator grammar that Yacas uses by default.
In> FromString("(+ a b)") LispRead(); Out> a+b; In> FromString("(List (Sin x) (- (Cos x)))") LispRead(); Out> {Sin(x),-Cos(x)}; |
A token is for computer languages what a word is for human languages: it is the smallest unit in which a command can be divided, so that the semantics (that is the meaning) of the command is in some sense a combination of the semantics of the tokens. Hence a := foo consists of three tokens, namely a, :=, and foo.
In> FromString("a := Sin(x)") \ In> While((tok := ReadToken()) != EndOfFile) Echo(tok); a := Sin ( x ) Out> True; |
The purpose of this function is to make sure that the file will at least have been loaded, but is not loaded twice.
This is similar to the way php works. You can have a static text file with dynamic content generated by Yacas.
Note that the second letter in the name of this command is a lower case L (from "line").
In> WriteString("First line" : Nl() : "Second line" : Nl()); First line Second line Out> True; |