I guess someone deleted a post but had this quoted
An AutoLISP variable that has not been assigned a value is said to be nil. This is different from blank, which is considered a character string, and different from 0, which is a number. So, in addition to checking a variable for its current value, you can test to determine if the variable has been assigned a value.
Each variable consumes a small amount of memory, so it is good programming practice to reuse variable names or set variables to nil when their values are no longer needed. Setting a variable to nil releases the memory used to store that variable's value. If you no longer need the val variable, you can release its value from memory with the following expression
_$ (setq val nil)
I guess the difference is or I does setting a variable to a empty list also release the value?
OK, I think I understand what you mean, and that makes sense.
Mainly,
nil is nothing (
null) because it's used to release memory, and it serves as well for some types explicitly defined in more strongly typed language (i.e. F#):
- the boolean
false value
- an empty list (as
[] in F#)
- the absence of a specific value as argument or function return (as
() the F#
unit type)
Here're some examples comparinf AutoLISP and F# (which is the strongly typed language closest to lISP I know).
nil as
null (null isn't often used with F# which avoid the use mutable variables as it's more an imperative behavior)
_$ (setq s "foo")
"foo"
_$ (setq s nil)
nil
> let mutable s = "foo" ;;
val mutable s : string = "foo"
> s <- null ;;
val it : unit = ()
nil as
false_$ (= 0 1)
nil
> 0 = 1 ;;
val it : bool = false
nil as
empty list_$ (setq l nil)
nil
_$ (cons 1 l)
(1)
> let l = [] ;;
val l : 'a list
> 1 :: l ;;
val it : int list = [1]
nil as
absence of a specific value_$ (defun foo nil (alert "Hello"))
FOO
_$ (foo)
nil
> let foo () = printfn "Hello" ;;
val foo : unit -> unit
> foo () ;;
Hello
val it : unit = ()