lisp

LISP - destructive and non-destructive constructs

谁都会走 提交于 2019-12-22 04:45:20
问题 What is the correct definition of destructive and non-destructive constructs in LISP (or in general). I have tried to search for the actual meaning but I have only found a lot of usage of these terms without actually explaining them. It came to my understanding, that by destructive function is meant a function, that changes the meaning of the construct (or variable) - so when I pass a list as a parameter to a function, which changes it, it is called a destructive operation, because it changes

Executes a function until it returns a nil, collecting its values into a list

◇◆丶佛笑我妖孽 提交于 2019-12-22 04:24:50
问题 I got this idea from XKCD's Hofstadter comic; what's the best way to create a conditional loop in (any) Lisp dialect that executes a function until it returns NIL at which time it collects the returned values into a list. For those who haven't seen the joke, it's goes that Douglas Hofstadter's “eight-word” autobiography consists of only six words: “I'm So Meta, Even This Acronym” containing continuation of the joke: (some odd meta-paraprosdokian?) “Is Meta” — the joke being that the

SBCL initialization file

折月煮酒 提交于 2019-12-22 04:03:24
问题 I would like to know where I should save my .sbclrc file. I tried saving it in my .sbcl folder, but it doesn't seem to be working. I'm using Windows XP with Emacs version 23. I'm trying to set up asdf-install, that is why I'm mucking around with the initialization file. Thanks for your time. 回答1: What is the result of evaluating this in the repl: (SB-IMPL::USERINIT-PATHNAME) 来源: https://stackoverflow.com/questions/2245854/sbcl-initialization-file

Apply-recur macro in Clojure

对着背影说爱祢 提交于 2019-12-22 01:58:45
问题 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. 回答1: 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

Common Lisp: compilation vs evaluation

。_饼干妹妹 提交于 2019-12-21 17:26:36
问题 On Emacs + Slime with sbcl, once I define a function (or more) in a file I have two choices: Evaluation : e.g. with C-M-x eval-defun Compilation : e.g. with C-c M-k compile-file The second one produces a .fasl file, too. What are the differences between the two? What's going on under the hood when I compile a definition / a file? What are the Pros and Cons of each one? 回答1: First of all, there's a function eval [1], that allows to evaluate (i.e. execute) arbitrary CL form in the language

Why does TCO require support from the VM?

孤街浪徒 提交于 2019-12-21 17:05:22
问题 Some VMs, most notably the JVM, are said to not support TCO. As a result, language like Clojure require the user to use loop recur instead. However, I can rewrite self-tail calls to use a loop. For example, here's a tail-call factorial: def factorial(x, accum): if x == 1: return accum else: return factorial(x - 1, accum * x) Here's a loop equivalent: def factorial(x, accum): while True: if x == 1: return accum else: x = x - 1 accum = accum * x This could be done by a compiler (and I've

Why is there no tail recursion optimization in Emacs lisp, not but like other scheme?

我的未来我决定 提交于 2019-12-21 12:44:31
问题 Emacs lisp is a dialect of LISP and especially Scheme. Most of scheme interpreters do have a optimization of Tail Recursion, but emacs lisp doens't. I searched the reason in `info elisp' for a while, but I fail to find it. P.S. Yes, there is other iteration syntax in elisp like `while', but I still cannot find a good reason why they didn't implement tail recursion like other scheme interpreters. 回答1: Emacs Lisp was created in the 1980's. The Lisp dialect that the Emacs author (Richard

Get index of list within list in Lisp

早过忘川 提交于 2019-12-21 12:12:41
问题 If I have a list like this ((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6)) And I want to find the index of (0 3 6) , is there a built-in function to do this? POSITION doesn't seem to work when the search item is itself a list. 回答1: See hyperspec. POSITION can take a :test argument: (position '(0 3 6) '((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6)) :test #'equal)) 3 The default test for POSITION (and other sequence operations) is EQL, by the way. 来源: https:

What is the Scheme function to find an element in a list?

故事扮演 提交于 2019-12-21 12:07:13
问题 I have a list of elements '(a b c) and I want to find if (true or false) x is in it, where x can be 'a or 'd, for instance. Is there a built in function for this? 回答1: If you need to compare using one of the build in equivalence operators, you can use memq, memv, or member, depending on whether you want to look for equality using eq?, eqv?, or equal?, respectively. > (memq 'a '(a b c)) '(a b c) > (memq 'b '(a b c)) '(b c) > (memq 'x '(a b c)) #f As you can see, these functions return the

Does (function) serve any purpose in Emacs?

你说的曾经没有我的故事 提交于 2019-12-21 11:29:53
问题 From the documentation of the function form: Like `quote', but preferred for objects which are functions. In byte compilation, `function' causes its argument to be compiled. `quote' cannot do that. So one would do #'(lambda ...) to enable byte compilation of the lambda form. On the other hand, as mentioned in the manual, That is no longer necessary. The lambda form has one other effect: it tells the Emacs evaluator and byte-compiler that its argument is a function, by using function as a