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

When to use ‘ (or quote) in Lisp?

Short answer Bypass the default evaluation rules and do not evaluate the expression (symbol or s-exp), passing it along to the function exactly as typed. Long Answer: The Default Evaluation Rule When a regular (I’ll come to that later) function is invoked, all arguments passed to it are evaluated. This means you can write this: … Read more

Why exactly is eval evil?

There are several reasons why one should not use EVAL. The main reason for beginners is: you don’t need it. Example (assuming Common Lisp): EVALuate an expression with different operators: (let ((ops ‘(+ *))) (dolist (op ops) (print (eval (list op 1 2 3))))) That’s better written as: (let ((ops ‘(+ *))) (dolist (op ops) … Read more