LET versus LET* in Common Lisp

LET itself is not a real primitive in a Functional Programming Language, since it can replaced with LAMBDA. Like this: (let ((a1 b1) (a2 b2) … (an bn)) (some-code a1 a2 … an)) is similar to ((lambda (a1 a2 … an) (some-code a1 a2 … an)) b1 b2 … bn) But (let* ((a1 b1) (a2 … 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

Common lisp error: “should be lambda expression”

Correct! The problem is in the line right after that, where it says ((cons nil lst) (append lst nil) (insertat nil lst 3) … The issue is the two opening parentheses. Parentheses can change meaning in special contexts (like the cond form you’re using), but in this context, the parentheses signify regular function application, just … Read more

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

Here’s a way (following the code structure by @coredump from their answer; runs about 4x faster on tio.run): (defun permutations (list callback) (if (null list) (funcall callback #()) (let* ((all (cons ‘head (copy-list list))) ; head sentinel FTW! (perm (make-array (length list)))) (labels ((g (p i &aux (q (cdr p))) ; pick all items in … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)