Yorick: Print expression

Home Manual Packages Global Index Keywords Quick Reference |
### 1.1.3 Printing an expression An unadorned expression is also a legal Yorick statement; Yorick prints its value. In the preceding examples, only the characters you would type have been shown; to exhibit the `print` function and its output, I need to show you what your screen would look like -- not only what you type, but what Yorick prints. To begin with, Yorick prompts you for input with a `>` followed by a space (see section 1.3.5 Prompts). In the examples in this section, therefore, the lines which begin with `>` are what you typed; the other line(s) are Yorick's responses.
    > E
    8.199e-07
    > print, E
    8.199e-07
    > m;c;m*c^2
    9.11e-28
    3.e+10
    8.199e-07
    > span(0,2,5)
    [0,0.5,1,1.5,2]
    > max(sin(theta)*exp(-theta/6))
    0.780288
In the `span` example, notice that an array is printed as a comma delimited list enclosed in square brackets. This is also a legal syntax for an array in a Yorick statement. For numeric data, the `print` function always displays its output in a format which would be legal in a Yorick statement; you must use the `write` function if you want "prettier" output. Beware of typing an expression or variable name which is a large array; it is easy to generate lots of output (you can interrupt Yorick by typing control-c if you do this accidentally, see section 1.3.1 Starting, stopping, and interrupting Yorick). Most non-numeric objects print some useful descriptive information; for example, before it was closed, the `file` variable above would have printed:
    > file
    write-only text stream at:
      LINE: 201  FILE: /home/icf/munro/damped.txt
As you may have noticed, printing a variable and invoking a procedure with no arguments are syntactically indistinguishable. Yorick decides which operation is appropriate at run time. Thus, if `file` had been a function, the previous input line would have invoked the `file` function; as it was not a function, Yorick printed the `file` variable. Only an explicit use of the `print` function will print a function:
    > print, fma
    builtin fma()