Prev: Comparing Lisp to Python, what you consider more important: speed or macros.
Next: Comparing Lisp to Python, what you consider more important: speed or macros.
From: Tamas K Papp on 28 Apr 2010 21:04 On Wed, 28 Apr 2010 14:21:01 -0700, grucidipo wrote: > The difficulty is about taking care of the correct type, for example > nth, gethash, char, aref, svref instead python accessor [], that is you > gain speed because you don't use CLOS like operations, defgeneric Aref is perfectly fine in place of char, svref, etc. And nothing prevents you form defining a generic accessor; also, CLOS is quite fast. Anyhow, I think that this is a rather superficial thing, and not something which would influence my choice of a language in the slightest. > I agree, macros are a big win, but the problem I see is that they are > not easy to standardise, you can construct a new language with macros > and for others reading your code can be difficult. Totally. For example, people use obscure constructs like (with-open-file (stream filespec) ...) which make reading their code difficult. Why don't they just write (let ((stream (open filespec)) (flag t)) (unwind-protect (multiple-value-prog1 (progn ...) (setq flag nil)) (when stream (close stream :abort flag)))) which is clear, simple and transparent? Tamas
From: Tamas K Papp on 28 Apr 2010 21:24
On Wed, 28 Apr 2010 14:04:37 -0700, grucidipo wrote: > As you are developing teaching algebra, here is a more simple program > for learning basic operations :)) > > (defun ask-what-is(op arg1 arg2) > (let (op&name res) > (setq op&name '((+ "sum") (* "product") (- "difference")) > res (funcall op arg1 arg2)) > (format t "~%What is the ~s of ~s and ~s?" (second (assoc op > op&name)) arg1 arg2) > (setq in (read)) > (if (= in (funcall op arg1 arg2)) > (format t "~%Correct!") > (format t "~%The correct answer is ~s" res)) > (= res in))) That really hurt. Please don't do it again. Also, why the scare quotes? Eg (ask-what-is '- 1 2) prompts What is the "difference" of 1 and 2? Is this some post-modern statement about algebra? I never got the hang of those. Anyway, a less original programmer whose mind was polluted by, say, reading the first 30 pages of a book on Lisp might have written something like (defparameter *op-table* '((+ "sum") (* "product") (- "difference"))) (defun ask-what-is (op arg1 arg2) (format t "~&What is the ~a of ~a and ~a? " (second (assoc op *op-table*)) arg1 arg2) (let* ((result (funcall op arg1 arg2)) (answer (read)) (correct-p (= answer result))) (if correct-p (format t "~&Correct.") (format t "~&Nope. The correct is ~a." result)) correct-p)) Best, Tamas |