lisp

How do I write a macro-defining macro in common lisp

百般思念 提交于 2019-12-05 01:26:05
I have about two macros (and climbing) in my codebase that look like this: (defmacro def-stat-method (method-name stat) `(progn (defmethod ,method-name ((monster monster)) (getf (stats monster) ,stat)) (defmethod (setf ,method-name) (value (monster monster)) (setf (getf (stats monster) ,stat) value)))) and this: (defmacro def-energy-method (method-name stat) `(progn (defmethod ,method-name ((monster monster)) (getf (energies monster) ,stat)) (defmethod (setf ,method-name) (value (monster monster)) (setf (getf (energies monster) ,stat) value)))) Each of the macros has the following calling

Apply-recur macro in Clojure

谁都会走 提交于 2019-12-05 01:01:20
I'm not very familiar with Clojure/Lisp macros. I would like to write apply-recur macro which would have same meaning as (apply recur ...) I guess there is no real need for such macro but I think it's a good exercise. So I'm asking for your solution. Well, there really is no need for that, if only because recur cannot take varargs (a recur to the top of the function takes a single final seqable argument grouping all arguments pass the last required argument). This doesn't affect the validity of the exercise, of course. However, there is a problem in that a "proper" apply-recur should

Is a functional language a good choice for a Flight Simulator? How about Lisp?

℡╲_俬逩灬. 提交于 2019-12-05 00:55:18
I have been doing object-oriented programming for a few years now, and I have not done much functional programming. I have an interest in flight simulators, and am curious about the functional programming aspect of Lisp. Flight simulators or any other real world simulator makes sense to me in an object-oriented paradigm. Here are my questions: Is object oriented the best way to represent a real world simulation domain? I know that Common Lisp has CLOS (OO for lisp), but my question is really about writing a flight simulator in a functional language. So if you were going to write it in Lisp,

Changing the nth element of a list

隐身守侯 提交于 2019-12-04 23:53:25
I want to change the nth element of a list and return a new list. I've thought of three rather inelegant solutions: (defun set-nth1 (list n value) (let ((list2 (copy-seq list))) (setf (elt list2 n) value) list2)) (defun set-nth2 (list n value) (concatenate 'list (subseq list 0 n) (list value) (subseq list (1+ n)))) (defun set-nth3 (list n value) (substitute value nil list :test #'(lambda (a b) (declare (ignore a b)) t) :start n :count 1)) What is the best way of doing this? How about (defun set-nth4 (list n val) (loop for i from 0 for j in list collect (if (= i n) val j))) Perhaps we should

(Random) in Common Lisp Not So Random?

眉间皱痕 提交于 2019-12-04 23:28:24
Okay, final question and I'll have finished my number guessing game in Common Lisp! :D Whenever the game starts (or a new game begins after the first game), the following function is called. ;;; Play the game (defun play () ;; If it's their first time playing this session, ;; make sure to greet the user. (unless (> *number-of-guesses* 0) (welcome-user)) ;; Reset their remaining guesses (setq *number-of-guesses* 0) ;; Set the target value (setq *target* ;; Random can return float values, ;; so we must round the result to get ;; an integer value. (round ;; Add one to the result, because ;;

Is there any common lisp docs like linux man? [closed]

本秂侑毒 提交于 2019-12-04 22:55:29
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am a newbie for emacs and common lisp. I am now using emacs and slime to learn P.Graham “ANSI Common LISP”. However, when I meet something that I don't konw, I can not easily get some useful info like linux man. Is there any common lisp docs like linux man? 回答1: Common Lisp HyperSpec describes the ANSI Common

Does Mac OS X come with a Lisp environment built in with Emacs?

谁说我不能喝 提交于 2019-12-04 22:30:51
问题 I have been trying to find an environment that does not involve installing anything else on my mac for Lisp, as I will not be using it after I get the homework done (who know if I continue using it). I have tried to look but I can't find anything. Anybody know if it does have it, and how to use it within Emacs? 回答1: You have a few options for one-click Lisp environments. If you prefer an Emacs-based environment, check out LispBox. This actually installs a separate instance of Emacs, afaik, so

Really minimum lisp

余生长醉 提交于 2019-12-04 22:20:25
问题 What is the minimum set of primitives required such that a language is Turing complete and a lisp variant? Seems like car, cdr and some flow control and something for REPL is enough. It be nice if there is such list. Assume there are only 3 types of data, integers, symbols and lists.(like in picolisp) 回答1: There's a good discussion of this in the Lisp FAQ. It depends on your choice of primitives. McCarthy's original "LISP 1.5 Programmer's Manual" did it with five functions: CAR, CDR, CONS, EQ

Common Lisp Compiling and execution time

Deadly 提交于 2019-12-04 22:13:10
问题 I have a lisp file which does lots of sampling, file I/O and arithmetic in a loop. (I do particle filtering in common lisp.) I am compiling my lisp file using the compile-file command. I also use the (declaim (optimize (speed 3) (debug 0) (safety 0))) at the beginning of my lisp file as I want to have my results as fast as possible. I use (time (load "/....../myfile.lisp") and (time (load "/......./myfile.dx64fsl") to measure speed. The issue is that compiling does not bring any advantage to

How well does your language support unicode in practice?

感情迁移 提交于 2019-12-04 21:12:06
问题 I'm looking into new languages, kind of craving for one where I no longer need to worry about charset problems amongst inordinate amounts of other niggles I have with PHP for a new project. I tend to find Java too verbose and messy, and my not wanting to touch Windows with a 6-foot pole tends to rule out .Net. That leaves essentially everything else -- except PHP, C and C++ (the latter two of which I know get messy with unicode stuff irrespective of the ICU library). I've short listed a few