lisp

Current memory usage in Lisp

强颜欢笑 提交于 2019-12-06 03:44:34
问题 I need to find out, from within a Common Lisp program, how much memory is currently being used. I'm given to understand there is no portable method (the standard function room prints the information to standard output in text form instead of returning it as a value), but sb-kernel:dynamic-usage works in SBCL. What are the equivalents in other Common Lisp implementations? Or is there another way to solve this problem I should be looking at? 回答1: It may not help you much, but anyway: You can

Are Project-Specific DSLs a Liability? [closed]

吃可爱长大的小学妹 提交于 2019-12-06 03:38:38
问题 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 8 years ago . I've forked this question from a similar question I made in a comment I made to one of the many great answers I recieved. I was originally asking about AST macros, which mostly provoked very detailed and thoughtful responses from Lispers. Thanks. Lazy Evaluation vs Macros The question I made in a comment was

Do property lists in Common Lisp refer to some global state?

三世轮回 提交于 2019-12-06 03:36:09
问题 The code below has z as a local variable, yet it behaves as if it is a global: (defun foo (m) (let ((z '(stuff nil))) (push m (getf z 'stuff)) (print z))) (foo 1) (foo 2) (foo 3) I would expect the output to be (STUFF (1)) (STUFF (2)) (STUFF (3)) T but when running it with SBCL I see (STUFF (1)) (STUFF (2 1)) (STUFF (3 2 1)) T Why is this the case? Is this behaviour peculiar to property lists? 回答1: In foo , z is bound to the literal expression '(stuff nil) . The function destructively alters

how to specify a property value of a variable in emacs lisp

和自甴很熟 提交于 2019-12-06 02:26:25
I use the following code in .emacs file to set default publish behavior. I put the org base directory in difference locations for difference computers: ;; define machine specific directories storing my org files (cond ((system-name-is-home) (setq org-dir "/data/org")) ((system-name-is-work) (setq org-dir "~/org"))) Thus I'd like to use a variable to specify :base-directory to org-dir instead of hard-coding it as "~/org" . How can I do that? (require 'org-publish) (setq org-publish-project-alist '( ("org-notes" :base-directory "~/org" :base-extension "org" :publishing-directory "~/tmp/"

Test whether the point is between matching quotes (emacs lisp)

£可爱£侵袭症+ 提交于 2019-12-06 02:10:31
How do we check whether (point) is within matching "quotes" Example 1: " (point) ", but not within Example 2: "quote here" (point) "quote there", in Emacs Lisp? What you are looking for is syntax-ppss (defined in syntax.el ). It returns 10 values, and the 4th tells you whether the point is inside a string. (eq (nth 1 (text-properties-at (point))) font-lock-string-face) This checks whether the font of the text at point is recognized as a string (i.e. has the text property face font-lock-string-face). This looking for a more elegant solution. 来源: https://stackoverflow.com/questions/15078322/test

Lisp Formatting Polynomial

谁说胖子不能爱 提交于 2019-12-06 02:07:04
I am representing sparse polynomials as lists of (coefficient, pairs). For example: '((1 2) (3 6) (-20 48)) => x^2 + 3x^6 - 20x^48 I am new to Lisp formatting, but have come across some pretty nifty tools, such as (format nil "~:[+~;-~]" (> 0 coefficient)) to get the sign of the coefficient as text (I know, that's probably not idiomatic). However, there are certain display problems when formatting single terms. For example, the following should all be true: (1 0) => 1x^0 => 1 (reducible) (1 1) => 1x^1 => x (reducible) (1 2) => 1x^2 => x^2 (reducible) (2 0) => 2x^0 => 2 (reducible) (2 1) => 2x

LISP - digits after decimal point

為{幸葍}努か 提交于 2019-12-06 02:06:33
问题 does anyone know how to specify the numer of digits after the decimal point for a float in Lisp? Say if I print this command at the REPL: CL-USER 3 > (format t "~,15f" (float (/ 1 7))) I get: 0.142857150000000 But the number is rounded at the 8th digit after the decimal point, I need to see a lot of digits after the decimal point in order to see if the number is cyclic and to calculate the period. (Actually I'm starting to try and solve Project Euler's problem 26). I need to get something

Can you have hash tables in lisp?

橙三吉。 提交于 2019-12-06 01:58:13
问题 Can you have hash tables or dicts in Lisp? I mean the data structure that is a collection of pairs (key, value) where values can be acceded using keys. 回答1: Common Lisp has at least four different ways to do that (key value storage): property lists (:foo 1 :bar 2) assoc lists ((:foo . 1) (:bar . 2)) hash tables CLOS objects (slot-value foo 'bar) to get and (setf (slot-value foo 'bar) 42) to set. The slot name can be stored in a variable: (let ((name 'bar)) (slot-value foo name)) . For simple

Common Lisp: is delete-if the same as setf + remove-if?

女生的网名这么多〃 提交于 2019-12-06 01:45:49
The following code generates prime from 1 to n: (defun prime-list(n) (let ((a)(b)(x (floor (sqrt n)))) (loop for i from (floor n 6) downto 1 do (push (1+ (* 6 i)) a) (push (1- (* 6 i)) a)) (loop while (<= (car a) x) do (push (car a) b) (setf a (remove-if #'(lambda(m)(or (= 0 (mod m (car a))) (> m n))) a))) (append '(2 3) (reverse b) a))) It seems to me the part (setf a (remove-if #'XXX a)) can be replaced by (delete-if #'XXX a) And I hoped this would make it faster. However when I made that change the function now get into an infinite loop and never returns. Why? As mentioned in the comments,

Writing a ++ macro in Common Lisp

非 Y 不嫁゛ 提交于 2019-12-06 01:25:26
问题 I've been attempting to write a Lisp macro that would perfom the equivalent of ++ in other programming languages for semantic reasons. I've attempted to do this in several different ways, but none of them seem to work, and all are accepted by the interpreter, so I don't know if I have the correct syntax or not. My idea of how this would be defined would be (defmacro ++ (variable) (incf variable)) but this gives me a SIMPLE-TYPE-ERROR when trying to use it. What would make it work? 回答1: