question_id int64 1.99k 74.6M | answer_id int64 4.76k 74.6M | title stringlengths 20 144 | question stringlengths 22 4.09k | answer stringlengths 24 4.1k |
|---|---|---|---|---|
3,538,983 | 3,539,153 | Why does plant1 keep being NIL? | Please, could someone explain me why "make-array" has no effect on plant1?
(LET (plant1) ((setq plant1 (make-array '(4 4))) (print plant1) (setf (AREF PLANT1 0 0) 1)))
NIL
Error: Attempt to do an array operation on NIL which is not an array.
[condition type: TYPE-ERROR]
| (LET (plant1) ((setq plant1 (make-array '(4 4))) (print plant1) (setf (AREF PLANT1 0 0) 1)))
First rule: format your code.
(LET (plant1)
((setq plant1 (make-array '(4 4)))
(print plant1)
(setf (AREF PLANT1 0 0) 1)))
There are too many parentheses. The syntax of let has a body of code, which is a sequence of f... |
3,548,169 | 3,549,847 | Equivalent of 'lein swank' to other Lisp/Scheme implementations with emacs/slime | I've been using emacs/slime for coding lisp, but with Clojure I found 'lein swank'.
I must say that it's pretty useful, as I can connect to a server that runs clojure.
How about the other Lisp implementations? What Lisp implementations provide the equivalent of 'lein swank' in Clojure? I mean, is there any other Lisp ... | Non-clojure swank backends don't need a lein swank equivalent since they can just launch a lisp instance and change its load-path at runtime to make it work for a given project. That approach doesn't work with Clojure since the JVM's classpath can't be modified at runtime.
|
3,560,142 | 3,566,097 | lisp package differences between repl and compile file | I'm currently playing with lispbuilder-sdl on SBCL under Windows.
My source code is as follows:
(asdf:operate 'asdf:load-op :lispbuilder-sdl)
(asdf:operate 'asdf:load-op :lispbuilder-sdl-binaries)
(asdf:operate 'asdf:load-op :lispbuilder-sdl-examples)
(sdl-examples:squashed)
When I compile the file I get the error: pa... | All of the compilation of that file happens before executing any of the load-ops. So when Lisp compiles the (sdl-examples:squashed) line, it hasn't run the load-op that defines your package.
You can get around this by not mentioning the sdl-examples package that requires the reader to locate its squashed symbol before... |
3,571,457 | 3,571,475 | Does 'require' in elisp/lisp prevent from reloading libraries? | For C/C++, people use #ifdef .. #endif technique to prevent reloading libraries, and Objective-C uses import to do the same thing.
How about lisp/elisp? If (require 'cl) is used before, and (require 'cl) is seen somewhere, lisp is clever enough not to load it again? Or, is there any way to prevent this reloading librar... | No, elisp won't load it again. From the docs (C-h f require):
"If feature FEATURE is not loaded, load
it from FILENAME."
The same is true for Common Lisp:
"The require function tests whether a
module is already present (using a
case-sensitive comparison); if the
module is not present, require
proceeds to ... |
3,571,518 | 3,571,532 | Book for learning how to write Clojure/Lisp Macros | I'm reading "Programming Clojure" and I'm interested in a book that discusses how to create macros as extensive as possible.
Do you suggest a book for this?
Thanks.
| The quintessential book on Lisp macros is probably Paul Graham's On Lisp. It used Common Lisp, though, but that doesn't matter too much if what you really want to look at it macros, although Clojure's are different on a number of levels. (Clojure being a Lisp-1, to begin with.)
|
3,578,187 | 3,578,256 | Tasks unsuited for dynamic scoping | Can you give me some examples of tasks unsuited for dynamically scoped lisps? I'm failing to see how the Lexical scope is so much better and not just a matter of changing the coding style, so I'd love to code something and see it with my own eyes.
Thanks!
| (define (add n) (lambda (m) (+ n m)))
(define add4 (add 4))
(map (add 7) (list 1 2 3))
But that's just one tiny random example. If you dig far enough, you'll find several tons of additional reasons. For a more thorough discussion, you should really go through some textbook. My recommendation for this would be PLAI.... |
3,590,221 | 3,591,086 | What is the difference between a variable and a symbol in LISP? | In terms of scope? Actual implementation in memory? The syntax? For eg, if (let a 1) Is 'a' a variable or a symbol?
| Jörg's answer points in the right direction. Let me add a bit to it.
I'll talk about Lisps that are similar to Common Lisp.
Symbols as a data structure
A symbol is a real data structure in Lisp. You can create symbols, you can use symbols, you can store symbols, you can pass symbols around and symbols can be part of la... |
3,592,112 | 3,592,529 | Q about Problem 19-2 in "Lisp" by Winston and Horn | Problem 19-2 in "Lisp" by Winston and Horn states,
In depth-first search, all of the
partial paths in the queue at a given
point in the search are related to
one another in a simple way: each is
the extension by one node of the
partial path after it in the queue.
The queue might, for example, look
... | See answer by Pascal Bourguignon.
|
3,597,781 | 3,598,093 | Dr Racket problems with SICP | I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket to let me redefine "primitives". For instance, I was under the impression that I should be able to arbitrarily do (define + 5) and that would be fine, or redefine the sqrt procedure. Instead, I get this:
define-values: cannot ... | Even if possible, such redefinitions are not something that you should do without really understanding how the system will react to this. For example, if you redefine +, will any other code break? The answer to that in Racket's case is "no" -- but this is because you don't really get to redefine +: instead, you defin... |
3,606,736 | 3,608,199 | Multiple (define)s in a CL style macro | I'm currently learning how to write CL style macros (define-macro) in Scheme. As a simple example, I wrote a struct macro that defines functions like make-thing, thing?, thing-field accessors and so on.
Now I'd like to combine multiple defines in a single macro, but only the last one is actually used. Currently I'm usi... | You don't need eval here; use begin instead to group those definitions together into a list; i.e., the template to be expanded should be of the form:
`(begin
,@(map ...)
(define ...)
(define ...)
...)
Edit:
Change for-each to map as suggested by OP.
|
3,623,101 | 3,623,566 | How to extend emacs lisp mode with indentation changes and color changes | Im making a DSL in lisp (basically what i think is a nicer syntax), its the same thing as lisp except with different 'primitives', no instead of not, 'as' instead of let.Thus i need to change both indentation and color only in files which end in .goby (it should not effect ones which end in .lisp) So i would like to c... | There's probably a cleaner way, but a way that works is to rewrite 'lisp-indent-function to be 'goby-indent-function and use your own table of offsets like so:
(define-derived-mode
goby-mode lisp-mode "Goby"
"Major mode"
(set (make-local-variable 'lisp-indent-function) 'goby-indent-function))
;; goby specific of... |
3,636,980 | 3,638,388 | Function Erroneously Returning Nil | I'm trying to learn Lisp now, as a supplement to my CS1 course because the class was moving too slow for me. I picked up "Practical Common Lisp," which so far has turned out to be a great book, but I'm having some trouble getting some examples to work. For instance, if I load the following file into the REPL:
;;;; Crea... | Nothing, AFAICT:
$ sbcl
This is SBCL 1.0.34.0...
[[pasted in code above verbatim, then:]]
* (addRecord (makeCD "White Album" "The Beatles" 5 t))
((:TITLE "White Album" :ARTIST "The Beatles" :RATING 5 :RIPPED T))
* (select (artistSelector "The Beatles"))
((:TITLE "White Album" :ARTIST "The Beatles" :RATING 5 :RIPPE... |
3,641,509 | 3,641,947 | How can I do setf on a struct's accessors when using intern | I'd like to setf different fields of a struct depending on a certain variable. I decided to use the following approach:
Generate a string with the field's accessor name:
(setq my-string (format nil "STRUCT-ESTADISTICAS-NUM-~S" x))
and then use intern with funcall:
(funcall (intern my-string) *estadisticas*)
This ... | You want to call a writer function of the struct via its name, and the name of the writer is the list (setf accessor-name); so
(funcall (fdefinition (list 'setf (intern my-string))) 0 estadisticas)
Edit:
Not seeing the rest of your code, it's hard to fathom what went wrong. On SBCL this works for me:
(defstruct poin... |
3,657,118 | 3,658,771 | In clojure, is (= 'a 'a) referring to the 'same atom'? | In some implementations of Common LISP we can say that for the following expression
(eq 'a 'a)
Is true because 'a and 'a are the "same atom".
This may be implementation dependent, but it seems the phrase (used in a popular LISP teaching book) assumes that atoms of the same value are stored in the same location in mem... | First, "atom" has a different meaning in Clojure than in most other Lisps. See http://clojure.org/atoms
Clojure's = function uses value-based equality. So two objects with equal values will be = even if they are stored in different locations in memory.
To test if two objects are actually the same object, at the same ad... |
3,665,132 | 3,665,167 | What is the difference between an atom in Common Lisp and an atom in Clojure? | The following page talks about how atoms work in Clojure. It doesn't say a whole lot about the differences between atoms in Clojure and other lisp dialects.
What is the primary difference between an atom in Common Lisp and an atom in Clojure? (What is missing from the definition of atom in Clojure that exists in CL?)
| Atoms in Clojure and atoms in Common Lisp (and most other Lisps) are two completely unrelated concepts. They have nothing to do with each other, other than having the same name.
There is no 'difference'. It would be asking what is the difference between a window in a house and a window on your computer screen? It does ... |
3,670,010 | 3,670,343 | Apply-recur macro in Clojure | 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.
| 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 validity of the exercise, of course.
However, there is a problem in that a "proper"... |
3,672,256 | 3,672,317 | Let: creating a temporary variable in Common Lisp | Given a function:
(defun foo (bar)
(let ((baz bar))
(setf baz (+ baz 1)))
I have been given to understand (perhaps incorrectly?) that baz becomes some sort of reference to bar, instead of being a true copy of bar.
What I would like to do is create a true temporary variable so that I can ensure that I can muck abo... | I think I'd rather say "baz becomes a reference to the same thing that bar is a reference to". But you're right that let does not do any copying.
If you want to make a copy of bar, you certainly can, though how you do that depends on what bar is: a list, a vector, etc.
For the curious, Kent Pitman wrote a great articl... |
3,672,880 | 3,675,690 | More generic lisp code to generate combinations of pairs | Given this sad thing below, which generates all pairs of only two ranges -
[53]> (setq thingie '())
NIL
[54]> (loop for i in (generate-range 0 3) do
(loop for j in (generate-range 4 6) do
(push (list i j) thingie)))
NIL
[55]> thingie
((3 6) (3 5) (3 4) (2 6) (2 5) (2 4) (1 6) (1 5) (1 4) (0 6) (0 5) (0 4))
[56]> ... | (defun map-cartesian (fn bags)
(labels ((gn (x y)
(if y (mapc (lambda (i) (gn (cons i x) (cdr y))) (car y))
(funcall fn x))))
(gn nil (reverse bags))))
CL-USER> (map-cartesian #'print '((1 2) (a b c) (x y)))
(1 A X)
(2 A X)
(1 B X)
(2 B X)
(1 C X)
(2 C X)
(1 A Y)
(2 A Y)
(1... |
3,679,234 | 3,679,323 | Are the variables *,+, and / bound to recent input in SLIME or Clozure CL? | I was messing around in SLIME (connected a Clozure REPL) when I discovered this:
It looks like the variables +, *, and / are all bound to some variation on recent input, + is the input itself, * is the result of evaluating that input, and / is the result contained in a list.
Is this right? Who is responsible for this, ... | Those are all, and more, specified by the Common Lisp standard. Search the environment dictionary for 'Variable'.
|
3,680,980 | 3,683,707 | Emulating lisp cons cells in Tcl | A list in lisp is a series of cons cells, but in Tcl, a list is a string with whitespace separating the elements. For translating code from lisp to tcl, one might simply take lisp lists and translate them to Tcl lists. However, this runs into trouble with side effecting cons cells not coming across to the Tcl code. ... | Lisp cons cells can't be directly modeled as Tcl values because of fundamentally different semantic models. Lisp uses a model whereby values are directly updatable; the value is the memory cell. Tcl uses a different model with values which are conceptually immutable and where there is no difference in principle between... |
3,681,599 | 3,773,048 | Lisp influence on on Factor programming language? | I have read (from Slava Pestov) that Factor was influenced by Lisp, but I am not sure that I can understand how? Are they not very difference programming languages?
| Even though the language is stack based there are plenty of elements that show a clear lisp influence. Take the IF statement as an example. In forth If statements are cond IF (code if true) ELSE (code if false) THEN and the definition of If acts on the runtime to make sure the correct branch is run. If in factor is a... |
3,681,708 | 3,681,793 | Closures and dynamic scope? | I think I understand why there is a danger in allowing closures in a language using dynamic scope. That is, it seems you will be able to close the variable OK, but when trying to read it you will only get the value at the top of global stack. This might be dangerous if other functions use same name in the interim.
Ha... | Yes, that's the basic problem. The term "closure" is short for "lexical closure", though, which by definition captures its lexical scope. I'd call the things in a dynamically scoped language something else, like LAMBDA. Lambdas are perfectly safe in a dynamically scoped language as long as you don't try to return them.... |
3,681,712 | 3,681,728 | Turning off the result printing in common lisp | I am working with a reasonably large dataset in GNU clisp. It would be really nice if I could turn off the P of the REPL. Having thousands of results spew across my screen really isn't very useful.
I rummaged through the docs and couldn't find out how to turn it off. I assume it's one of the variables.
| You might try changing the value of *print-length*.
|
3,683,388 | 3,685,147 | Given the following LISP eval function - what is required to add defmacro? | Given the following definition of the LISP eval function - what is required to add the defmacro function? (Or even just evaluate a macro)
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x (cond (y 't) ('t '())))
('t '())))
(defun not. (x)
(cond (x '())
('t 't)))
(defun append. (x y)
... | The representation of an anonymous macro is by convention a list of the form (macro lambda ...). Try evaling these in your favorite Lisp interpreter (tested in Emacs):
> (defmacro triple (x) `(+ ,x ,x ,x))
triple
> (symbol-function 'triple)
(macro lambda (x) (\` (+ (\, x) (\, x) (\, x))))
Although things don't work th... |
3,689,855 | 3,690,050 | How to guess out the grammars of a list of sentences generated by some way? | I have a lost of sentences generated from http://www.ywing.net/graphicspaper.php, a random computer graphics paper title generator, some of example sentences sorted are as following:
Abstract Ambient Occlusion using Texture Mapping
Abstract Ambient Texture Mapping
Abstract Anisotropic Soft Shadows
Abstract Approximat... | This seems to be an interesting problem. How ever, I was under the impression that it is not easy to guess a generator from it's generated sequence of bits. What you can get is a model that may be or may not be a close approximation of the original generator. The approximation will be closer when a large number of sequ... |
3,693,323 | 3,694,071 | How do I manipulate parse trees? | I've been playing around with natural language parse trees and manipulating them in various ways. I've been using Stanford's Tregex and Tsurgeon tools but the code is a mess and doesn't fit in well with my mostly Python environment (those tools are Java and aren't ideal for tweaking). I'd like to have a toolset that wo... | This is a typical case of using Lisp. You would need a function that maps another function over the tree.
Here is a procedural matching example using Common Lisp. There are matchers in Lisp that work over list structures, which could be used instead. Using a list matcher would simplify the example (see my other answer ... |
3,693,447 | 3,693,926 | Cannot create apply function with static language? | I have read that with a statically typed language like Scala or Haskell there is no way to create or provide a Lisp apply function:
(apply #'+ (list 1 2 3)) => 6
or maybe
(apply #'list '(list :foo 1 2 "bar")) => (:FOO 1 2 "bar")
(apply #'nth (list 1 '(1 2 3))) => 2
Is this a truth?
| A full APPLY is difficult in a static language.
In Lisp APPLY applies a function to a list of arguments. Both the function and the list of arguments are arguments to APPLY.
APPLY can use any function. That means that this could be any result type and any argument types.
APPLY takes arbitrary arguments in arbitrary le... |
3,702,030 | 3,702,161 | Common Lisp - Using a function as input to another function | Say I have a function that takes a list and does something:
(defun foo(aList)
(loop for element in aList ...))
But if the list is nested I want to flatten it first before the loop does stuff, so I want to use another function (defun flatten(aList)) that flattens any list:
(defun foo(flatten(aList))
(loop for ele... | Here's one way:
(defun foo (alist)
(loop for element in (flatten alist) ...)
|
3,707,434 | 3,709,387 | Which Scheme IDE's are there? | I am planning on learning Scheme (by following
SICP) and afterwards doing a project with this language. However, I was wondering what would be a good IDE for this? I've looked around a bit, but could not really find very much, except something called Edwin?
| Other answers have given all the good choices, but without much description. Here's some more detail:
DrRacket
Racket's IDE, DrRacket, is a great tool for beginners and has a lot of strengths for more advanced schemers. It has good profiler and debugger support (far better than Emacs), uses "standard" keyboard shortc... |
3,708,793 | 3,709,846 | Common Lisp: Why not the array literal evaluate arguments? | Why is it that the Common Lisp array syntax is not evaluating its arguments:
(let ((a 1)) #2A((a 2) (3 4)))
=> #2A((A 2) (3 4))
I would have guessed it was #2A((1 2) (3 4)). Is this because A is not available at reader time?
| In short, yes.
#2A((A 2) (3 4)) is not an abbreviation ("syntactic sugar") for (make-array '(2 2) :initial-contents (list (list a 2) (list 3 4))). If anything, it could be rationalized as (make-array '(2 2) :initial-contents (quote ((A 2) (3 4)))), but this would be a bit misleading as the array construction already h... |
3,723,579 | 3,723,657 | Is there a way to dereference a list in common lisp? | Is there a way to dereference a list in lisp?
I am trying to compare 2 strings but one is in a list.
| It sounds like you want car. If your second structure looks like '("string"), then you want
(car '("string"))
If the string is not the first element in the list, you probably want (for example)
(nth 2 '(1 symbol "string"))
Remember to compare strings you want equal, not = which is for numbers only.
|
3,725,637 | 3,725,905 | Why to use LISP today, when there are Scala, Erlang, Haskell etc | In the past LISP was the only powerful functional programming language, as far as I understand. Now there are lots, why do people still use LISP with its weird syntax? Is there a unique killer-feature of a kind?
| First, Lisp in general and Common Lisp in particular is more "multi-paradigm" than "functional". From here on, I will mostly discuss Common Lisp (CL).
There isn't "one killer feature", though. CL is a programmable programming language, making it easy to do meta-programming. That is, you can usually do "meta-level" thin... |
3,732,173 | 3,732,241 | Multiple lines comments in Scheme (RnRS) | I created this solution:
; use like this:
; (/* content ... */ <default-return>)
; or
; (/* content ... */) => #f
(define-syntax /*
(syntax-rules (*/)
((/* body ... */) #f)
((/* body ... */ r) r)))
But is it really the best or easiest way?
| You can't do it this way -- it won't work for a number of contexts. Here are some examples that won't work:
(+ (/* foo */) 1 2)
(define (foo a (/* b */) c) ...)
(/* foo; bar */)
(/*x*/)
(let ((x (/* 1 */) 2))
...)
(let ((/* (x 1) */)
(x 2))
...)
(car '((/* foo */) 1 2 3))
There is no standard multi-li... |
3,732,416 | 3,732,462 | Problem with treetop grammar, not matching all options | I am writing a small, really simple lisp parser in ruby with the treetop gem just to experiment with it. However, it is not really working out how I want it to, and the documentation is pretty poor so it's hard to understand what I am doing wrong. Currently, the grammar can match both a symbol and a boolean, but not a ... | The way you defined the rules number and symbol they always match (because * means "zero or more" and you can always find zero of something). This means that if you try to parse "42", the parser first successfully matches the rule symbol against the empty string at the beginning and then expect no further input.
To fix... |
3,744,780 | 3,744,998 | Does "The whole language always available" hold in case of Clojure? | Ninth bullet point in Paul Graham's What Made Lisp Different says,
9. The whole language always available.
There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or run code while compiling, and read or compile code at runtime.
Running code at read-t... | You can mix runtime and compile-time freely in Clojure, although Common Lisp is still somewhat more flexible here (due to the presence of compiler macros and symbol macros and a fully supported macrolet; Clojure has an advantage in its cool approach to macro hygiene through automagic symbol resolution in syntax-quote).... |
3,748,225 | 3,749,353 | Accessing active symbol table in Common Lisp | I have heard that the active symbol table is accessible within the Common Lisp runtime. Have I misunderstood?
| 'Symbol tables' are called 'packages' in Common Lisp. See for example: Introduction to Packages, CL HyperSpec.
Several operations over packages are available in Common Lisp: The Packages Dictionary.
Symbols can be members of packages (being 'interned').
The variable *package* holds a package as a value, which is used b... |
3,761,981 | 3,763,262 | In SICP 3.2, The Environment Model of Evaluation, is an environment initially the same as its first frame? | In The Structure and Interpretation of Computer Programs part 3.2, an "environment" is defined as "a sequence of frames." But as far as I can see, the book doesn't further discuss the difference between an environment and a frame. Also, I suspect the drawings of environments conflates them with frames because books d... | The sequence of frames is the linked list (of frames) pointing 'upwards' towards the global environment. So when an environment is created (for example, in the context of a procedure binding), the 'environment' is a pointer to the frame...which in term points to the enclosing environment (or null, if the global enviro... |
3,767,972 | 3,768,156 | Displaying a string while using cond in Lisp | I'm just starting off with Lisp and need some help. This is technically homework, but I gave it a try and am getting somewhat what I wanted:
(defun speed (kmp)
(cond ((> kmp 100) "Fast")
((< kmp 40) "Slow")
(t "Average")))
However, if I run the program it displays "Average" instead... | You can also use symbols instead of strings:
(defun speed (kmp)
(cond ((> kmp 100) 'fast)
((< kmp 40) 'slow)
(t 'average)))
Symbols are uppercased by default, so internally fast is then FAST.
You can write any symbol in any case and with any characters using escaping with vertical b... |
3,769,373 | 3,769,433 | Some languages and uses for monads | According to you, which language do you think would be the best for implementing monads (Python/Ruby/LISP)?,also can anyone tell me some possible uses of monads (please give examples),like exceptions?
Thanks in advance
| All About Monads - legendary tutorial that lists all the standard monads and gives a lot of real-world examples. Popular monads that you can meet even in the mainstream languages are Maybe, List and Continuation.
Some people also think that jQuery itself is a monad (as it follows the monadic axioms).
As for the langua... |
3,772,365 | 3,772,819 | How to defun a function within a defun? | For example, I pass the function name to another function
(personal-function 'func-name '(attr1 attr2 ...))
and what I want to do is
(defun personal-function (func-name)
(defun func-name '(attr1 attr2 ...) (dosomething)))
However, it said I can't defun with a symbol... What should I do?
| Use
(setf (symbol-function my-symbol) some-function)
create a new function with
(compile nil (list 'lambda args body))
where args and body have meaningful values.
|
3,772,765 | 3,774,577 | Is there a relationship between calling a function and instantiating an object in pure functional languages? | Imagine a simple (made up) language where functions look like:
function f(a, b) = c + 42
where c = a * b
(Say it's a subset of Lisp that includes 'defun' and 'let'.)
Also imagine that it includes immutable objects that look like:
struct s(a, b, c = a * b)
Again analogizing to Lisp (this time a superset), say a st... | Both f and make-s are functions, but the resemblance doesn't go much further. Applying f calls the function and executes its code; applying make-s creates a structure.
In most language implementations and modelizations, make-s is a different kind of object from f: f is a closure, whereas make-s is a constructor (in the... |
3,772,916 | 3,773,081 | What is the future of LISP? Should I learn it? | I know this is not a very technical question, but it's for all technical people, that's why I ask it here. Here is my question:
Can someone help me understand the current and future of learning LISP? One of my papers in university uses LISP for a project (it's a big project - may be two semester long), and I am not ab... | If you have a real interest in software development, you should learn Lisp and other programming languages.
Ruby, Python and Perl are distant relatives of Lisp. A bit nearer is Javascript - which is basically a primitive Lisp with a strange non-programmable syntax.
The core of Scheme is relatively clean and quite power... |
3,780,228 | 3,780,596 | overview, but very over in functional programming | What does a very general function look like in functional programming?
Somebody said "we don't have objects, but we have higher order functions". Do higher order functions replace objects?
While programming object-oriented apps, I try to go from a more general to a more detailed idea, lots of times. If I try to do that... | This answer is oriented towards Haskell rather than Lisp because although lisp has higher order functions, idiomatic lisp can be and is often very object-oriented.
We'll also ignore inheritance (and ad-hoc polymorphism) which is commonly associated with object oriented programming, but is somewhat orthogonal.
In genera... |
3,787,980 | 3,788,113 | Design By Contract LIbrary(ies) for Common Lisp? | Coming from a background in Clojure, I am taken with the potential that its pre-/post-conditions provide as a basis for design by contract:
;; sqr.clj
(defn sqr [n]
{:pre [(not= 0 n) (number? n)]
:post [(pos? %) (number? %)]}
(* n n))
(sqr 10)
;=> 100
(sqr 0)
; Assertion error
Is there a similar pre/post ca... | it is relatively trivial to write a macro that can be used like this:
(defun sqr (n)
(with-dbc-checked
(:pre ((not (zerop n)) (numberp n))
:post ((plusp %) (numberp %)))
(* n n)))
For CLOS generic functions, see here: http://www.muc.de/~hoelzl/tools/dbc/dbc-intro.html
Btw., from this code it can be s... |
3,791,065 | 3,791,406 | Why am I getting this lambda expression error, and what can I do about it? | I'm pretty new to lisp; I was wondering if anyone here could help me out.
I have the following code snippet:
(defun write-lookup (binding-list pattern fact)
(cond
; No bindings have been stored
; Return the binding list with a new one!
((not binding-list) (cons (cons pattern fact) nil))
... | First you need to indent your code properly:
(defun write-lookup (binding-list pattern fact)
(cond
; No bindings have been stored
; Return the binding list with a new one!
((not binding-list) (cons (cons pattern fact) nil))
; A list of bindings is being stored
(cond
; The c... |
3,793,030 | 3,793,170 | Mapping Languages to Paradigms | I recently read Eric Steven Raymond's article "How To Become A Hacker" and I like his suggestion of learning 5 key languages (he suggests Python, C/C++, Lisp, Java, and Perl) as a way of covering the main programming paradigms in use today.
His advice is that it's not so important which specific languages a programmer ... | I think you're approaching it wrong. As esr himself says, it's not the language that matters, it's the paradigm. So when you say that
Perl is a functional language
It's great for quick text substitutions in multiple files from the command line
you are missing one of the main points of a functional language which i... |
3,793,083 | 3,796,257 | Scheme Code Analysis for Space vs. Time | I'm working my way through the online MIT lectures for the classic 6.001 course: The Structure and Interpretation of Computer Programs.
I'm trying to gain an understanding of analyzing code complexity in terms of memory usage vs. execution time. In the first few lectures, they present a solution in Scheme for the Fi... | Well, considering that (fib n) causes n-1 calls to fib-helper, your solution runs in linear time. fib-helper only calls itself once for each iteration, and each iteration is a tail call, so your program runs in constant space.
This means that a call to (fib 1000) should only take about ten times the CPU time of (fib 1... |
3,795,895 | 3,795,922 | Problem with access of slots in Lisp (CLOS) | I have a Node class that has an 'element' slot which contains a list with numbers and one letter, for example:
'(1 2 3 b 4 5 6)
(defclass node ()
((element :reader get-element
:writer set-element
:initform '()
:initarg :element
:documentation "The element"))
Part of t... | Reverse creates and returns a new list. Rotatef (just as setf, incf and the like) modify a place. You will have to copy-list or copy-tree your element to create a new list that you then modify.
|
3,795,954 | 3,796,019 | Why is read-line run twice for reading from a file in Lisp? | This is the code to implement the 'cat' command with lisp, as is explained in the book ANSI Common Lisp, page 122.
(defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(do ((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(format t "~A~%" ... | The syntax of DO variables is: variable, initialization form, update form. In this case, the initialization form is the same as the update form. But there is no shorthand for that case in DO, so you have to write it out twice.
|
3,798,617 | 3,798,659 | How to do Pattern Matching in Common Lisp | I have no idea if there exists a pattern matching function for Common Lisp, nevertheless I have to make my own function. I have no idea about Lisp. Can somebody give heads-up on learning Lisp and most importantly, how to go about doing pattern matching in Lisp. I will have to pass a pattern and a fact and say if they m... | Simple pattern matching functionality is explained in various Lisp books.
Lisp, 3rd edition, Winston/Horn
Paradigms of Artificial Intelligence Programming, Case Studies in Common Lisp, Peter Norvig
and others.
Above books explain implementing pattern matching in Lisp very well.
Libraries exist, for example trivia, cl... |
3,805,294 | 3,911,317 | SICP, Scheme, DrRacket Question: Timer/profiler function? | I'm currently trying to do exercise 1.22, which needs a function called runtime that returns the number of milliseconds the system has been running. However, my environment (R5RS) does not seem to have this. It does not have time, current-milliseconds, current-inexact-milliseconds, etc, either.
What function do I have... | Probably, the best thing to do is switch the language in DrRacket to "Use the language declared in the source", and start your file with #lang racket. Then functions like current-seconds and friends will be available.
Alternatively, you could use the profiling library, available via (require profile) and documented he... |
3,809,602 | 3,811,088 | How to return control from a function in lisp | (defun returnFirstCharacter(p)
(if (symbolp p) (char (symbol-name p) 0) nil)
)
(defun returnRestCharacters (p)
(let ()
(intern (subseq(string p) 1))
)
)
(defun val (x a)
(cond ((null a) nil)
((equal (car(cdr a)) x) (cdr (cdar a)))
(t (val x (cdr a)))
)
)
(defun match (patter... | This looks like part of a COND block. With that assumption in mind, I've added the COND back in and re-formatted the code to make it a bit more obvious.
(cond ((alpha-char-p (returnFirstCharacter p))
(let () (if (equal p d) (match2 nil nil a) nil)))
((equal (returnFirstCharacter p) #\=)
(let ()
... |
3,811,448 | 3,812,208 | Can call-with-current-continuation be implemented only with lambdas and closures? | Does anyone know if call/cc can be implemented with just lambdas and closures?
It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures.
Any more ideas?
| The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean?
In any case, continuations can be used in any language with closures by manually writing in continuation passing style. Then automatic translation into this form can be implemented by extending the compile... |
3,817,063 | 3,817,603 | Struggling with common lisp libraries | I've learned scheme and quickly mastered a lot of it, then did a project in it just fine. Literally took me days to finish. I'm now trying to learn common lisp to get a feel for that and now I'm just really really struggling with trying to learn asdf. It seems to be common knowledge how to use it with libraries but I'm... |
I really want to be able to make an
executable to give to people without
having to explain how to install sbcl
and (require) it then run it.
You do not need ASDF in order to produce a 'stand-alone' executable. Most implementations provide means to save an executable image, but how to do this (and if it is to be... |
3,818,443 | 3,819,138 | How to make and use library with lisp (clisp)? | In C/C++, I can make a library, and make it static one or dll using #include "" in source code, and -labc when linking.
How do I have the same feature in lisp?
As an example of util.lisp in directory A. I define a library function hello.
(defpackage "UTIL"
(:use "COMMON-LISP")
(:nicknames "UT")
(:export "HELLO")... | You have to load util.lisp before main.lisp:
> (load "util.lisp")
> (load "main.lisp")
> (main)
hello, world
NIL
Practical Common Lisp has a good introduction to defining and using packages.
|
3,840,443 | 3,840,621 | How to go about learning Common Lisp and Emacs Lisp? | The last few months I've been using Emacs extensively as my main development environment and I've now come to a point at which I'd like to learn it's own Emacs Lisp to write my own little stuff for Emacs and extend it to my personal needs.
Having said that I've also wanted to learn Common Lisp for a while now, to play ... | Start with Emacs Lisp (given that you seem to have already started customizing your emacs) - it seems to be more immediately useful for you.
Do keep in mind that there is quite a bit of difference between Emacs Lisp (there is a lot of buffer management stuff, especially in the code you're likely to see in the wild) and... |
3,843,980 | 3,844,036 | What is WITH-STANDARD-IO-SYNTAX macro for? | The Practical Common Lisp page 25, explains the WITH-STANDARD-IO-SYNTAX as follows. "It ensures that certain variables that affect the behavior of PRINT are set to their standard values".
The usage is as follows.
(with-open-file (...)
(with-standard-io-syntax
(print ...
Should (print) be used in this macr... | Various dynamic variables affect the output produced by print. with-standard-io-syntax ensures those variables are set to the default values.
For example:
(let ((list '(1 2 3 4 5 6 7 8 9 10))
(*print-length* 5))
(print list)
(with-standard-io-syntax
(print list)))
Prints:
(1 2 3 4 5 ...)
(1 2 3 4 5 6 7... |
3,848,724 | 4,887,804 | Help with installing ECL (Embeddable Common Lisp) via mingw32 or mingw-64 on Win7-64 | I'm trying to compile ECL 10.4.1 on my Win7 64-bit box, but am having issues.
I've attempted the build with both mingw32/MSYS and mingw-w64/MSYS, using the exact packages linked to here. Both have failed.
With mingw32: ./configure passes, make fails as follows:
gcc -DECLDIR="\"/usr/local/lib/ecl-10.4.1\"" -I. -Ic:/my_... | Firt, 10.4.1 is really old release. Update to at least 11.1.1, or, preferably git version.
Then, you need to install mingw32 (preferably using mingw-get) and msys.
After that, you need to install mingw32-gmp-dev package (or manually compile it), boehm-gc-7.2alpha2 and libffi.
Given all that you should start your msys s... |
3,849,045 | 3,849,620 | Increase Minimum Stack Overflow Size in Mac Common Lisp 5.0 | I'm relatively new to Lisp (I just know the very basics) and I'm currently trying to run an algorithmic composition program created by David Cope. It runs in MCL 5.0, and I keep getting the following error:
Error in process play: Stack overflow on value stack.
To globally increase stack space, increase *minimum-stac... | It seems to say that you simply need to modify the special variable *minimum-stack-overflow-size*. When you are at the REPL (CL-USER> prompt or similar), inspect this variable by evaluating its name:
CL-USER> *minimum-stack-overflow-size*
Then, set it to a bigger value (the 1234567 is just a placeholder) with setf:
C... |
3,851,502 | 3,853,697 | Opening an HTML page in a browser from Common Lisp | My Common Lisp program writes out an HTML file. I then want to launch this file in the user's default browser.
Is there a way of doing this in Common Lisp? Moreover, is there an OS-independent way of doing this?
| This depends on the Common Lisp implementation and possibly the platform it runs on (Windows, Mac, Linux, ...).
LispWorks provides the function SYS:OPEN-URL. See http://www.lispworks.com/documentation/lw60/LW/html/lw-1369.htm#pgfId-1219832
(sys:open-url "http://www.foo.com/")
One certainly can also use a file URL.
|
3,855,862 | 3,857,334 | setq and defvar in Lisp | I see that the Practical Common Lisp uses (defvar *db* nil) for setting up a global variable. Isn't it OK to use setq for the same purpose?
What are the advantages/disadvantages of using defvar vs. setq?
| There are several ways to introduce variables.
DEFVAR and DEFPARAMETER introduce global dynamic variables. DEFVAR optionally sets it to some value, unless it is already defined. DEFPARAMETER sets it always to the provided value.
SETQ does not introduce a variable.
(defparameter *number-of-processes* 10)
(defvar *world... |
3,856,917 | 3,856,973 | Lisp's apply and funcall vs Python's apply | Lisp's APPLY is for calling functions with computed argument stored in lists.(Modified from Rainer's comment)
For example, the following code changes (list 1 2 3) to (+ 1 2 3).
(apply #'+ '(1 2 3))
However, Python's apply does what Lisp's funcall does, except for some minor differences (input is given as tuple/list)... |
Is there any reason why Python chose the name apply not funcall?
Because it's Python, not LISP. No need to have the same name, funcall is a LISP command and apply is something different in Python.
apply is deprecated in Python, use the extended call syntax.
Old syntax:
apply(foo, args, kwargs)
New syntax:
foo(*args,... |
3,858,746 | 4,249,756 | Audacity Nyquist Plugin | I am playing around with Audacity and have been trying to generate tones with harmonics. Audacity does not seem to support it directly, but you can write a plugin to do it. The plugins are written in Nyquist (a variant of lisp) and there a small tutorial here. I do not have any experience with lisp and just want to wri... | Try the Buzz Tone example from the Sample Nyquist plugins for Audacity(at Sourceforge). I've never coded one of these, yet this example seems to make sense.
Also see Touch Tones.
|
3,859,765 | 3,860,014 | Why does let require a vector? | I never really thought about this until I was explaining some clojure code to a coworker who wasn't familiar with clojure. I was explaining let to him when he asked why you use a vector to declare the bindings rather than a list. I didn't really have an answer for him. But the language does restrict you from using l... | Mostly readability, I imagine. Whenever bindings are needed in Clojure, a vector is pretty consistently used. A lot of people agree that vectors for bindings make things flow better, and make it easier to discern what the bindings are and what the running code is.
Just for fun:
user=> (defmacro list-let [bindings & bod... |
3,868,658 | 3,868,950 | defmacro with defclass | I have a class in Common Lisp:
(defclass my-cool-class()
((variable1
:initarg :variable1
:accessor variable1
:initform (error "Must supply value to variable1"))
(variable2
:initarg :variable2
:accessor variable2
:initform (error "Must supply value to variable2"))
I wanted to create a macro... | You can't put macros in code where you want. Read the syntax for a construct in CLHS.
For example you can't do:
(defun foo (make-arg-list 'a 'b) a b)
DEFUN expects an arglist and not a function that creates an arglist.
Lisp expands macros, where Lisp forms are expected. Where other lists (for example a list of slots) ... |
3,878,687 | 3,878,863 | capturing cl-fad:walk-directory output for finding files | I've wrestled with this for hours I'm trying to write a find file function similar to the unix command. The long and short of it boils down not understanding why I can't return a proper value from the cl-fad:walk-directory function as a list (cl-fad is here http://weitz.de/cl-fad/).
I'm trying something like this:
(cl-... | The walk function doesn't collect return values like mapcar, it just applies. You'll need to save the output yourself somewhere, perhaps appending to a global list or stack.
(let (files)
(cl-fad:walk-directory "/tmp/" #'(lambda (x) (push (namestring x) files)))
files)
Note that namestring converts from p... |
3,893,808 | 3,893,902 | Are there easy way of installing Lisp library such as ruby gem (Ruby) or easy_install (Python)? | I find easy_install extremely useful for programming with Python, and the same as rubygem with Ruby.
Does Lisp have similar feature? I understand that there are many Lisp implementations (clisp, sbcl, clozure cl ...), but I just wanted to know what would Lispers do when they need to find and use Lisp library functions.... | It's been a tricky problem, and there have been several attempted solutions.
I recently did a survey of Common Lisp users, and most of them simply manage libraries by hand by downloading project archives and checking things out of git, cvs, svn, etc.
The next most popular method of library management is a program calle... |
3,896,542 | 3,896,240 | In Lisp (Clojure, Emacs Lisp), what is the difference between list and quote? | From reading introductory material on Lisp, I now consider the following to be identical:
(list 1 2 3)
'(1 2 3)
However, judging from problems I face when using the quoted form in both Clojure and Emacs Lisp, they are not the same. Can you tell me what the difference is?
| By numbers do you mean the strings?
var_dump(array_values($your_array));
|
3,904,248 | 3,940,581 | Is cl-opengl glut mature? | I want to create my own editor to code in, at first I was going to use ncurses to make a terminal editor. Not working, the library has no documentation and it's mail list is completely empty. I'm probably going to make it with a gui library instead. I'm thinking of just using glut from cl-opengl, but I can't find any i... | It's better to use lispbuilder. It's by far more complete than cl-opengl.
But if you want a gui library for lisp you can try wxcl.
|
3,911,103 | 3,911,879 | Extracting a list inside a list | I am having problems extracting a list from a list.
(defun delete (a l)
(cond
((null l) nil)
((eq (car l) a) (delete a (cdr l)))
(t (cons (car l) (delete a (cdr l))))))
It deletes whatever is 'a' in a list l but if l consists of another list and a is in that inner list then my program can't r... | There is not only one possible solution, but I will stay close to your code. Since this is homework, I will not give you a working answer, but I will try to give you some things to think about, and give detailed pointers:
Try to understand what your code does and what you really want it to do:
(defun remove-all (a l)
... |
3,920,193 | 3,922,204 | What would be an example of an anaphoric conditional in Lisp? | What would be an example of an anaphoric conditional in Lisp? Please explain the code as well.
| An example is the Common Lisp LOOP:
(loop for item in list
when (general-predicate item)
collect it)
The variable IT has the value of the test expression. This is a feature of the ANSI Common Lisp LOOP facility.
Example:
(loop for s in '("sin" "Sin" "SIN")
when (find-symbol s)
collect it)
retu... |
3,928,689 | 3,944,577 | What programming languages have the most easily-implemented interpreters? | I need to implement an interpreter for a programming language as part of a project I'm working on. I don't think the details of this project are too relevant, except that it requires me to implement an interpreter from scratch, I can't use an existing programming language (the requirements include supporting portable ... | This sounds like a job for Lua.
It's a small language, designed to be simple to implement
There are already several implementations in Java and at least works in progress for Javascript.
Its syntax meets your requirements (assignments, infix operators).
The work you'd have left is to implement delimited continuations... |
3,936,919 | 3,936,962 | Checking whether every list in a list is null in Common Lisp | I know that I can check whether a list of lists only contains null lists like this
CL-USER> (null (find-if (lambda (item) (not (null item))) my-list))
where my-list is a list of lists.
For example:
CL-USER> (null (find-if (lambda (item) (not (null item))) '(nil (bob) nil)))
NIL
CL-USER> (null (find-if (lambda (item) (... | The higher order function every takes a predicate function and a list and returns true iff the predicate returns true for every element in the list.
So you can just do:
(every #'null my-list)
|
3,950,601 | 3,950,697 | Swapping elements in a Common Lisp list | Is there a Common Lisp function that will swap two elements in a list given their indices and return the modified list?
| You can use rotatef:
(rotatef (nth i lst) (nth j lst))
Of course, list indexing can be expensive (costing O(size of list)), so if you do this with any regularity, you'd rather want to use an array:
(rotatef (aref arr i) (aref arr j))
|
3,954,977 | 3,956,911 | Clojure: gc overhead limit exceeded, lazy evaluation, pi sequence | For the next code:
(ns clojure101.series)
(defn avg [[x y]] (/ (+ x y) 2))
(defn avg-damp
[seq]
(map avg (partition 2 seq)))
(defn avg-damp-n
[n]
(apply comp (repeat n avg-damp)))
(defn sums
[seq]
(reductions + seq))
(defn Gregory-Leibniz-n
[n]
(/ (Math/pow -1 n) (inc (* 2 n))))
(def Gregory-Leibn... | Hmm... This works for me. Tested with Clojure 1.2 on Windows XP.
user=> (defn avg
[xs & {:keys [n] :or {n 2}}]
(/ (reduce + xs) n))
#'user/avg
user=> (defn Gregory-Leibniz-n
[n]
(/ (Math/pow -1 n) (inc (+ n n))))
#'user/Gregory-Leibniz-n
user=> (->> (range)
(map #(* 4 (Grego... |
3,960,140 | 3,960,895 | Have some way to save the REPL state of Common Lisp or Scheme? | Have some way to save the REPL state of Common Lisp or Scheme?
Thanks
| Most Scheme implementations compile to either C or some other intermediary format, so I know of none that provide for saving the current image state. Most will compile binaries though, so if that's what you're really after read your implementation manual.
Common Lisp, on the other hand, usually provided this in an impl... |
3,964,795 | 3,965,222 | Common Lisp Wildcard for eql | Is there a wildcard in Common Lisp that is eql to any atom?
That is, is there any wildcard such that
(eql wildcard any-atom)
returns true?
| No.
The purpose of EQL is to compare for equality of value for certain primitive type objects (numbers, characters) and to compare for identity for all other objects (symbols, arrays, conses, structures, streams, CLOS objects, ...).
Thus it makes no sense to have something that is 'identical' to everything else. The pu... |
3,974,311 | 3,975,462 | Data structure with two primary keys? (caching lat/lon address pairs) | I'm trying to cache lat/lon address pairs from Google Maps, so I need a data structure where the key is two ints (lat and lon). What's the simplest data structure for that?
I thought of two ways so far:
Nested hash:
{37.734608 {-121.913019 "San Ramon, CA" -121.6 "Tracy, CA"}}
Concat the two to make the key:
{"37.73460... | As you have lisp in your tags, the simplest and most idiomatic way is to use an association-list:
;; Sample in Scheme
> (define lat/lon (list (cons '(3.44 5.44)
'("blah" "3.44,5.44" "bloo"))
(cons '(37.734608 -121.913019)
'("San... |
3,981,314 | 3,981,492 | hacker news algorithm in php? | This is the Hacker News ranking algorithm, which I think is a simple way of ranking things, espcially if users are voting on items, but I really dnt understand this, can this be converted to PHP, so I can understand it fully?
; Votes divided by the age in hours to the gravityth power.
; Would be interesting to scal... | Directly ripped from http://amix.dk/blog/post/19574 and translated to PHP from the Python:
function calculate_score($votes, $item_hour_age, $gravity=1.8){
return ($votes - 1) / pow(($item_hour_age+2), $gravity);
}
|
3,995,832 | 3,996,022 | What does #[...] mean in emacs-lisp? | I am puzzled by the expression
#[nil "\300\207"
[nil]
1]
as a value of skeleton-pair-filter-function.
Is this an alternative way of writing function in elisp? Or lisp in general?
Thanks.
| It's a byte code function object, the result of byte compiling a function.
See manual entry here
|
4,003,115 | 4,003,127 | Strange Lisp Quoting scenario - Graham's On Lisp, page 37 | I'm working my way through Graham's book "On Lisp" and can't understand the following example at page 37:
If we define exclaim so that its return value
incorporates a quoted list,
(defun exclaim (expression)
(append expression ’(oh my)))
> (exclaim ’(lions and tigers and bears))
(LIONS AND TIGERS AND BEARS OH MY)
... | nconc is a destructive operation that alters its first argument by changing its tail. In this case, it means that the constant list '(oh my) gets a new tail.
To hopefully make this clearer. It's a bit like this:
; Hidden variable inside exclaim
oh_my = oh → my → nil
(exclaim '(lions and tigers and bears)) =
lions ... |
4,003,385 | 4,003,528 | Reorder function arguments in Lisp | I'm interested in an operator, "swap-arg", that takes as input 1) a function f of n variables, and 2) index k, and then returns a the same function except with the first and kth input variables swapped. eg (in mathematical notation):
(swap-arg(f,2))(x,y,z,w) = f(z,y,x,w)
Now my first idea is to implement this using rot... | Using APPLY:
(defun create-swapped-arg-function (f k)
"Takes as input a function f of n variables and an index k.
Returns returns a new function with the first and kth input variables swapped,
which calls the function f."
(lambda (&rest args)
(apply f (progn
(rotatef (nth k args) (first args))
... |
4,010,260 | 4,012,719 | Play MIDI file from Common Lisp | Is it possible to play a MIDI file (existing on the hard drive) from Common Lisp? If so, how?
| If your Common Lisp implementation supports FFI, you might be able to use a library like PortAudio. (Also see the Common Lisp Foreign Function Interface project). Another option is to use the venerable Simple DirectMedia Layer which already have Lisp bindings. (But you may also have to get Timidity).
|
4,012,025 | 4,012,514 | How would a LISP developer solve the problem that AutoMapper solves in .NET? | I.e. transferring the state from one object to another object, which shares some (but not all) of the first object's members.
I'm not applying this question to any real-life problem yet, but I guess I'm asking it to get a feel for the differences between the problem-solving approach in LISP as opposed to object-oriente... | Just as an object is an instance of a class, a class is also an object, which is an instance of the (meta)class "class". You can ask each of your classes for the list of it's slot definitions and compare the two lists to find the commonalities.
http://www.lisp.org/mop/concepts.html
|
4,028,860 | 4,028,906 | How viable is emacs LISP aside from editing emacs? | I'm in my second year of my CS major, and I've only had courses in C (first course and then a polymorphic data structures course), C++ (OOP focus), MIPS assembly, and a compiler course. I worked in WinForms and C# over the summer. I worked through the Little Schemer and I'm really interested in learning some sort of LI... | Emacs is a text editor. Emacs Lisp is - at heart - a text editing language.
Pinnacles of elisp today - IMO - are ERC, the emacs IRC client, and org-mode, a very nice organizing system. There is also an email client for emacs.
So for building text editing plugins, I don't think you can beat elisp/emacs.
For actual sta... |
4,029,061 | 4,029,136 | Read Statement Being Skipped Over, Unbound Variable | I'm still working on my number guessing game in Common Lisp, and I've reached a standstill. When the following code is invoked:
;;;; number-game.lisp
;;;;
;;;; Andrew Levenson
;;;; 10/25/2010
;;;;
;;;; Simple number guessing game. User has
;;;; five guesses to determine a number between
;;;; one and one hundred, inclus... | Check the syntax of LET.
Example:
(let ((variable (compute-some-value)))
(do-something-with variable)
(do-some-more))
|
4,029,406 | 4,029,453 | Integer Value is Not a Number in Common Lisp? | When I execute the following Common Lisp program by calling (play), I get the error: Argument X is not a NUMBER: Guess
;;;; number-game.lisp
;;;;
;;;; Andrew Levenson
;;;; 10/25/2010
;;;;
;;;; Simple number guessing game. User has
;;;; five guesses to determine a number between
;;;; one and one hundred, inclusive (1-10... | Your read-guess function returns the symbol GUESS by using 'guess rather than the value of guess (ie without the single quote).
I think you also have other issues, for example (greater-than (guess)) evaluates guess as a function. You will need to fix these also.
|
4,029,464 | 4,029,488 | What is the simplist way to ensure that 2 lists in lisp are the same length? | Given 2 lists, I want to ensure that they are the same size, I'm having a tough time with this code. Should I be using variables to do this?
(defun samesize (list1 list2)
(cond (;logic here) T))
| Both Common Lisp and elisp have length:
(defun samesize (list1 list2)
(= (length list1) (length list2)))
|
4,030,388 | 4,030,607 | Will reading the Little Lisper help me in learning clojure? | I plan to pick up the clojure language.
I have at my disposal an old book:
The Little Lisper
I know there are more recent versions of it (The Little Schemer) but I'm wondering if it will help ease me into picking up Clojure. Or should I find other learning resource ?
| stop eating snacks for big meals. they are food to get between meals... :D
meaning, if you want clojure, go for that :
go to rubylearning and register for a clojure online course
get one of the books on clojure (the joy of clojure, clojure in action or programming clojure)
read through this quite comprehensive article... |
4,034,042 | 4,034,109 | (Random) in Common Lisp Not So Random? | Okay, final question and I'll have finished my number guessing game in Common Lisp! :D Whenever the game starts (or a new game begins after the first game), the following function is called.
;;; Play the game
(defun play ()
;; If it's their first time playing this session,
;; make sure to greet the user.
(u... | You need to seed the random state at the start of the program.
(setf *random-state* (make-random-state t))
;; # this initializes the global random state by
;; "some means" (e.g. current time.)
|
4,056,676 | 4,056,877 | Illegal Function Call in Common Lisp | I'm working on making a two player tic-tac-toe game, and am in the phase where I work out all of the errors in my code. The current error i'm stuck on is an illegal function call error in the following code:
(cond
[...snip...]
((= CHOICE 3)
(IF (NUMBERP (AREF *BOARD* 0 2))
(SETF (AREF *BOARD* 0 2) *MARKER*)
... | I figured it out! I had too many parentheses in the function due to poor copy+pasting skills.
|
4,060,245 | 4,060,381 | Checking for a win in Tic-Tac-Toe | Okay, so I'm about finished with my latest project, a (admittedly not very good) implementation of Tic Tac Toe in Common Lisp (the whole program available here), but I'm stuck on one last part; I can't figure out how to get my function that checks for a winner working. The function (and its subordinate function) look l... | There's implicit progn in defun statement, so it is evaluated in a such way:
statements are evaluated one after another;
value of last statement is returned as a function result.
In your check-for-win you have 2 statements: cond and nil. In accordance with progn evaluation rules, value of nil will be returned for an... |
4,060,353 | 4,065,643 | Common LISP on iPhone/iOS | Is it possible to call a Common Lisp function in iOS?
If so, is it possible create it in a dynamic library?
| It depends on what you mean by calling a CL function, but most likely ECL will be your shortest path. Start here, as there is a patch for ECL to better accommodate iOS: http://funcall.posterous.com/tag/iphone
ECL generates C code, so you should be in safe territory with Apple's shifting policies.
|
4,061,229 | 4,061,263 | Managing Code Assets | I have written quite a bit of code of the past few years. I've been using the Visual Studio Development Environment for my C# code, but I wouldn't call myself an advanced user of Visual Studio. I can create projects, create source code, and build/debug the project. I don't use many of the advanced features of the ID... | Take some time, work through the code and create different projects, for the likes of filters, plots. Give meaningful namespaces to these assemblies, put the code under source control, use external references to these repos in the source control of your main project, or only import the generated assemblies.
Copying cod... |
4,063,148 | 4,063,218 | Binomial Coefficient using Tail Recursion in LISP | I want to program a function to find C(n,k) using tail recursion, and I would greatly appreciate your help.
I have reached this:
(defun tail-recursive-binomial (n k)
(cond ((or (< n k) (< k 0)) NIL)
((or (= k 0) (= n k)) 1)
(T (* (tail-recursive-binomial (- n 1) (- k 1)) (/ n k)))))
Using the followi... | As starblue suggests, use a recursive auxiliary function:
(defun binom (n k)
(if (or (< n k) (< k 0))
NIL ; there are better ways to handle errors in Lisp
(binom-r n k 1)))
;; acc is an accumulator variable
(defun binom-r (n k acc)
(if (or (= k 0) (= n k))
acc
(binom-r (- n 1) (- k 1) (* acc (/ n ... |
4,064,454 | 4,069,136 | How to eliminate all levels of lists in LISP |
Possible Duplicate:
How to remove nested parentheses in LISP
This is my second quick-and-silly question about LISP, but I am kind of stuck. I need to access all the nodes in a list with several levels. I need something like:
>> (get-symbols '(A (B (C D) E )))
(A B C D E)
I don't care about the order. How would you ... | From OnLisp:
(defun flatten (tree)
(if (atom tree)
(mklist tree)
(nconc (flatten (car tree))
(if (cdr tree) (flatten (cdr tree))))))
|
4,068,340 | 4,085,713 | Is there a mocking/stubbing framework for Common Lisp? | Is there a mocking/stubbing framework for Common Lisp?
EmacsLispMock looks great, but it is an Emacs lisp framework, and I'm looking for something to use from Common Lisp.
Any suggestions?
| The following should do what you're looking for
(defmacro with-replaced-function (fdef &rest body)
(let ((oldf (gensym))
(result (gensym))
(name (car fdef))
(args (cadr fdef))
(rbody (cddr fdef)))
`(let ((,oldf (symbol-function ',name)))
(setf (symbol-function ',name) (lambd... |
4,069,703 | 4,070,758 | please help decipher this lisp extract | (let ((g (* 2 (or (gethash word good) 0)))
(b (or (gethash word bad) 0)))
(unless (< (+ g b) 5)
(max .01
(min .99 (float (/ (min 1 (/ b nbad))
(+ (min 1 (/ g ngood))
(min 1 (/ b nbad)))))))))
| What is the problem? It is almost plain english:
Let g be the value of word in the hashtable good (or 0 if not existent there) times 2
(let ((g (* 2 (or (gethash word good) 0)))
and b the value of word in the hashtable bad (or 0 if not existent there).
(b (or (gethash word bad) 0)))
With this in mind, and unde... |
4,074,929 | 4,077,914 | Emacs Lisp search-backward | Preamble
Using VTK library with C++, quite often I have to write something like this:
vtkInteractorStyleRubberBandZoom *isrbz = vtkInteractorStyleRubberBandZoom::New();
Furthermore, every time I need to use a new VTK class in my program, I have to go somewhere up the source file and add #include "vtkInteractorStyleRub... | OK, I got it. Somehow I got an idea that the third argument of search-backward (noerror) is a callback, which it isn't. Therefore it is evaluated every time, not just when the search fails. It should be something like this instead:
(defun expand-vtk ()
(interactive)
(setq now (point))
(setq vtkstart (search-backw... |
4,074,961 | 4,075,555 | Anonymous macros in Clojure | In Common LISP you can do the following
(macro lambda (x) (list (quote car) (list (quote cdr) x)))
It looks like this is not possible (an anonymous macro) in Clojure.
Is this true?
Why was this left out?
| There is some macrolet (or other things) in clojure.contrib.macro-utils. However it smells a little like a hack to me. Inclusion in clojure.core is on the TODO radar, but doesn't have high priority at the moment.
EDIT: See also here http://dev.clojure.org/display/design/letmacro.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.