Lisp Learning Pt. 2

Feb 4, 2024

Going forward with learning, defvar is used to define variables. Continue with the last program written in hello.lisp. Here is how we can define the hello, world program again with variables.

; hello.lisp

(defvar msg "hello, world")
(format t msg)

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

; hello.lisp

(defvar *msg* "hello, world")
(format t *msg*)

Not just * but hyphen(-) is also used define multi-words variables as kebab-case and this is recommended instead of camelCase or snake_case.

; hello.lisp

(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 the next line without context). Maybe 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.

Tags: lisp