Chapter 3. Variables

A variable holds a value. To define a variable, just assign a value to it.

Yewslip> x = 42  /* global */

An undefined variable has the value of nil.

Yewslip> print y

Variables may be global or local. Global variables are those defined outside of functions. Local variables are those defined in functions. Local variables are specific to each function call, they disappear after the function returns. Global variables are accessible in all functions.

Yewslip> func f()
    ...>     y = 17  /* local */
    ...>     print x, y
    ...>     x += 1
    ...> end

Yewslip> f()
42 17

Yewslip> print x, y
43 (nil)

There is no way to use a local variable with the same name as a global variable. That is why there are so few predefined global variables. They are: eval, repr and lib. This also means that you must be careful which global variables you define.

A useful construct to do something without defining global variables is:


This wraps the statements into a function and calls it once.