Day 2 - Lisp Learning

Sunday, February 4, 2024 | Permalink

Going forward with learning, defvar is used to define variables. Continue with last program written in hello.lisp. Here is how I've defined the hello, world program again with variable.

(defvar greetings "hello, world")


(format t greetings)

I read many places that variables are defined with star(*) around it to mark as global variable and * is valid character to define a variable.

(defvar *greetings* "hello, world")

(format t *greetings*)


Not just * but hyphen(-) can be used to define multi-words variables and this is recommended instead of camelCase or snake_case.

(defvar hello-world "hello, world")

(format t hello-world)

Frankly speaking I haven't seen a program like above anywhere else (defining a variable and then using it in next line without context). May be in functional programming, most of the variables are bound to the scope and only defined where needed.

But, defvar is used to define the variable in Common Lisp.

Labels: