lisp

How to modify place with arbitrary function

懵懂的女人 提交于 2019-12-10 13:19:51
问题 Sometimes we need to modify a place but here is no built-in function that meets our needs. For instance, here are incf and decf for addition and subtraction: CL-USER> (defvar *x* 5) *X* CL-USER> (incf *x* 3) 8 CL-USER> *x* 8 CL-USER> (decf *x* 10) -2 CL-USER> *x* -2 But how about multiplication and division? What if we wish to modify a place with arbitrary function, like this: (xf (lambda (x) ...) *x*) xf utility would be very useful, especially when we have to deal with deeply nested

Why does this Lisp macro as a whole work, even though each piece doesn't work?

若如初见. 提交于 2019-12-10 13:13:20
问题 I'm reading/working through Practical Common Lisp. I'm on the chapter about building a test framework in Lisp. I have the function "test-+" implemented as below, and it works: (defun test-+ () (check (= (+ 1 2) 3) (= (+ 5 6) 11) (= (+ -1 -6) -7))) Remember, I said, it works , which is why what follows is so baffling.... Here is some code that "test-+" refers to: (defmacro check (&body forms) `(combine-results ,@(loop for f in forms collect `(report-result ,f ',f)))) (defmacro combine-results

CLOS make-instance is really slow and causes heap exhaustion in SBCL

こ雲淡風輕ζ 提交于 2019-12-10 12:57:10
问题 I'm writing an multiarchitecture assembler/disassembler in Common Lisp (SBCL 1.1.5 in 64-bit Debian GNU/Linux), currently the assembler produces correct code for a subset of x86-64. For assembling x86-64 assembly code I use a hash table in which assembly instruction mnemonics (strings) such as "jc-rel8" and "stosb" are keys that return a list of 1 or more encoding functions, like the ones below: (defparameter *emit-function-hash-table-x64* (make-hash-table :test 'equalp)) (setf (gethash "jc

What is the definition of “natural recursion”?

我的梦境 提交于 2019-12-10 12:43:24
问题 The Third Commandment of The Little Schemer states: When building a list, describe the first typical element, and then cons it onto the natural recursion. What is the exact definition of "natural recursion"? The reason why I am asking is because I am taking a class on programming language principles by Daniel Friedman and the following code is not considered "naturally recursive": (define (plus x y) (if (zero? y) x (plus (add1 x) (sub1 y)))) However, the following code is considered

Is it true that Lisp is not a functional programming language? [closed]

与世无争的帅哥 提交于 2019-12-10 12:28:21
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I read in the book: "Masterminds of programming" , the the interview with Guido Van Rossum says: The more fundamental property Python

How to stop evaluating lisp form when passed as function parameter?

荒凉一梦 提交于 2019-12-10 11:17:52
问题 I am learning Lisp. Now I am trying to create a function that takes some valid Lisp form as argument and returns a function that executes the Lisp forms when called. For example: (defun fn (name action) (setf (symbol-function name) #'(lambda () action))) When I am passing say (+ 4 5 6) the function is getting created with specific name and when called returning the sum. (fn 'add (+ 4 5 6)) (add) ==> 15 But if I invoke (fn 'error (assert (= 2 3)) it is throwing error (= 2 3) must evaluate to a

Lisp Reverse “all” Function

ぃ、小莉子 提交于 2019-12-10 10:40:13
问题 I want to write a function in lisp that reverses all elements from the list using map functions but I don't have any idea how to start this.. I think I have to use the built in reverse function somehow.. For example if I have the list (1 2 3 (4 5 6 (7 8 9))) I would get (((9 8 7) 6 5 4) 3 2 1) or if I had the list(1 2 3 (4 5) (6 7)) I would get ((7 6) (5 4) 3 2 1) .. Any help is appreciated! 回答1: Just a quick answer, not sure about efficiency/elegancy: (defun reverse-deeply (list) (mapcar #'

New SLIMV 0.8.4 install, paren matching works, indentation doesn't

天涯浪子 提交于 2019-12-10 10:17:13
问题 I'm reinstalling everything after a hdd failure on my netbook (fresh install of Ubuntu Netbook Edition 10.04), and am trying to get the excellent SLIMV working again. It was working fine on the previous installation, but with this one, parenthesis matching works, but auto-indenting Lisp code does not. Hitting return starts the cursor back in column 1 of the next line, no matter where it is in the nested parens. I've been digging through the docs to see if there's a commandline or .vimrc

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

萝らか妹 提交于 2019-12-10 10:13:25
问题 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? 回答1: 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. 回答2: (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

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

≯℡__Kan透↙ 提交于 2019-12-10 10:04:41
问题 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