Variables

Variables

Define Variables

We use "setq" command in order to create a variable. The variable could be a number , a string , a symbol, a list. For example:

: (setq a1 1234)
-> 1234
: (setq a2 "hello")
-> "hello"
: (setq a3 '(11 22 33 44))
-> (11 22 33 44)
: a1
-> 1234
: a2
-> "hello"
: a3
-> (11 22 33 44)

Variable Properties.

Besides , you can easily create your own properties for each variable using "put" command. A useful property could be "documentation" which would be a string describing the variable.

: (put 'a1 'documentation "Number")
-> "Number"
: (put 'a2 'documentation "String")
-> "String"
: (put 'a3 'documentation "List")
-> "List"
: (get 'a1 'documentation)
-> "Number"
: (get 'a2 'documentation)
-> "String"
: (get 'a3 'documentation)
-> "List"

PicoLisp Functions Used.

The description of the picolisp functions used taken from official PicoLisp documentation (https://software-lab.de/doc/index.html) follows: 



(setq var 'any ..) -> any
Stores new values any in the var arguments. See also setval and def.

: (setq  A 123  B (list A A))  # Set 'A' to 123, then 'B' to (123 123)
-> (123 123)



(put 'sym1|lst ['sym2|cnt ..] 'any) -> any
Stores a new value any for a property key (or in the symbol value for zero) in a symbol, or in a list. That symbol is sym1 (if no other arguments are given), or a symbol found by applying the get algorithm to sym1|lst and the following arguments. If the final destination is a list, the value is stored in the CDR of an asoqed element (if the key argument is a symbol), or the n'th element (if the key is a number). See also =:.

: (put 'X 'a 1)
-> 1
: (get 'X 'a)
-> 1
: (prop 'X 'a)
-> (1 . a)

: (setq L '(A B C))
-> (A B C)
: (setq B 'D)
-> D
: (put L 2 0 'p 5)  # Store '5' under the 'p' property of the value of 'B'
-> 5
: (getl 'D)
-> ((5 . p))


Fetches a value any from the properties of a symbol, or from a list. From the first argument sym1|lst, values are retrieved in successive steps by either extracting the value (if the next argument is zero) or a property from a symbol, the CDR of an asoqed element (if the next argument is a symbol), the n'th element (if the next argument is a positive number) or the n'th CDR (if the next argument is a negative number) from a list. See also put; and :.

: (put 'X 'a 1)
-> 1
: (get 'X 'a)
-> 1
: (put 'Y 'link 'X)
-> X
: (get 'Y 'link)
-> X
: (get 'Y 'link 'a)
-> 1
: (get '((a (b . 1) (c . 2)) (d (e . 3) (f . 4))) 'a 'b)
-> 1
: (get '((a (b . 1) (c . 2)) (d (e . 3) (f . 4))) 'd 'f)
-> 4
: (get '(X Y Z) 2)
-> Y
: (get '(X Y Z) 2 'link 'a)
-> 1