values function in Common Lisp

Multiple Values in CL The language Common lisp is described in the ANSI standard INCITS 226-1994 (R2004) and has many implementations. Each can implement multiple values as it sees fit, and they are allowed, of course, to cons up a list for them (in fact, the Emacs Lisp compatibility layer for CL does just that … Read more

Variable references in lisp

With lexical scope one does not have access to variables that are not in the current scope. You also cannot pass lexical variables to other functions directly. Lisp evaluates variables and passes the values bound to these variables. There is nothing like first-class references to variables. Think functional! (let ((a 1)) (values (lambda (new-value) (setf … Read more

Lisp Executable

I was actually trying to do this today, and I found typing this into the CLisp REPL worked: (EXT:SAVEINITMEM “executable.exe” :QUIET t :INIT-FUNCTION ‘main :EXECUTABLE t :NORC t) where main is the name of the function you want to call when the program launches, :QUIET t suppresses the startup banner, and :EXECUTABLE t makes a … Read more

setq and defvar in Lisp

There are several ways to introduce variables. DEFVAR and DEFPARAMETER introduce global dynamic variables. DEFVAR optionally sets it to some value, unless it is already defined. DEFPARAMETER sets it always to the provided value. SETQ does not introduce a variable. (defparameter *number-of-processes* 10) (defvar *world* (make-world)) ; the world is made only once. Notice that … Read more

How to generate all the permutations of elements in a list one at a time in Lisp?

General principle Suppose you have the following range function: (defun range (start end &optional (step 1)) (loop for x from start below end by step collect x)) You can accept another parameter, a function, and call it for each element: (defun range-generator (callback start end &optional (step 1)) (loop for x from start below end … Read more