lisp

Little Schemer atom vs (quote atom)

左心房为你撑大大i 提交于 2020-06-27 16:54:06
问题 I've just started reading The Little Schemer . It starts off with several questions asking if a given expression is an atom. It's pretty straightforward but, funny enough, the very first question is throwing me off a bit. It asks: Is it true that this is an atom? atom 1 1 (quote atom) or ’atom What's throwing me off is the footnote reference. They're asking if atom is an atom, but then somehow they're saying that atom is really (quote atom) or ’atom ? I just don't get it. 回答1: What’s going on

Proclaim, declaim, declare

时光毁灭记忆、已成空白 提交于 2020-06-24 03:44:29
问题 Can you please explain the differences between the three symbols proclaim , declaim and declare ? 回答1: They are symbols, not keywords. proclaim names a function for making global declarations. You should use declaim instead whenever possible. declaim names a macro for making global declarations (like proclaim) which are also effective at compile-time . declare is just a symbol (i.e., it does not name a function, macro, or special operator) for making local declarations in the beginning of

Proclaim, declaim, declare

前提是你 提交于 2020-06-24 03:43:41
问题 Can you please explain the differences between the three symbols proclaim , declaim and declare ? 回答1: They are symbols, not keywords. proclaim names a function for making global declarations. You should use declaim instead whenever possible. declaim names a macro for making global declarations (like proclaim) which are also effective at compile-time . declare is just a symbol (i.e., it does not name a function, macro, or special operator) for making local declarations in the beginning of

Using regex (Regular Expressions) in Parenscript

混江龙づ霸主 提交于 2020-06-09 05:29:26
问题 I am trying out Parenscript. While trying to experiment with regex function, I get unexpected output. for example, the reference manual shows: (regex "foobar") /foobar/; (regex "/foobar/i") /foobar/i; However in my repl I get error that function (parenscript:regex..) is undefined. The function parenscript:regex is undefined. [Condition of type undefined-function] Restarts: 0: [continue] Retry using regex. 1: [use-value] Use specified function 2: [retry] Retry SLIME REPL evaluation request. 3:

Update functions in Hash Table in Racket

懵懂的女人 提交于 2020-06-09 04:19:23
问题 I am a beginner in Racket and I am trying to updare a hash table using hash-update! where the value is a mutable set. Below are the code lines: (hash-update! hash key (curryr set-add! new_val) (mutable-set 1)) However I receive an error expected: set? given: #<void> argument position: 1st other arguments...: x: 2 where I tried 2 as the new_val Any suggestions ? 回答1: This is because the updater is supposed to be a function that takes a value as input and produces a new value output. Since the

clojure: no cons cells

不问归期 提交于 2020-05-28 12:44:27
问题 i heard that clojure does not have cons cells as of most lisp languages. does that mean a clojure list does not end with an empty list? could anyone explain what that exactly means? 回答1: Lisp provides a primitive cons data structure and a notation for it. See John McCarthy, Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, 1960, Chapter 3, Recursive Functions of Symbolic Expressions. That chapter introduces: Symbolic expressions made of atoms and pairs of

clojure: no cons cells

a 夏天 提交于 2020-05-28 12:44:03
问题 i heard that clojure does not have cons cells as of most lisp languages. does that mean a clojure list does not end with an empty list? could anyone explain what that exactly means? 回答1: Lisp provides a primitive cons data structure and a notation for it. See John McCarthy, Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, 1960, Chapter 3, Recursive Functions of Symbolic Expressions. That chapter introduces: Symbolic expressions made of atoms and pairs of

Uninterned symbols symbols

隐身守侯 提交于 2020-05-23 12:08:07
问题 There is something I can't understand about Common lisp. Assume I'm writing a macro similar to this: (defmacro test-macro () (let ((result (gensym))) `(let ((,result 1)) (print (incf ,result))))) Than I can do > (test-macro) 2 2 Now I want to see how it expands > (macroexpand-1 '(test-macro)) (LET ((#:G4315 1)) (PRINT (INCF #:G4315))) ; T Ok. There are unique symbols generated with gensym that were printed as uninterned. So as far as I know the uninterned symbols are the symbols for which the

How do I iterate through a directory in Common Lisp?

女生的网名这么多〃 提交于 2020-05-10 03:44:08
问题 I'm using OpenMCL on Darwin, and I'd like to do something like: (loop for f in (directory "somedir") collect (some-per-file-processing f)) But I can't get directory to return anything other than NIL , and I can't seem to find any good explanation online (other than "its different for each system"). Any pointers? 回答1: Does your pathname specification contain a wildcard? Common Lisp's pathname stuff is somewhat hard to grasp at first - at least for me it was... As the CLHS states on the

Check for proper list in Common Lisp

一笑奈何 提交于 2020-04-11 05:47:05
问题 Is there a standard function in Common Lisp that can check against improper lists (i.e. circular and dotted lists) without signaling an error? list-length can check against circular lists (it returns nil for them), but signals type-error when given a dotted list. Scheme's list? traverses the whole list to make sure it is not dotted or circular; Common Lisp's listp only checks that it's given nil or a cons cell. Here's the simplest I could come up with: (defun proper-list-p (x) (not (null