Lisp

Common Lisp

Everything is a LIST(in lisp)!!!

quote or 'something

quote returns a list with evaluating it, important if we want to give a list as an argument to a function.

(quote (* 2 6))
(* 2 6)

' is just a way to write (quote (list))

'(* 2 6)
(* 2 6)

And not just with lists, it can be used to tell if to treat symbols as data.

(equal 'this 'that)
NIL

An object with apostrophe evaluates to itself, this ' is also called as quoting.

Flow Control in LISP

if

(if NIL/T if-true if-false)

cond

(cond (test-1 if-test-1)
      (test-1 if-test-1)
      ...
      (test-n if-test-n))

and or macros

(and (item1)
     (item2)
     (item3))

AND macro returns NIL in case nil is encountered or last item of the list.

Why use it?

  • Returns last value

  • If one value is nil, it will stop the evaluation of further lists/expressions.

(or (item1)
    (item2)
    (item3))

in case of or, it returns first non nil value if any is available.

Why use it?

  • Returns first non-nil value

  • Only first non-nil expression is evaluated

Functions in LISP

Syntax

(defun function-name (argument1 argument2 ...) (what-it-does))

Variables in Lisp

setf

Macro for defining any kind of data.

setq

For defining symbols

LISP Tooling

SLY

Package for Emacs, amazing for working with LISP.

sly-mrepl

Handles REPL for LISP

Backlinks