clisp

How to modify this “make-matrix” function?

帅比萌擦擦* 提交于 2019-11-28 14:13:44
Well, the flawed function is as follows: (defun make-matrix (n) (make-array (n n) :initial-element 0)) I want to use functions like (make-matrix 8) to replace the longer (make-array '(8 8) :initial-element 0) , but CLISP says there is a fault in (n n) , because n is not a defined function. How do I write this make-matrix function? You try to use (n n) , but that is Lisp syntax for calling a function named n with an argument n . You should invoke make-array like this: (make-array (list n n) :initial-element 0) 来源: https://stackoverflow.com/questions/19678906/how-to-modify-this-make-matrix

combining two variables into one function name in macro

寵の児 提交于 2019-11-28 14:07:56
I was toying around with macros and clos, where I created an "object" macro to create instances (defmacro object (class &rest args) `(make-instance ',class ,@args)) Now doing this, I also ended up kind of wanting to do something similar for accessor functions created by clos. Example: (defclass person () ((name :accessor person-name :initarg :name))) then creating the instance (setf p1 (object person :name "tom")) now to get the name from the object obviously I would call person-name, however just as with the object macro, I wanted to create a "gets" macro to do this. So ideally: (gets person

Writing lambda expressions in common lisp

家住魔仙堡 提交于 2019-11-28 08:26:06
I am currently reading ANSI Common Lisp by Paul Graham, and I have a question about writing lambda expressions. Do we need to prefix a lambda expression with #' ?. If I write something like this in REPL, it will work fine > ((lambda (x) (+ x 1)) 1) 2 so will this > (mapcar (lambda (x) (+ x x)) '(1 2 3 4)) (2 4 6 8) I understand that #' denotes a function. So my question is, is it some sort of convention or recommended practice? Can anything go wrong if I don't prefix lambdas with #' , is it implementation dependent? The LAMBDA expression (lambda ...) is considered to be a lambda expression

Unusual stack overflow when inserting nodes in binary tree

佐手、 提交于 2019-11-27 08:29:56
问题 CLISP Version: 2.49 Leaf Node (value (NIL) (NIL)) Non-Leaf Node (value (value (NIL) (NIL)) (NIL)) Code ("format" for debug only) ; (nil) means NULL (defun binary-insert (root obj <) (if (null (cdr root)) (progn (format t "In Null [~A] => " root) (setf (car root) obj) (format t "mid [~A] => " root) (setf (cdr root) '((nil) (nil))) (format t "[~A]~%" root)) (if (funcall < obj (car root)) (progn (format t "In Left [~A] => " root) (binary-insert (nth 1 root) obj <) (format t "[~A]~%" root)) ;

How to modify this “make-matrix” function?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 08:12:53
问题 Well, the flawed function is as follows: (defun make-matrix (n) (make-array (n n) :initial-element 0)) I want to use functions like (make-matrix 8) to replace the longer (make-array '(8 8) :initial-element 0) , but CLISP says there is a fault in (n n) , because n is not a defined function. How do I write this make-matrix function? 回答1: You try to use (n n) , but that is Lisp syntax for calling a function named n with an argument n . You should invoke make-array like this: (make-array (list n

What's difference between defvar, defparameter, setf and setq

一个人想着一个人 提交于 2019-11-27 06:30:11
I found a Similar question . But I don't quite understand that explanation. So I'm trying to run clisp with the following example: [1]> (defvar a 5) A [2]> (+ a 1) 6 [3]> (defparameter b 5) B [4]> (+ b 1) 6 [5]> (setf c 5) 5 [6]> (+ c 1) 6 [7]> (setq d 5) 5 [8]> (+ d 1) 6 [9]> (let ((a 500)) (+ a 1)) 501 [10]> (let ((b 500)) (+ b 1)) 501 [11]> (let ((c 500)) (+ c 1)) 501 [12]> (let ((d 500)) (+ d 1)) 501 [13]> What I found is totally the same. I can't figure out what's different with them? Michał Kwiatkowski DEFPARAMETER always assigns a value. So: [1]> (defparameter a 1) A [2]> (defparameter

Writing lambda expressions in common lisp

偶尔善良 提交于 2019-11-27 02:18:48
问题 I am currently reading ANSI Common Lisp by Paul Graham, and I have a question about writing lambda expressions. Do we need to prefix a lambda expression with #' ?. If I write something like this in REPL, it will work fine > ((lambda (x) (+ x 1)) 1) 2 so will this > (mapcar (lambda (x) (+ x x)) '(1 2 3 4)) (2 4 6 8) I understand that #' denotes a function. So my question is, is it some sort of convention or recommended practice? Can anything go wrong if I don't prefix lambdas with #' , is it

Lisp Executable

霸气de小男生 提交于 2019-11-26 23:44:08
I've just started learning Lisp and I can't figure out how to compile and link lisp code to an executable. I'm using clisp and clisp -c produces two files: .fas .lib What do I do next to get an executable? thekidder 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 native executable. It can also be useful to call (EXT

What&#39;s difference between defvar, defparameter, setf and setq

给你一囗甜甜゛ 提交于 2019-11-26 12:00:32
问题 I found a Similar question. But I don\'t quite understand that explanation. So I\'m trying to run clisp with the following example: [1]> (defvar a 5) A [2]> (+ a 1) 6 [3]> (defparameter b 5) B [4]> (+ b 1) 6 [5]> (setf c 5) 5 [6]> (+ c 1) 6 [7]> (setq d 5) 5 [8]> (+ d 1) 6 [9]> (let ((a 500)) (+ a 1)) 501 [10]> (let ((b 500)) (+ b 1)) 501 [11]> (let ((c 500)) (+ c 1)) 501 [12]> (let ((d 500)) (+ d 1)) 501 [13]> What I found is totally the same. I can\'t figure out what\'s different with them?

Lisp Executable

你。 提交于 2019-11-26 08:47:11
问题 I\'ve just started learning Lisp and I can\'t figure out how to compile and link lisp code to an executable. I\'m using clisp and clisp -c produces two files: .fas .lib What do I do next to get an executable? 回答1: 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