lisp

Understanding Peter Norvig's permutation solution in PAIP

為{幸葍}努か 提交于 2021-02-20 19:00:28
问题 Peter Norvig's PAIP book contains this code as a solution to the permutation problem (some sections are removed for brevity) (defun permutations (bag) ;; If the input is nil, there is only one permutation: ;; nil itself (if (null bag) '(()) ;; Otherwise, take an element, e, out of the bag. ;; Generate all permutations of the remaining elements, ;; And add e to the front of each of these. ;; Do this for all possible e to generate all permutations. (mapcan #'(lambda (e) (mapcar #'(lambda (p)

SLIME on Emacs with paredit in repl - how to prevent execution of incomplete but balanced expressions?

时光总嘲笑我的痴心妄想 提交于 2021-02-20 06:38:46
问题 I use paredit on emacs with SLIME's repl. This means that at any point during my typing on the repl, my s-expressions are balanced. However, they may not be complete, and I might want to continue typing inside them in another line, as follows: CL-USER> (defun print-hello () ) When I start a new line by pressing the enter key, however, the SLIME repl executes my incomplete expression. I want it to wait for me to complete the expression, as follows: CL-USER> (defun print-hello () (format t

SLIME on Emacs with paredit in repl - how to prevent execution of incomplete but balanced expressions?

我的未来我决定 提交于 2021-02-20 06:35:34
问题 I use paredit on emacs with SLIME's repl. This means that at any point during my typing on the repl, my s-expressions are balanced. However, they may not be complete, and I might want to continue typing inside them in another line, as follows: CL-USER> (defun print-hello () ) When I start a new line by pressing the enter key, however, the SLIME repl executes my incomplete expression. I want it to wait for me to complete the expression, as follows: CL-USER> (defun print-hello () (format t

Resources for learning Lisp [closed]

旧城冷巷雨未停 提交于 2021-02-17 15:47:45
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . What is a good book or tutorial to learn Lisp? 回答1: Practical Common Lisp is an awesome (and free) book for anyone interested in the

Scaling lengths in an AutoCAD diagram

人走茶凉 提交于 2021-02-11 12:08:36
问题 This is a followup to my previous post here I've a 2D geometry created using the following code, ref. (defun graph ( pts sls tls ) ( (lambda ( l ) (foreach x l (text (cdr x) (itoa (car x)) 0.0 1)) (mapcar '(lambda ( a b / p q r ) (setq p (cdr (assoc a l)) q (cdr (assoc b l)) r (angle p q) ) (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q) '(62 . 8))) (text (mapcar '(lambda ( x y ) (/ (+ x y) 2.0)) p q) (rtos (distance p q) 2) (if (and (< (* pi 0.5) r) (<= r (* pi 1.5))) (+ r pi) r) 2 ) )

Scheme: Iterative process to reconstruct a list in original order?

别等时光非礼了梦想. 提交于 2021-02-11 04:55:20
问题 My question is: how to write a procedure that utilises tailcall, and that constructs a list not in the reverse order. To show what I mean, here is an example of a very simple procedure that is iterative, and that creates a copy of a list: (define (copy-list ls) (define (iter cp-ls rest-ls) (if (null? rest-ls) cp-ls (iter (cons (car rest-ls) cp-ls) (cdr rest-ls)))) (iter '() ls)) The problem is that, due to the iterative order in which the elements are cons ed together, the returned list ends

Scheme: Iterative process to reconstruct a list in original order?

不问归期 提交于 2021-02-11 04:54:20
问题 My question is: how to write a procedure that utilises tailcall, and that constructs a list not in the reverse order. To show what I mean, here is an example of a very simple procedure that is iterative, and that creates a copy of a list: (define (copy-list ls) (define (iter cp-ls rest-ls) (if (null? rest-ls) cp-ls (iter (cons (car rest-ls) cp-ls) (cdr rest-ls)))) (iter '() ls)) The problem is that, due to the iterative order in which the elements are cons ed together, the returned list ends

Use mit-scheme with REPL and editor together

拈花ヽ惹草 提交于 2021-02-10 20:12:10
问题 I'm going through SICP course and as recommended installed mit-scheme. I want to use the REPL together with a scheme file. The reason is because I can add scheme code in the file and then run the commands in REPL. What I have works, but the problem is every time I edit the file, I have to quit terminal and reload the file for REPL to see changes. Is there a way to reload the file easily or some other way for REPL to see changes from the file? This my setup: I installed mit-scheme with brew

error in process sentinel: Could not start nREPL server: java.lang.NumberFormatException: Invalid number

十年热恋 提交于 2021-02-10 18:18:00
问题 I've looked at all of the similar questions on stack overflow. This one is different enough to warrant a separate question. Basically, I can't start a repl server because I get the error below. It's been pointed out that this is typically a dependency issue, but I'm updated, to my knowledge. What am I getting wrong here? Here's the full error: error in process sentinel: Could not start nREPL server: java.lang.NumberFormatException: Invalid number: 0.8.3 at clojure.lang.LispReader.readNumber

How to convince Lisp SBCL to do inline fixnum arithmetic?

為{幸葍}努か 提交于 2021-02-08 05:02:03
问题 I've found some techniques in other SO answers, but apparently I've been unable to convince SBCL to do inline fixnum arithmetic: (declaim (optimize (speed 2) (safety 1))) (declaim (ftype (function (fixnum fixnum) double-float) fixnumtest) (inline fixnumtest)) (defun fixnumtest (i j) (declare (type fixnum i j)) (let* ((n (the fixnum (+ i j))) (n+1 (the fixnum (1+ n)))) (declare (type fixnum n n+1)) (/ 1.0d0 (the fixnum (* n n+1)) ) ) ) (defun main () (format t "~11,9F~%" (fixnumtest 2 3)) )