lisp

How can I reuse a gethash lookup in Common Lisp?

心不动则不痛 提交于 2019-12-21 09:28:48
问题 I have a hash table where the keys are rather complex lists, with sublists of symbols and integers, and the value should be modified depending on the already existing value. The table is created with :test #'equal . I do something similar to this a lot: (defun try-add (i) (let ((old-i (gethash complex-list table nil))) (if (may-add old-i) (push i (gethash complex-list table))))) Profiling shows that equal tests take a lot of time. I have an optimization idea, that the amount of gethash

How can I reuse a gethash lookup in Common Lisp?

瘦欲@ 提交于 2019-12-21 09:28:09
问题 I have a hash table where the keys are rather complex lists, with sublists of symbols and integers, and the value should be modified depending on the already existing value. The table is created with :test #'equal . I do something similar to this a lot: (defun try-add (i) (let ((old-i (gethash complex-list table nil))) (if (may-add old-i) (push i (gethash complex-list table))))) Profiling shows that equal tests take a lot of time. I have an optimization idea, that the amount of gethash

Uninterned symbols in Common Lisp

夙愿已清 提交于 2019-12-21 09:27:20
问题 Several times I came across the notion of uninterned symbols, but I am not entirely clear about what they are. Is there a way to intern a symbol created with (make-symbol)? Can I assign a value to a symbol without interning it? Is it possible to rename a symbol (interned or uninterned)? What else can one do with an uninterned symbol? Update: What is happening with symbols in this piece of code? CL-USER> (defun func () (let ((var 'sym)) (print (find-symbol "sym")) (print var))) FUNC CL-USER>

common lisp - get path to file

[亡魂溺海] 提交于 2019-12-21 08:27:46
问题 In Common Lisp, is there a way to get the path to a compiled file (something like current-directory)? The file is not inside the current-directory folder. 回答1: This ought to be a comment but I'm going to give some code examples that might help the original poster along. First of all, you need to be a little more clear about what you want to do. What is the problem you're trying to solve? Secondly, here are a couple of examples which could be useful: *default-pathname-defaults* usually set to

How does “Cons” work in Lisp?

我是研究僧i 提交于 2019-12-21 07:54:55
问题 I was studying Lisp and I am not experienced in Lisp programming. In a part of my studies I encountered the below examples: > (cons ‘a ‘(a b)) ----> (A A B) > (cons ‘(a b) ‘a) ----> ((A B).A) I was wondering why when we have (cons ‘a ‘(a b)) the response is (A A B) and why when we change it a little and put the 'a after (a b) , the response is a dotted list like ((A B).A) ? What is the difference between the first code line and the second one? What is going on behind these codes? 回答1: It's

What is the Definition of a Lisp Cons Cell?

懵懂的女人 提交于 2019-12-21 07:34:46
问题 What exactly is the definition of a Common Lisp Cons Cell? How is a Cons Cell different than a standard linked list item? After all, both the cons cell and the linked list item have a value and a pointer to the next cell or item... or is this understanding wrong? 回答1: Cons cells in general hold two pointers that can point to anything. General usage of course is to point to a "value" with the left one, and to another Cons cell (or nil) with the "right" one. 回答2: A cons cell is closer to a

Is there a simple way to use Python libraries from Common Lisp?

ε祈祈猫儿з 提交于 2019-12-21 07:27:07
问题 One thing I really miss when writing Common Lisp code is access to Python libraries, both standard library and third party modules. CLPython provides a limited subset of Python functionality which precludes the use of most libraries, so that's not really useful to me. I would like to be able to call Python code from Common Lisp such that it runs in a Python VM like CPython or PyPy. 回答1: One solution is python-on-lisp. It should be ASDF-installable. It hasn't been maintained or updated for a

Why no destructing in def form?

时光怂恿深爱的人放手 提交于 2019-12-21 07:25:55
问题 In a let form (Clojure here) I can doing something like (let [[u s v] (svd A)] (do-something-with u v)) where svd returns a list of length three. This is a very natural sort of thing to do, so why isn't that we don't we have (def [u s v] (svd A)) and its various generalizations as the default behavior of the def form? I don't see how this would interfere with anything that def is already doing. Can someone who understands the Zen of Lisp or Clojure explain why def does not support binding

Why use #' before function arguments in emacs-lisp?

佐手、 提交于 2019-12-21 07:03:17
问题 I'm familiar with Emacs Lisp, but not Common (or any other) Lisp. Some Lisp programmers suggest (e.g. A basic function for emacs) that it's good to use #' in front of function arguments in Lisp code. For example: (mapc #'my-fun '(1 2 3)) In Emacs Lisp, I believe that this is equivalent to (mapc 'my-fun '(1 2 3)) From the elisp manual, section 12.7. The read syntax #' is a short-hand for using function . The following forms are all equivalent: (lambda (x) (* x x)) (function (lambda (x) (* x x)

What does #+#. mean in lisp?

久未见 提交于 2019-12-21 06:56:52
问题 It is almost impossible to google, hence my understanding is limited to contextual clues from reading through the slime source code: perhaps it is part of the object system in common lisp? Something like 'self'? snippet: (cond #+#.(swank-backend::sbcl-with-new-stepper-p) Perhaps this will make it more googleable : pound plus pound // hash plus hash symbol // octothorp plus octothorp 回答1: That's pretty rare to see. #+clim clim:+red+ #-clim mygraphics:+red+ above means that the reader returns