lisp

Emacs lisp: why does this sexp cause an invalid-function error?

走远了吗. 提交于 2019-11-28 03:54:45
问题 The sexp in question is (((lambda (b) (lambda (a) (+ b a))) 3) 5) which, to me, looks like it should evaluate to 8 , and in other lisps (e.g. Racket) it does, but in elisp it instead throws this error: Debugger entered--Lisp error: (invalid-function ((lambda (b) (lambda (a) (+ b a))) 3)) It appears to be telling me that ((lambda (b) (lambda (a) (+ b a))) 3) Is not a valid function. This seems wrong, because when I evaluate that expression I get (lambda (a) (+ b a)) which looks like a valid

Lisp commenting convention

梦想的初衷 提交于 2019-11-28 03:46:12
What is the Lisp convention about how many semicolons to use for different kinds of comments (and what the level of indentation for various numbers of semicolons should be)? Also, is there any convention about when to use semicolon comments and when to use #|multiline comments|# (assuming they exist and exist on multiple implementations)? In Common Lisp: ;;;; At the top of source files ;;; Comments at the beginning of the line (defun test (a &optional b) ;; Commends indented along with code (do-something a) ; Comments indented at column 40, or the last (do-something-else b)) ; column + 1 space

Collection of Great Applications and Programs using Macros

我与影子孤独终老i 提交于 2019-11-28 02:49:07
I am very very interested in Macros and just beginning to understand its true power. Please help me collect some great usage of macro systems. So far I have these constructs: Pattern Matching: Andrew Wright and Bruce Duba. Pattern matching for Scheme, 1995 Relations in the spirit of Prolog: Dorai Sitaram. Programming in schelog. http://www.ccs.neu.edu/home/dorai/schelog/schelog.html Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov. The Reasoned Schemer. The MIT Press, July 2005 Matthias Felleisen. Transliterating Prolog into Scheme. Technical Report 182, Indiana University, 1985.

In Common Lisp, why do multi-expression bodies of (if) statements require (progn)?

天大地大妈咪最大 提交于 2019-11-28 02:44:31
问题 Is this just a bit of historical cruft left over from the 1950s or is there some reason syntactically why multi-expression bodies of (if) forms require (progn)? Why can't you wrap the multiple expressions in a set of parentheses like with (let): (if some-cond ((exp1) (exp2) (exp3)) ; multi exp "then" (exp4)) ; single exp "else" It appears it would be trivial to write a macro to test each body to see first if it is a list and then if it is, if its first element is also a list (and thus not a

Lisp in the real world

北慕城南 提交于 2019-11-28 02:33:16
I have experimented with Lisp (actually Scheme) and found it to be a very beautiful language that I am interested in learning more about. However, it appears that Lisp is never used in serious projects, and I haven't seen it listed as a desired skill on any job posting. I am interested in hearing from anyone who has used Lisp or seen it used in the "real world", or who knows whether it is considered a purely academic language. Matthias Benkard Franz, Inc. provides an inexhaustive list of success stories on their website. However: Please don't assume Lisp is only useful for Animation and

What is the best way to do GUIs in Clojure?

巧了我就是萌 提交于 2019-11-28 02:32:26
What is the best way to do GUIs in Clojure ? Is there an example of some functional Swing or SWT wrapper? Or some integration with JavaFX declarative GUI description which could be easily wrapped to s-expressions using some macrology? Any tutorials? Dave Ray I will humbly suggest Seesaw . Here's a REPL-based tutorial that assumes no Java or Swing knowledge. Seesaw's a lot like what @tomjen suggests. Here's "Hello, World": (use 'seesaw.core) (-> (frame :title "Hello" :content "Hello, Seesaw" :on-close :exit) pack! show!) and here's @Abhijith and @dsm's example, translated pretty literally: (ns

Why (apply and '(1 2 3)) doesn't work while (and 1 2 3) works in R5RS? [duplicate]

瘦欲@ 提交于 2019-11-28 02:06:34
This question already has an answer here: Using AND with the apply function in Scheme 9 answers I tried it in Racket like this > (apply and '(1 2 3)) . and: bad syntax in: and > (and 1 2 3) 3 Does anyone have ideas about this? Joshua Taylor Chris Jester-Young's answer is right, but there's one other point I want to highlight. The standard and operator is a macro which delays the evaluation of its arguments, by (essentially, if not exactly) turning (and a b c) into (if a (if b c #f) #f) . This means that if a is false, b and c do not get evaluated. We also have the option of defining an and

To sort out atoms first and then sublists from a list in LISP

本秂侑毒 提交于 2019-11-28 02:05:19
I have this homework in LISP where I need to sort out atoms and then sublists from a list. I'm sure this is supposed to be easy task but as I'm not much of a programmer then this is really taking quite a while for me to understand. I have this list of numbers: (5 -1 (2 6 1) (8 7 -3) (0 (9 4)) -6) And if I understand correctly my task then I should get something like this: (5 -1 -6 (2 6 1) (8 7 -3) (0 (9 4))) So far all I found out is how to count atoms and/or sublists but I don't need that. (DEFUN ATOMNUMBER (L) (COND ((NULL L) 0) ((ATOM (CAR L)) (+ 1 (ATOMNUMBER (CDR L)))) (T (ATOMNUMBER (CDR

Lisp, cons and (number . number) difference

*爱你&永不变心* 提交于 2019-11-28 02:04:51
What is the difference between (cons 2 3) and '(2 . 3) in Lisp? '(2 . 3) is a dotted pair. (cons 2 3) creates a dotted pair too. So these should evaluate to the same thing. So one is a literal for a dotted pair, the other one creates a dotted pair. They are not exactly the same, even though they evaluate to the same values in the REPL. Consider these examples, in which cons cells are modified destructively: TEST> (defun literal-cons () (let ((cons '(1 . 2))) (incf (cdr cons)) cons)) LITERAL-CONS TEST> (literal-cons) (1 . 3) TEST> (literal-cons) (1 . 4) TEST> (literal-cons) (1 . 5) Compared to

In Lisp, how do I fix “Warning: Assumed Special?”

我的未来我决定 提交于 2019-11-28 01:46:46
问题 In this file I get 9 warnings of "assumed special". They are ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special in SETQ ;;;*** Warning in CHECK-ROW: RESULT assumed special in SETQ ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: CHECKARRAY assumed special ;;;*** Warning in CHECK-ROW: