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
2,835,942
2,836,848
How do I install LFE on Ubuntu Karmic?
Erlang was already installed: $dpkg -l|grep erlang ii erlang 1:13.b.3-dfsg-2ubuntu2 Concurrent, real-time, distributed function ii erlang-appmon 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP application monitor ii erlang-asn1 1:13.b.3-dfsg-2ubu...
No, there is nothing you missed. The Makefile in LFE is "less than perfect" and should be ignored, it will be improved upon in the next release. To compensate all the needed files have already compiled and the .beam files are in the ebin directory. As it is not part of OTP I don't think it should ever install there. Th...
2,852,249
2,852,287
Can you execute multiple statements in an "if" statement?
This is my function: (defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input num) //if this (setq num NEWNUM) (FUNCT2) //then execute both of these (list 'not found)))) //else output this So after the if statement I want to be able to execute (setq num ...
To do several things in sequence, you want progn. (defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input num) //if this (progn (setq num NEWNUM) (FUNCT2)) //then execute both of these (list 'not found)))) //else output this
2,853,969
2,854,034
Clojure: Equivalent to Common Lisp READ function?
When I want to read in an S-expression stored in a file into a running Common Lisp program, I do the following: (defun load-file (filename) "Loads data corresponding to a s-expression in file with name FILENAME." (with-open-file (stream filename) (read stream))) If, for example, I have a file named foo.txt tha...
You can do e.g. (require '[clojure.contrib.io :as io]) (io/with-in-reader (io/file "foo.txt") (read)) ; => (1 2 3) Note that you'll likely want to rebind *read-eval* to false first. Also note that the above works with current contrib HEAD (and will almost certainly work in 1.2 when it's released); for Clojure 1.1, th...
2,877,371
2,877,854
Definition of "lisp form"?
What exactly the definition of a "Lisp form"? As far as I know, it's "either an atom or a list that has a symbol as its first element". But then, this (in Scheme) would not be a form: ((lambda () 42)) ;; The answer to Life, the Universe and Everything. Because the first element of the list is itself another list. And...
A lisp form is a lisp datum that is also a program, that is, it can be evaluated without an error. (3 4 1) Is a lisp datum, it's a list of 3, 4 and 1. This is not a form however as trying to evaluate it does not result into another datum. But rather an error. 3 Is a datum, and a form, also called a 'normal form' or a...
2,892,565
2,893,019
How to write (simple) macro?
I need to write a macro (with-hooks (monster method who what) &body body) for a game I'm writing. Monster is a CLOS object, method and who are strings and what is a function (#' notation). The macroexpansion would be something to the effect of (add-hook monster method who what) ,@body (remove-hook monster method who) ...
I'd write it like this: (defmacro with-hooks ((monster method who what) &body body) (let ((monster-var (gensym)) (method-var (gensym)) (who-var (gensym)) (what-var (gensym))) `(let ((,monster-var ,monster) ; dummy comment (,method-var ,method) (,who-var ,who) ...
2,901,255
2,903,934
extract/slice/reorder lists in (emacs) lisp?
In python, you might do something like i = (0, 3, 2) x = [x+1 for x in range(0,5)] operator.itemgetter(*i)(x) to get (1, 4, 3). In (emacs) lisp, I wrote this function called extract which does something similar, (defun extract (elems seq) (mapcar (lambda (x) (nth x seq)) elems)) (extract '(0 3 2) (number-sequence ...
If your problem is the speed then use (vector 1 2 3 4 5) instead of a list, and (aref vec index) to get the element. (defun extract (elems seq) (let ((av (vconcat seq))) (mapcar (lambda (x) (aref av x)) elems))) If you're going to extract from the same sequence many times of course it make sense to store the seq...
2,917,608
2,917,841
member and defparameter
In the following Lisp REPL interaction: CL-USER> (defparameter *unison* 0) *UNISON* CL-USER> (member *unison* '(*unison*)) NIL why is nil returned?
Because the *unison* variable is bound to 0, and the list has only a *unison* symbol since it's quoted. Try this in comparison: (member *unison* (list *unison*)) This will actually evaluate the second *unison* which returns 0, resulting in a (0) list.
2,930,044
2,930,170
What the heck is the "Structure and Interpretation of Computer Programs" cover drawing about?
What the heck is the Structure and Interpretation of Computer Programs cover drawing about? I mean I know what "eval", "apply", and 'λ' all mean, but I'm having a hard time deciphering the rest of the picture. Who the heck is the maiden? Does she work for the wizard? Why the heck is she pointing at the table? Is sh...
The maiden stands for functional programming. She's a maiden (i.e. a virgin) because functional programmers can't do anything that has side effects. The table stands for COBOL. That's why it has a demon foot. The bowl stands for riches, which rests on COBOL, because at least you can use COBOL for writing a business ap...
2,932,441
2,932,760
scheme2lisp::define function and pass it as parameter
I need to translate some code from Scheme to Common Lisp. Now, I have something like this: (defun sum (term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) b)))) (defun sum-int (a b) (defun (ident x) x) (sum ident a 1+ b)) but it produces errors. *** - DEFUN: the name of a function must be a sy...
(defun sum (term a next b) (if (> a b) 0 (+ (funcall term a) (sum term (funcall next a) next b)))) (defun sum-int (a b) (flet ((ident (x) x)) (sum #'ident a #'1+ b))) Just another CL take with FLET (untested).
2,933,051
2,934,498
Clojure for a lisp illiterate
I am a lifelong object-oriented programmer. My job is primarily java development, but I have experience in a number of languages. Ruby gave me my first real taste of functional programming. I loved the features Ruby borrowed from the functional paradigm such as closures and continuations. Eventually, I graduated to ...
My first introduction to Lisp was: Paradigms of Artificial Intelligence Programming of Peter Norvig. It is a very readable and gentle introduction to many features of Common Lisp and functional programming concepts. Starting directly with some Clojure books could be preferable for you, because there are several differe...
2,940,267
2,940,347
Call function based on a string
I am passing in command line arguments to my Lisp program and they are formatted like this when they hit my main function: ("1 1 1" "dot" "2 2 2") I have a dot function (which takes two vectors as arguments) and would like to call it directly from the argument, but this isn't possible because something like (funcall ...
"1 1 1" is a string of five characters: 1, space, 1, space and 1. The double quotes are not part of the string. ("1 1 1" "dot" "2 2 2") is a list of three strings. There are no " characters above. The " are used to delimit strings in s-expressions. If you have a dot function you need to tell us what kind of input data ...
2,946,988
2,947,682
Is there such a thing as an "elisp bundle" for TextMate?
I started using Code Collector Pro to organise and save my Emacs codes, and this software requires TextMate bundles for syntax highlighting. They have a lisp bundle, but not an elisp bundle, at least not that I can see. I would think that the syntax highlighting would work under the lisp bundle, but for some reason it ...
I wouldn't have thought so, because anyone writing elisp is going to do it in Emacs so there wouldn't be any call for a Textmate bundle for it.
2,953,141
2,953,231
Why are most S-Expression languages dynamically typed?
How come most Lisps and Schemes are dynamically typed? Does static typing not mix with some of their common features?
Typing and s-expressions can be made to work together, see typed scheme. Partly it is a historical coincidence that s-expression languages are dynamically typed. These languages tend to rely more heavily on macros, and the ease of parsing and pattern-matching on s-expressions makes macro processing much easier. Most re...
2,965,622
2,965,760
How do you construct a symbol in clojure?
I want to construct a macro that, given a symbol 'foo, creates a method called foo*. How can I concatenate 'foo and '*?
(let [s (symbol 'test)] (symbol (str s "*")))
2,966,014
2,966,107
How do I create a macro to define two functions in clojure
The code below doesn't behave as I would expect. ; given a function name, its args and body, create 2 versions: ; i.e., (double-it foo []) should create 2 functions: foo and foo* (defmacro double-it [fname args & body] `(defn ~fname ~args ~@body) `(defn ~(symbol (str fname "*")) ~args ~@bod...
; given a function name, its args and body, create 2 versions: ; ie (double-it foo [] ) should create 2 functions: foo and foo* (defmacro double-it [fname args & body] `(do (defn ~fname ~args ~@body) (defn ~(symbol (str fname "*")) ~args ~@body))) (double-it afunc [str] (println s...
2,966,765
2,976,516
What is the difference between 1 and '1 in Lisp?
I had never really thought about whether a symbol could be a number in Lisp, so I played around with it today: > '1 1 > (+ '1 '1) 2 > (+ '1 1) 2 > (define a '1) > (+ a 1) 2 The above code is scheme, but it seems to be roughly the same in Common Lisp and Clojure as well. Is there any difference between 1 and quoted 1?...
Well, they are in fact very different. '1 is however precisely the same as (quote 1). (car ''x) evaluates to the symbol 'quote'. 1 is an S-expression, it's the external representation of a datum, a number 1. To say that 1 is a 'number-object' or an S-expression to enter that object would both be acceptable. Often it is...
2,968,526
2,968,574
Emacs Lisp spawning subprocesses with custom environmental variables
Basically I want to spawn a process changing its working directory. My idea was to spawn a process and set the PWD enviroment variable. There's a way to obtain something like that? (virtually I would like to change any of the environment variables for flexibility)
Just bind the default-directory variable before spawning your process. Example: (let ((default-directory "/tmp/")) (call-process "/bin/bash" nil "*scratch*" nil "-c" "echo working dir is $PWD")) I ran this from my *scratch* buffer and the string working dir is /tmp was added to the buffer.
2,970,426
2,970,508
Test if a class is a subclass of another class in common lisp
How do I see if one CLOS class is a subclass of another CLOS class?
You can get the CLASS-NAME of a class. A class has also a type of the same name. SUBTYPEP tests if a type is a subtype of another type.
2,979,428
2,979,455
uses for dynamic scope?
I've been getting my hands wet with emacs lisp, and one thing that trips me up sometimes is the dynamic scope. Is there much of a future for it? Most languages I know use static scoping (or have moved to static scoping, like Python), and probably because I know it better I tend to prefer it. Are there specific applicat...
There's a good discussion of this issue here. The most useful part that pertains to your question is: Dynamic bindings are great for modifying the behaviour of subsystems. Suppose you are using a function ‘foo’ that generates output using ‘print’. But sometimes you would like to capture the output in a buffe...
2,992,925
2,993,109
How can I simply "run" lisp files
Python When I learned Python I installed it on windows with a nice gui installer and all .py files would automatically run in python, from the command line or explorer. I found this very intuitive and easy, because I could instantly make plain text files and run them. Lisp I'm starting to learn lisp and have decided (f...
Executables SBCL can save executable images, as Greg Harman mentions (see the :EXECUTABLE keyword): http://www.sbcl.org/manual/index.html#Saving-a-Core-Image Scripts Lisp files can be executed as scripts, see: http://www.sbcl.org/manual/#Shebang-Scripts Command Line Options SBCL has command line options to evaluate/loa...
2,994,231
2,995,773
Is there any limit to recursion in lisp?
I enjoy using recursion whenever I can, it seems like a much more natural way to loop over something then actual loops. I was wondering if there is any limit to recursion in lisp? Like there is in python where it freaks out after like 1000 loops? Could you use it for say, a game loop? Testing it out now, simple countin...
First, you should understand what tail call is about. Tail call are call that do not consumes stack. Now you need to recognize when your are consuming stack. Let's take the factorial example: (defun factorial (n) (if (= n 1) 1 (* n (factorial (- n 1))))) Here is the non-tail recursive implementatio...
3,000,193
3,000,438
Lisp data security/validation
This is really just a conceptual question for me at this point. In Lisp, programs are data and data are programs. The REPL does exactly that - reads and then evaluates. So how does one go about getting input from the user in a secure way? Obviously it's possible - I mean viaweb - now Yahoo!Stores is pretty secure, so h...
The REPL stands for Read Eval Print Loop. (loop (print (eval (read)))) Above is only conceptual, the real REPL code is much more complicated (with error handling, debugging, ...). You can read all kinds of data in Lisp without evaluating it. Evaluation is a separate step - independent from reading data. There are all ...
3,019,142
3,019,237
running shell commands with gnu clisp
I'm trying to create a "system" command for clisp that works like this (setq result (system "pwd")) ;;now result is equal to /my/path/here I have something like this: (defun system (cmd) (ext:run-program :output :stream)) But, I am not sure how to transform a stream into a string. I've reviewed the hyperspec and go...
Something like this? Version 2: (defun copy-stream (in out) (loop for line = (read-line in nil nil) while line do (write-line line out))) (defun system (cmd) (with-open-stream (s1 (ext:run-program cmd :output :stream)) (with-output-to-string (out) (copy-stream s1 out)))) [6]> (system...
3,019,250
3,019,407
Find all paths from root to leaves of tree in Scheme
Given a tree, I want to find the paths from the root to each leaf. So, for this tree: D / B / \ A E \ C-F-G has the following paths from root (A) to leaves (D, E, G): (A B D), (A B E), (A C F G) If I represent the tree above as (A (B D E) (C (F G))) then the function g does the trick: (define (paths t...
I am more fluent in Common Lisp. (defun paths (tree) (if (atom tree) (list (list tree)) (mapcan (lambda (node) (mapcar (lambda (path) (cons (car tree) path)) (paths node))) (cdr tree)))) CL-USER> (paths '(A (B D E) (C (F G)))...
3,022,488
3,022,523
Why does using cons to create a pair of two lists produce a list and two elements?
I've started learning Scheme, for fun mostly, and because I've never used a functional language before. I chose Scheme because I wanted to read SICP for a long time. Anyway, I'm currently learning about lists, and before that I learned about cons, car and cdr. And there's an example that creates a list of lists with c...
You get a list with (1 2) as the first element (the car) and (3 4) as the rest (the cdr) because the first argument to cons is the first element of the list and the second argument is a list containing the remaining items. This closely resembles the structure of a list: each node of a (proper) list contains an element ...
3,034,237
3,034,272
Check if current Emacs buffer contains a string
I have a buffer open in emacs. I want a function that will return t if the current buffer contains the string, otherwise it returns nil. (defun buffer-contains-substring (string) ... )
This is careful to not change where you are, or damage any match data. (defun buffer-contains-substring (string) (save-excursion (save-match-data (goto-char (point-min)) (search-forward string nil t))))
3,065,606
3,068,177
When did the idea of macros (user-defined code transformation) appear?
I have read McCarthy's 1960 paper on LISP and found no reference to anything that's similar to user-defined macros or normal order evaluation. I was wondering when macros first appeared in programming language history (and also in Lisp history): When was the idea of user-defined code transformation (before interpretat...
From The Evolution of Lisp (Steele/Gabriel): 3.3 Macros Macros appear to have been introduced into Lisp by Timothy P. Hart in 1963 in a short MIT AI Memo [Hart, 1963], Timothy P. Hart, MACRO Definitions for LISP, October 1963
3,074,586
3,074,698
how to turn off the debugger in sbcl
I'm trying to learn common lisp currently and I've been using sbcl (I hope that's a decent implementation choice.) Coming from ruby and irb I find the automatic moved to a debugger on every mistake a little annoying at this time. Is there a way to turn it off temporarily when I'm playing around.
Common Lisp has a variable *debugger-hook*, which can be bound/set to a function. * (aref "123" 10) debugger invoked on a SB-INT:INVALID-ARRAY-INDEX-ERROR: Index 10 out of bounds for (SIMPLE-ARRAY CHARACTER (3)), should be nonnegative and <3. Type HELP for debugger help, or (SB-EXT:QUI...
3,086,561
3,086,734
Make clos objects printable in lisp
If you want to make CLOS objects in common lisp printable (print readably), how do you go about doing this without using anything but print and read.
There are two parts to doing this, at least in my solution, however you will need this function (thanks to the guys at cl-prevalence for this (warn LLGPL) (defun get-slots (object) ;; thanks to cl-prevalence #+openmcl (mapcar #'ccl:slot-definition-name (#-openmcl-native-threads ccl:class-instance-slots ...
3,121,145
3,121,339
How do I write a macro-defining macro in common lisp
I have about two macros (and climbing) in my codebase that look like this: (defmacro def-stat-method (method-name stat) `(progn (defmethod ,method-name ((monster monster)) (getf (stats monster) ,stat)) (defmethod (setf ,method-name) (value (monster monster)) (setf (getf (stats monster) ,stat) ...
Just write a macro that expands into another defmacro, like this: (defmacro def-foo-method (macro-name method) `(defmacro ,macro-name (method-name stat) (let ((method ',method)) `(progn (defmethod ,method-name ((monster monster)) (getf (,method monster) ,stat)) (defmethod (...
3,123,935
3,157,618
What can be the use of SymbolType in Python?
Here's the SymbolType package that adds symbols to Python. Can those who have done anything useful with Lisp/Scheme tell me what how can I take advantage of this type in Python? Can it be used to isolate strings coming from outside (from the web) from internal code? $ sudo easy_install SymbolType $ ipython Unfortunate...
Symbols are not a replacement for strings. While both are represented by a sequence of characters, a symbol shouldn't be used in place of a string when this is the dominant property. Symbols represent a unique identity. This means that pointer equality (instead of content equality) can be used to compare them. For t...
3,128,943
3,128,956
Scheme symbolic equivalence
The platform i'm working with is DrScheme. I've seen that a pair (a b) [constructed by (cons a b)] is implemented within the language like a procedure that looks like this: (define (cons a b) (lambda(pick) (cond ((= pick 1) a) ((= pick 2) b)))) and the selectors: (define (car x) (x 1)) (define (cdr x) ...
l1 is also just a list containing the same elements. Note that this also returns #f: (define l1 '(a b c)) (define l2 '(a b c)) (eq? l1 l2) While this returns #t: (define l1 '(a b c)) (define l2 (list 'a 'b 'c)) (equal? l1 l2) The reason is that eq? checks whether l1 and l2 are references to the same object in memory,...
3,129,735
3,129,742
Simple LISP function not working
I decided to learn LISP today, and have been playing around with it for a bit. I wrote a simple baby function just to test my understanding, and now understand that my understanding doesn't understand as much as I had understood it to understand. :D Anyway, here is the function. The idea is that when it is called, e.g....
esexp(base (+ x 1)) should be (esexp base (+ x 1)) esexp is a function just like +. The syntax for invoking a function is (function-name arg1 arg2 ...)
3,132,000
3,132,524
auto indentation on common lisp emacs + slime + sbcl in windows
I can't use auto indentation function on emacs + slime + sbcl when I define my function and so on. My .emacs file configuration is this: (setq inferior-lisp-program "D:/emacs/sbcl_1.0.37/sbcl.exe" lisp-indent-function 'common-lisp-indent-function slime-complete-symbol-function 'slime-fuzzy-complete-symbol ...
The slime section in my .emacs: ;;; SLIME (setq inferior-lisp-program "/usr/bin/sbcl") (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/") (require 'slime) (require 'slime-autoloads) (slime-setup '(slime-fancy)) (global-set-key "\C-cs" 'slime-selector)
3,155,091
3,155,643
What does |5E| mean in Common Lisp?
I got following error message in Common Lisp. What does || mean in CL? CL-USER> (write-to-string 5e) The variable |5E| is unbound. [Condition of type UNBOUND-VARIABLE]
|foo| is just a printed representation for symbols. 5e does not read as a number by default, so it is a symbol and may be printed as |5E|. One can use it also to have all kinds of characters in symbols, including whitespace. |this is a symbol, isn't it?| - it is! CL-USER > (describe '|this is a symbol, isn't it?|) |th...
3,164,422
3,164,588
require and *modules* are deprecated in common lisp?
Common Lisp HyperSpec says that require and ****modules**** are deprecated. But I still see we use require all the time. What should we use?
They were deprecated long ago. The standard was published in 1994. What were the consequences? None, since no new standard has been published and no new standard is being worked on. So, if your Common Lisp implementations provide a useful definition and implementation of PROVIDE, REQUIRE and *MODULES*, then use it. The...
3,165,385
3,165,541
Make macros and functions integrate more seamlessly
OK, I understand pretty well how to use both function and macros. What I'm curious about is why the compiler can't be a bit more clever when integrating the two, e.g. consider the Clojure code: (defmacro wonky-add [a b] `(+ ~a (* 2 ~b))) (defn wonky-increment [a] (apply wonky-add a 1)) => Error: can't take value of a ...
This answer is not so much about Clojure, but Lisp and macros in general. Remember: APPLY is there to be able to call functions with argument lists that are created at runtime. Macros are there to generate new source code from some source code - and the generated source code will run. Now: If you allow apply to feed di...
3,168,282
3,168,512
CLISP overflow after multiplication
i'm trying to get a first lisp program to work using the CLISP implementation, by typing (print (mod (+ (* 28433 (expt 2 7830457) 1)) (expt 10 10)))) in the REPL. but it gives me *** - overflow during multiplication of large numbers. i thought lisp features arbitrary size/precision. how could that ever happen then?
According to http://clisp.cons.org/impnotes/num-concepts.html the maximum size for a bignum is (2^2097088 - 1) and your 2^7830457 is much larger than that. Perhaps you can look at breaking down that number - perhaps separate out a number of smaller 2^X factors...
3,172,670
3,172,677
Scheme: CAR and CDR of a list
I am confused as to how car and cdr work on lists. Here is an example of what I have tried: (define sample (read)) (display sample) (display (car sample)) (display (cdr sample)) (display (car (cadr sample))) (display (cdr (cdr sample))) On entering the value '(A B C D E F), here is what I get: '(a b c d e f) quote ((...
If you wanted to simply type the list (a b c d e f), you should just type (a b c d e f). What you typed, instead, was (quote (a b c d e f)) because the ' operator is short for (quote ...). Your list literally has the first element quote and the second element (a b c d e f). Of course, when you're writing source code,...
3,172,938
3,174,085
How to install/upgrade Lisp libraries on Debian
I recently discovered that some of my favorite libraries have been removed from Debian, e.g., Hunchentoot: For a while now most Common Lisp projects do not do releases anymore, our plan is to move to proving a cl-build like environment inside debian I've looked at the mailing lists and Debian Common Lisp homepage a...
On anything but Gentoo (which has a very well maintained Lisp overlay), I would use clbuild for now. I have the hope that XCVB will be usable soon.
3,180,390
3,180,782
What does the double minus (--) convention in function names mean in Emacs Lisp
I've been reading through a number of Emacs Lisp packages and have come across the convention of some functions being declared with -- after the library prefix, e.g.: (defun eproject--combine-regexps (regexp-list) I'm wondering if this a convention for declaring "private" functions to the library but so far I haven't ...
Emacs doesn't have any support for namespaces, packages, libraries or modules. Emacs sources therefore use foo- as a prefix for a foo library, and in some cases foo-- is used for bindings that are supposed to be internal.
3,182,148
3,182,220
reduce, or explicit recursion?
I recently started reading through Paul Graham's On Lisp with a friend, and we realized that we have very different opinions of reduce: I think it expresses a certain kind of recursive form very clearly and concisely; he prefers to write out the recursion very explicitly. I suspect we're each right in some context and ...
If you have a choice, you should always express your computational intent in the most abstract terms possible. This makes it easier for a reader to figure out your intentions, and it makes it easier for the compiler to optimize your code. In your example, when the compiler trivially knows you are doing a fold operati...
3,189,957
3,190,195
A way to strip returned values from java.io.File.listFiles in Clojure
I call a java function in Clojure to get a list of files. (require '[clojure.java.io :as io]) (str (.listFiles (io/file "/home/loluser/loldir"))) And I get a whole bunch of strings like these #<File /home/loluser/loldir/lolfile1> etc. How do I get rid of the brackets and put them in some form of an array so another f...
Those strings are just the print format for a Java File object. See the File javadoc for which operations are available. If you want the file paths as strings, it would be something like (map #(.getPath %) (.listFiles (io/file "/home/loluser/loldir"))) Or you could just use list, which returns strings in the first ...
3,214,603
3,215,312
How does a macro-enabled language keep track of the source code for debugging?
This is a more theoretical question about macros (I think). I know macros take source code and produce object code without evaluating it, enabling programmers to create more versatile syntactic structures. If I had to classify these two macro systems, I'd say there was the "C style" macro and the "Lisp style" macro. ...
I don't think there's a fundamental difference in "C style" and "Lisp style" macros in how they're compiled. Both transform the source before the compiler-proper sees it. The big difference is that C's macros use the C preprocessor (a weaker secondary language that's mostly for simple string substitution), while Lisp...
3,221,684
3,221,963
how to do file selection using mouse with emacs cedet?
I am using emacs 23.2 on Ubuntu 10.04 & Windows XP along with cedet extention. Cedet seems to work fine but I could not select the file using mouse. Rather I need to use the Key press to select the file from cedet (placed at left side).. how to do file selection using mouse with emacs cedet? Any clue shall be appreciat...
CEDET is a collection of features, so I'm not sure specifically which one you're talking about, but are you left-clicking or middle-clicking the mouse? The middle mouse button is more commonly bound to an 'open file' command in Emacs modes. In any case, you can always use C-h m to list the help for the active major mod...
3,222,440
3,222,596
Stuck in a Clojure loop, need some guidance
I am stuck in a Clojure loop and need help to get out. I first want to define a vector (def lawl [1 2 3 4 5]) I do (get lawl 0) And get "1" in return. Now, I want a loop that get each number in the vector, so I do: (loop [i 0] (if (< i (count lawl)) (get lawl i) (recur (inc i)))) In my mind this is ...
You need to consider what is "to get each lawl value" supposed to mean. Your get call does indeed "get" the appropriate value, but since you never do anything with it, it is simply discarded; Bozhidar's suggestion to add a println is a good one and will allow you to see that the loop does indeed access all the elements...
3,222,761
3,222,776
10 LISP primitives analogous to 5 axioms of Euclidean geometry?
LISP can be built from ten primitives: The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply. Apparently these are equivalent to the 5 axioms of Euclidean geometry. http://hyperpolyglot.wikidot.com/lisp Can anyone explain how they are equivalent?
It only says: The primitives are analogous to the 5 axioms of Euclidean plane geometry. Which doesn't express equivalence. As far as I can tell the author just draws an analogy and wants to say that LISP is constructed from its ten atoms, just like Euclid's plane geometry is constructed from its five axioms. Poor ana...
3,222,789
3,222,915
common lisp cons creates a list from two symbols, clojure cons requires a seq to cons onto?
(Disclaimer - I'm aware of the significance of Seqs in Clojure) In common lisp the cons function can be used to combine two symbols into a list: (def s 'x) (def l 'y) (cons s l) In clojure - you can only cons onto a sequence - cons hasn't been extended to work with two symbols. So you have to write: (def s 'x) (def l ...
In Clojure, unlike traditional Lisps, lists are not the primary data structures. The data structures can implement the ISeq interface - which is another view of the data structure it's given - allowing the same functions to access elements in each. (Lists already implement this. seq? checks whether something implements...
3,231,244
3,233,404
In Clojure: Error executing a Java call with let inside a function but not in REPL
I have the following code: (defn post [title content timestamp] (let [[innholdet tajm] [(str "<html> <head> <title>" title " :: " blog_title "</title></head> <body><h1>" title "</h1> <br/>" content "<br/><i>posted " (Date. timestamp) "</i> ...
Just a small change is necessary: (defn post [title content timestamp] (let [[innholdet tajm] [(str "<html> <head> <title>" title " :: " blog_title "</title></head> <body><h1>" title "</h1> <br/>" content "<br/><i>posted " (Date. **(Long/parseLong tim...
3,237,405
3,237,784
idiomatic way to replace (null x) function from common lisp in clojure
In Common Lisp you use the (null x) function to check for empty lists and nil values. Most logically this maps to (or (nil? x) (= '() x)) In clojure. Can someone suggest a more idiomatic way to do it in Clojure?
To get the same result for an empty list in Clojure as you do in Common Lisp, use the empty? function. This function is in the core library: no imports are necessary. It is also a predicate, and suffixed with a ?, making it a little clearer what exactly you're doing in the code. => (empty? '()) true => (empty? '(1 2))...
3,242,034
3,242,097
Android without Java
After doing the whole "enterprise" programming for a while, I'm seriously disillusioned by the language itself and always feel quite hampered if I have to go back to it. The project size of your average Android app isn't too intimidating and the libraries are actually quite nice regarding their coding style, but if I c...
Personally, I'd say Scala is your best bet right now. It works really well, with the one drawback being that you are required to include Scala as a dependency (which will increase the size of your application). Scala Programming for Android Can I program for Android using any JVM language? Getting Started Programming...
3,243,035
3,243,085
(define (average ....)) in Lisp
I'm just playing around with scheme/lisp and was thinking about how I would right my own definition of average. I'm not sure how to do some things that I think are required though. define a procedure that takes an arbitrary number of arguments count those arguments pass the argument list to (+) to sum them together ...
The definition would be a very simple one-liner, but without spoiling it, you should look into: a "rest" argument -- this (define (foo . xs) ...xs...) defines foo as a function that takes any number of arguments and they're available as a list which will be the value of xs. length returns the length of a list. apply t...
3,247,045
3,247,417
How Are Lazy Sequences Implemented in Clojure?
I like Clojure. One thing that bothers me about the language is that I don't know how lazy sequences are implemented, or how they work. I know that lazy sequences only evaluate the items in the sequence that are asked for. How does it do this? What makes lazy sequences so efficient that they don't consume much stack? ...
Let's do this. • I know that lazy sequences only evaluate the items in the sequence that are asked for, how does it do this? Lazy sequences (henceforth LS, because I am a LP, or Lazy Person) are composed of parts. The head, or the part(s, as really 32 elements are evaluated at a time, as of Clojure 1.1, and I think 1.2...
3,247,302
3,247,465
Why do I get NPE in the following code?
The following code executes as expected but gives a NullPointerException at the end. What am I doing wrong here? (ns my-first-macro) (defmacro exec-all [& commands] (map (fn [c] `(println "Code: " '~c "\t=>\tResult: " ~c)) commands)) (exec-all (cons 2 [4 5 6]) ({:k 3 :m 8} :k) (conj [4 5 \d] \e \f)) ; Output...
Take a look at the expansion that is happening: (macroexpand '(exec-all (cons 2 [4 5 6]))) => ((clojure.core/println "Code: " (quote (cons 2 [4 5 6])) "\t=>\tResult: " (cons 2 [4 5 6]))) As you can see, there is an extra pair of parentheses around your expansion, which means that Clojure tries to execute the result of...
3,272,567
3,272,659
SQLITE user-defined functions in Lisp
In SQLITE there is a possibility to relatively easily create User-Defined Functions and Aggregates in (extension) languages such as C, Perl, Python and others. Is there also such possibility using common-lisp as SQLITE language extension? I know there are libraries like cl-sqlite and plain-odbc but they don't seem to ...
When I wrote cl-sqlite, I hadn't thought about user-defined functions. But it's actually pretty easy. It just takes to define callbacks, foreign functions and wrap them in lispy interface. I guess I'll add this feature to cl-sqlite soon.
3,277,352
3,290,751
Is there a Scheme implementation that parallelizes?
Is there a R5RS-or-higher Scheme implementation that does parallelization? For example, if I say to do: (map (lambda (x) (pure-functional-stuff x)) '(1 3 5 7 11 13)) it will process 1, 3, 5, and 7 simultaneously if the machine can do it? That's supposed to be one of the big advantages of functional pro...
I'm a developer of Schemik and I think that it is the Scheme you are looking for. The project is still developed and maintained. Early this year, I released a version which improves compatibility with R5RS. Unfortunately, Schemik is a research project focused on the process of expression evaluation, thus, its standard ...
3,281,780
3,284,615
Clojure: No implementation of method in protocol
I am trying to load the Clojure library for RDF clj-plaza in Clojure REPL like so: user=> (use 'plaza.rdf.core) nil I have a folder named plaza, and a subfolder named rdf and the file core.clj available and as far as I can tell, Clojure REPL loads the library as it should. Now, if I do user=> (alter-root-rdf-ns “http:...
The (defn document-to-model ...) snippet does not implement load-stream; it implements a function called document-to-model which calls load-stream with a bunch of arguments, the first of which -- *rdf-model* -- needs to be of a type to which the RDFModel protocol has been extended (or which implements the protocol or t...
3,299,263
3,299,361
Which dialect of LISP is 'The Little Lisper' [3rd Edn] written in? (at the time)
The Little Lisper is an extraordinary book. http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632/ref=sr_1_1?ie=UTF8&s=books&qid=1279715423&sr=8-1 Does anyone know which dialect/version of LISP it was written for at the time of publication? Perhaps Common LISP Standardised Scheme Some LISP-1 diale...
I do not know about the third edition, but the early ones were Scheme around R4RS. There is also the slightly newer translation "The Little Schemer'. I'm pretty sure that most of the code should run fine in any modern scheme. I'd suggest Racket (AKA PLT Scheme) as it is at constructed by a team led by Matthias Fellei...
3,316,407
3,316,823
Benefits and uses of a functional programming language
Possible Duplicate: Why functional languages? I began programming with C/C++, VB, and eventually Python - all imperative languages. I took a course about programming languages and learned my first functional language - OCaml. It was terrible. Syntax and other horrors aside, OCaml took my imperative thought process a...
First of all, almost any language in common use today is equivalent in expressive power, be it imperative or functional, so it's natural to think that anything you can do in a functional language you can probably do in an imperative one, because it's probably true. One of the really nice things about functional languag...
3,319,427
3,319,492
How to display rationals as long lists of digits in Lisp?
I'm just starting to learn Lisp and was wondering how to display a rational as a decimal number with lots of digits. If I use (float x), where x is a rational then it displays about 8 digits or so. But I want to display hundreds of digits.
You will have to implement an algorithm to basically do the long division and calculate the digits yourself. There is no native datatype capable of holding hundreds of decimal digits.
3,321,367
3,321,698
Why does this work in DrRacket but not in Racket from the console
(define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car lat)) (else (pick (sub1 num) (cdr lat)))))) (define brees (quote (a b c d e touchdown g h i))) (pick 6 brees) The language in DrRacket is set to Advanced Student. It also works fine...
When I type this into the console I get Welcome to Racket v5.0. > (define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car lat)) (else (pick (sub1 num) (cdr lat)))))) > (define brees (quote (a b c d e touchdown g h i))) > (pick 6 brees) 'touchdown How a...
3,328,512
3,330,981
Why multiple namespaces?
What is the rationale behind the design decision to have separate namespaces for values and functions in Common Lisp? What are the arguments for and against it?
Common Lisp is basically a descendant from the original Lisp 1.5, or rather, a unification of its diverging dialects. The original Lisp 1.5 was what is nowadays called a Lisp-2. Because it was back in the sixties and the fact that you could pass functions to other functions was weird enough. No one would even think of ...
3,340,805
3,340,829
Running Clojure and other Lisp at the same time on Emacs
I use Aquamacs, and Aquamacs is pre-equipped with SLIME. (setq inferior-lisp-program "/usr/local/bin/sbcl") #####!!! (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME/contrib") (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME") (require 'slime) (slime-setup) As is ask...
Sure, you can use C-u M-x slime instead of just M-x slime to have SLIME ask you for the name of the Lisp executable to be launched, with whatever is your default already filled in. There's also a slime-lisp-implementations variable which I have configured like so: (setq slime-lisp-implementations `((clojure ,(swa...
3,340,837
3,341,527
Common Lisp: What is the downside to using this filter function on very large lists?
I want to filter out all elements of list 'a from list 'b and return the filtered 'b. This is my function: (defun filter (a b) "Filters out all items in a from b" (if (= 0 (length a)) b (filter (remove (first a) a) (remove (first a) b)))) I'm new to lisp and don't know how 'remove does its thing, what kind...
There are two ways to find out: you could test it with data you could analyze your source code Let's look at the source code. lists are built of linked cons cells length needs to walk once through a list for EVERY recursive call of FILTER you compute the length of a. BAD! (Use ENDP instead.) REMOVE needs to walk onc...
3,343,404
3,343,961
What are the good things about slime?
As I asked here, I couldn't make it run Aquamacs/slime/clojure, but I could use Auqamacs/clojure with 'M-x conjure-mode', then C-c C-z (run clojure) and C-c C-e (run expression). I don't have an experience with SLIME, but I feel that C-c C-z and C-c C-e is just enough for lisp/conjure REPL or debugging. What features ...
So, so, so much more. M-. to go to a definition. C-c C-k to compile the current buffer. M-p & M-n to go forwards and backward in REPL history. M-<tab> for completion. A debugger. A wonderful REPL. And so much more. Slime gives so much: look at its manual. It shouldn't be too hard to set up: this post is a great sta...
3,344,126
3,344,225
Modify Lisp function without rewriting it?
I wrote a Lisp function earlier that had an error. The first challenge was to figure out how to view the function again. That challenge is solved. Now that I see WHAT I have done wrong, I want to modify the contents of the defined function without rewriting the whole thing? Seems like as intelligent as Lisp is, there ...
Judging from the question, I think that you have a strange setup. It seems to indicate that you are writing your functions directly at the REPL. Don't do that. The usual setup is to have an IDE (for example, Emacs with Slime) where you edit a source file, and then "send" top-level forms (like function definitions) to...
3,344,696
3,344,846
Emacs: Enter commands like in gedit
in gedit it's possible to define so-called "snippets" for simpler input. For example, there is a snippet while. This means: If you type while -> (-> stands for tab key). And gedit automatically converts it to the following (including correct indentation): while (condition){ } In vim (in conjunction with latex-suite) ...
See yasnippet. It provides snippets for most major languages, and it is easy to add new ones or modify the old ones.
3,345,397
3,358,638
How is Racket different from Scheme?
Racket is a descendant of Scheme. How is Racket different than R6RS? What did it add, or take away, or is just different? I understand that Racket is more than a language, it's a platform for languages. But I'm referring to the main Racket dialect.
Racket is ultimately based on R5RS, and not R6RS and not a strict superset of either. I don't think it can be called 'Scheme' because it's not backwards compatible with any Scheme standard. Most implementations offer extensions, but are otherwise backwards compatible, of course, the compiler that comes with Racket can ...
3,357,308
3,368,037
Trouble with this macro
Embarrassingly enough, I'm having some trouble designing this macro correctly. This is the macro as I have it written: (defmacro construct-vertices [xs ys] (cons 'draw-line-strip (map #(list vertex %1 %2) xs ys))) It needs to take in two collections or seqs, xs and ys, and I need it to give me… (draw-line...
I looked at the macro expansion for draw-line-strip and noticed that it just wraps the body in a binding, gl-begin, and gl-end. So you can put whatever code inside it you want. So (defn construct-vertices [xs ys] (draw-line-strip (dorun (map #(vertex %1 %2) xs ys)))) should work.
3,358,987
3,368,021
Problem with emacs lisp shell process arguments
I'm attempting to run P4V commands directly from xemacs. After pulling in the p4.el to emacs I've written the following: (defun p4v-command (cmd) (get-buffer-create p4-output-buffer-name);; We do these two lines (kill-buffer p4-output-buffer-name) ;; to ensure no duplicates (call-process "p4v" nil (get-buffe...
call-process definitely doesn't concatenate its arguments; it passes them through to the program directly. To see this is the case, type M-: and evaluate the following expression: (call-process "/bin/ls" nil "*scratch*" nil "avg ba") where "avg" and "ba" are files in the current directory. I get the following messag...
3,367,083
3,367,840
What is the most performant lisp on the JVM
What is the most performant (fastest) lisp implementation on the JVM? By lisp implementation I consider all implementations of any language in lisp family, like Common Lisp, Scheme, Clojure, ... I know that Clojure can be made pretty fast using type hints, that ABCL is in general not considered to be fast. I don't have...
With Clojure you can get to the speed of Java (with type hints of course) and you can not get faster than java (exept in some very rare cases). I don't know about the other lisps the are maybe the same speed but not faster. So that said about the standard speed of calls and so on. Clojure has data structures are not al...
3,382,813
3,382,883
What is the best language in which to write an expert system?
Is LISP or something like Jess the best choice? I'm interested in writing a program that makes a suggestion based on users' answers. Computational considerations are not really a factor this is pretty much a pattern matching engine. Also I would like to make an app for this and put it up on the web. UPDATE: I would ...
Step 1. Pick an inference engine. There are many choices. Here's a list: http://en.wikipedia.org/wiki/Expert_system#Shells_or_Inference_Engine Step 2. Use the language that interfaces with the inference engine. You'll be much happier leveraging an inference engine for expert systems work. I would like to put thi...
3,398,602
3,400,850
Easy way to merge plists?
Is there an easy way in Common Lisp to merge two plists? Or from another point of view: is there a way to remove duplicates from a plist? I know I can just append plists (and GETF will take the first one it finds), but I'd like to not keep accumulating unused keys as my app runs. I'm thinking about something like (lo...
You could start from this primitive version: (defun merge-plist (p1 p2) (loop with notfound = '#:notfound for (indicator value) on p1 by #'cddr when (eq (getf p2 indicator notfound) notfound) do (progn (push value p2) (push indicator p2))) p2) CL-USER 104 > (merge...
3,401,538
3,401,619
HTDP Exercise 6.6.1 - What does it mean by template functions?
I'm looking at Scheme at the moment for a bit of fun, using the "how do design programs" book. All pretty easy so far but ran into this odd wording in exercise 6.6.1 where I'm not clear what is intended: Develop the template fun-for-circle, which outlines a function that consumes circles. Its result is undetermined. ...
In HtDP, a template is a kind of a sketch of a function, which basically lists everything that you know about the inputs, including fields and often the result of a recursive call on part of the data (these come later in the book). You can see the term defined at the top of Section 6.5, with an example of a template. ...
3,401,604
3,403,544
Concise Lisp code to apply a list of functions all to the same argument(s) and get a list of the return values?
Suppose I have a single element, and I have a list of predicates (functions). I want to apply each of these predicates to the single element and get a corresponding list of return values. I know that map and friends can apply a single function to each a list of arguments, but is there any concise syntax to apply many f...
This operation is not that common and there is not really a predefined way to do it, other than writing it directly, in Common Lisp. Various people like a short syntax and added syntactic elements that would help in such a case to all kinds of Lisps. In Common Lisp one might want to write a function that does what you...
3,407,066
3,416,109
Error starting sbcl under slime on Vista
I'm having trouble getting SBCL to start under slime. I've messed things up and I don't know how to recover. This was working fine until I... Had a problem loading a package via asdf. At which point I started debugging the asdf.lisp provided with SBCL to see what was going wrong. The sole change I made was to put a...
I've sorted the problem using the following steps: Fire up sbcl from Windows start menu. Run the following code to add the sbcl-hooks-require symbol to the feature list: (push :sbcl-hooks-require features) Recompile asdf.lisp. In order to do this I needed to recompile asdf outside of the installed C:\Program files\St...
3,434,964
3,445,196
How to run Clozure CL (Lisp) from a shell script on OS X?
I tried the following: $ cat args.sh \#! /Applications/ccl/dx86cl64 (format t "~&~S~&" *args*) $ ./args.sh Couldn't load lisp heap image from ./args.sh I can run lisp fine directly: $ /Applications/ccl/dx86cl64 Welcome to Clozure Common Lisp Version 1.5-r13651 (DarwinX8664)! ? Is it possible to write a shell scr...
Just following up on Charlie Martin's answer and on your subsequent question. The dx86cl64 --eval <code> will fire up a REPL, so if you want to fire up a given script then quit, just add this to the end of your script: (ccl::quit). In the example you provided, this would do the trick: #! /bin/bash exec /Applications/c...
3,436,194
3,508,176
How to find the mean/average of a sound in Nyquist
I'm trying to write a simple measurement plug-in for Audacity and it's about as much fun as pounding rocks against my skull. All I want to do is take a chunk of audio and find the average of all the samples (the chunk's DC offset) so that I can present it as a number to the user, and so that I can subtract the DC offs...
NEVERMIND snd-maxsamp is computing the absolute value, not snd-avg. snd-avg works just fine. Here's how to squeeze a number ("FLONUM") out of it: (snd-fetch (snd-avg s (round len) (round len) OP-AVERAGE)) This produces a negative number for negative samples and a positive number for positive samples, as it should. ...
3,436,216
11,747,759
How to map clojure code to and from JSON?
I have a crazy idea, which involves putting some clojure code into CouchDB and writing views that query it. I don't want to store the clojure code as plain text, because then I would have to worry about parsing it in the views. Formatting and comments don't need to be preserved, but the code should be able to go in and...
I think your idea is sound, but I'd simplify the handling of collections by using tagged arrays (["list", …], ["vector", …]) instead. Apart from that, I wouldn't change the implementation strategy. I like your idea and to code in Clojure, so I took a stab at implementing your code-to-json (with the above suggestion inc...
3,437,103
3,437,390
Is it possible to implement coroutines using only LISP primitives?
First, I'm a LISP newbie. What I want to get is a cooperative micro-threading feature. And this can be gained with coroutine. As I know, Scheme supports coroutines via continuations. However, not all Scheme implementation may have continuations. If so, can I add a continuation feature with only LISP primitives?
You can. Chapters 5 and 6 of Essentials of Programming Languages shows how to implement continuations in Scheme. In his book On Lisp, Paul Graham explains how to implement continuations in Common Lisp (Chapters 20-22).
3,457,711
3,460,904
Idiomatic way to pass a method name for evaluation in Clojure?
I'm passing the name of a function for use in another method. (defn mapper [m function] (cond (= '() m) '() true (cons (function (first m)) (mapper (rest m) function)))) (println (mapper '((blue red)(green red)(white red)) #'first)) Is there a more idiomatic way to do this in clojure?
Prefer vectors to lists. You don't have to quote a vector most of the time, and it has better performance for a lot of things, like random access. Lists are used much more rarely in Clojure than in other Lisps. Prefer keywords to quoted symbols. Keywords stand out as "constant strings" or enumerated values. Keywor...
3,467,227
3,467,971
Scheme and Clojure don't have the atom type predicate - is this by design?
Common LISP and Emacs LISP have the atom type predicate. Scheme and Clojure don't have it. http://hyperpolyglot.wikidot.com/lisp Is there a design reason for this - or is it just not an essential function to include in the API?
In Clojure, the atom predicate isn't so important because Clojure emphasizes various other types of (immutable) data structures rather than focusing on cons cells / lists. It could also cause confusion. How would you expect this function to behave when given a hashmap, a set or a vector for example? Or a Java object t...
3,467,317
3,468,060
Can you implement any pure LISP function using the ten primitives? (ie no type predicates)
This site makes the following claim: http://hyperpolyglot.wikidot.com/lisp#ten-primitives McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or ...
Some numbers can be represented with just those primitives, it's just rather inconvenient and difficult the conceptualize the first time you see it. Similar to how the natural numbers are represented with sets increasing in size, they can be simulated in Lisp as nested cons cells. Zero would be the empty list, or (). ...
3,467,696
3,467,811
Implementing Micro Manual LISP
I am implementing an interpreter for the LISP defined in, http://www.scribd.com/vacuum?url=http://www.ee.ryerson.ca/~elf/pub/misc/micromanualLISP.pdf My problem is the paper states that a LIST is, 4. (LIST e1 ... en) is defined for each n to be (CONS e1 (CONS ... (CONS en NIL))). So when a read in a list from the ...
(QUOTE (B C D (E F))) is (CONS B (CONS C (CONS D (CONS (CONS E (CONS F NIL)) NIL)))) (QUOTE (B C D E F)) is (CONS B (CONS C (CONS D (CONS E (CONS F NIL)) NIL))) Or to put it another way: (LIST D (LIST E F)) = (CONS D (CONS (LIST E F) NIL)) (LIST D E F) = (CONS D (LIST E F))
3,474,115
3,474,133
with-open-file explanation in layman terms
I'm learning CL, and I have minimal experience in other languages. Could someone explain to me in layman terms what this means, especially what "out" here represents, and how it all fits together: (defun save-db (filename) (with-open-file (out filename :direction :output :if-exis...
out is the stream variable bound to the open file. with-open-file guarantees that the file is open inside the scope, and closed outside the scope, no matter how you exit.
3,476,266
3,476,425
Popping an element from an association list in lisp (elisp)
I'm searching for a way to "pop" an element from an association list, in other words a "destructive" assoc: (setq alist '((a . 1) (b . 2)) (assoc-pop 'a alist) ;; -> (a . 1) ;; alist -> ((b . 2)) Are there any function in the elisp harness? What's the most elegant way to obtain a symilar functionality? (not sure about...
There is no such built-in operator that I am aware of, but I think that you can get this functionality quite quickly: (defmacro assoc-pop (key alist) `(let ((result (assoc ,key ,alist))) (setq ,alist (delete result ,alist)) result))
3,482,359
3,482,762
Unexpected output with cons()
I am from an imperative background but these days trying my hands on LISP (Common LISP) I read here about cons that (cons x L): Given a LISP object x and a list L, evaluating (cons x L) creates a list containing x followed by the elements in L. When I intentionally did not use a list as the second argument i.e wh...
Cons constructs a "cons cell". This has nothing to do with lists at first. A cons cell is a pair of two values. A cons cell is represented in written form by a "dotted pair", e.g. (A . B), which holds the two values 'A and 'B. The two places in a cons cell are called "car" and "cdr". You can visualize such a cons c...
3,483,077
3,485,181
Applying the Y-Combinator to a recursive function with two arguments in Clojure?
Doing the Y-Combinator for a single argument function such as factorial or fibonacci in Clojure is well documented: http://rosettacode.org/wiki/Y_combinator#Clojure My question is - how do you do it for a two argument function such as this getter for example? (Assumption here is that I want to solve this problem recur...
The number of args doesn't change anything since the args are apply'd. You just need to change the structure of get_: (defn get_ [f] (fn [n lat] (cond (empty? lat) () (= 1 n) (first lat) :else (f (dec n) (next lat))))) (defn Y [f] ((fn [x] (x x)) (fn [x] (f (fn [& args] (ap...
3,484,094
3,484,307
What are the advantages of scheme macros?
Why would anyone prefer Scheme macros over Common Lisp macros (and I genuinely want to know too, I'm not trying to be a troll)? My experience as a Lisp newb is that Common Lisp style macros are much easier to learn than Scheme's macros. I have yet to see any advantages to Scheme's macros, but of course that doesn't me...
Scheme macros introduce two, essentially orthogonal, concepts: hygiene and pattern matching. Hygiene is less important in a lisp2 like Common Lisp. The pattern matching language captures many of the common macro idioms, but has the problem that it is essentially a different language from scheme. Probably the best in...
3,487,417
3,489,650
What is it about a single namespace that leads to unhygienic macros? (in LISP)
Some claim that a single namespace in LISP leads to unhygienic macros. http://community.schemewiki.org/?hygiene-versus-gensym http://www.nhplace.com/kent/Papers/Technical-Issues.html What precisely is it about having single, dual or multiple namespaces that leads to macro hygiene?
Lisp-2 means you have two namespaces: one for functions, one for the other stuff. This means you're less likely to rebind a function value (or var value) in a macro, unwittingly. In Lisp-1, since there's one namespace, you're (statistically, but not practically) twice as likely to hit an existing definition. In real...
3,492,902
3,495,997
What POOP frameworks exist for Lisp and Scheme
What nice POOP (Prototype-based Object-oriented Programming) Frameworks exist in Lisp and Scheme? I know one: Sheeple But are there any others?
There should be quite a few. ObjectLisp is one. It was used on the LMI Lisp Machines and for the early Macintosh Common Lisp starting in the mid 80s. Basically every 'Frame system' without classes can support Prototype-based Object-oriented Programming. There should something like twenty systems that should do it.
3,493,047
3,493,361
What is the correct term for the following functional programming pattern?
I've heard it referred to as a stream, as an infinite list, and sometimes even as a lazy sequence. What is the correct term for the following pattern? (Clojure code shown) (def first$ first) (defn second$ [str] (cond (empty? str) () true ((first (rest str))))) (defn stream-builder [next_ n] (cons n (cons ...
Short answer: stream-builder returns a function that returns an infinite sequence/list, which must be evaluated 'lazily' (since you can't evaluate something infinitely long in finite time). In the Clojure world, you should probably call none of the things in your example "streams" to avoid confusion with another concep...
3,497,168
3,497,770
Lisp compiler design
I am looking for a compiler design book. I am learning it at college; but lectures were never meant for me. Moreover, at my college they don't do much practical and I believe even if I sincerely do the course about finite automata and compiler design, I will not know how to implement a compiler. So, I am looking for bo...
Lisp in small pieces is probably the best book on implementing Lisp. Highly recommended. Probably available through some used book service. It might be expensive, even as a used book. It is a translation from the French original. There is also a revised version in French, which hasn't been translated to English - unfor...
3,513,128
3,513,158
Transposing lists in Common Lisp
I am trying to transpose a list of lists; my comments indicate the thought process. (setq thingie '((1 2 3) (4 5 6) (7 8 9))) ;;test case (defun trans (mat) (if (car mat) (let ((top (mapcar 'car mat)) ;;slice the first row off as a list (bottom (mapcar 'cdr mat))) ;;take the rest of the rows ...
There is a simple way for this: (defun rotate (list-of-lists) (apply #'mapcar #'list list-of-lists)) Your attempt is always returning the original mat. Fix your indentation, and you see that the returned value from the if form is always thrown away. Edit: How this works: List takes any number of arguments and mak...
3,515,152
3,515,413
emacs lisp listing files with glob expansion
Are there any library or function that performs a bash-like glob expansion for emacs lisp? For example: (directory-files-glob "~/Desktop/*") > ("/home/user/Desktop/file1" "/home/user/Desktop/file2") If there isn't such a function are there any hint/suggestion on how to implement it? EDIT: I've found in the docs also a...
Check out the documentation for directory-files: (directory-files "~/Desktop" nil ".") Note: The third argument is a regular expression - not globbing. It is straight forward to turn globbing patterns into regular expressions. eshell comes with a translation package which you can use: (require 'em-glob) (defun direct...
3,516,053
3,516,303
Lisp style question: memoization (caution: contains the solution for project euler #14)
I am just trying to learn some Lisp, so I am going through project euler problems. I found problem no. 14 interesting (so if you are planning to solve this problems stop reading now, because I pasted my solution at the bottom). With my algorithm it was so slow, but after using memoization (I copied the function from P...
It is bad style to setq an unknown name. It is assumed that you mean to create a new global special variable, then set it, but this should be made explicit by introducing these bindings first. You do this at the top level by using defvar (or defparameter or defconstant) instead, and in lexical blocks by using let, do...
3,518,874
3,520,833
Difference between let* and set? in Common Lisp
I am working on a genetic programming hobby project. I have a function/macro setup that, when evaluated in a setq/setf form, will generate a list that will look something like this. (setq trees (make-trees 2)) ==> (+ x (abs x)) Then it will get bound out to a lambda function #<FUNCTION :LAMBDA (X) ... > via strategic...
(Setq make-trees 2) sets the value of the variable make-trees to 2, then returns 2. I do not see a reason for a macro in what you describe. Is it true that your make-trees creates a single random tree, which can be interpreted as a program? Just define this as a function with defun. I am thinking of something like t...
3,526,497
3,526,645
Scheme or Common Lisp?
I am an intermediate programmer, and have decided to learn either common lisp or scheme. My question is simple, which one would you choose? I don't care much for the difficulty of the syntax, just the power, flexibility, and other aspects of the language itself. Also, which implementation of either common lisp or schem...
Like so many things, it depends on what you want to do. Remember, if you choose one now, it doesn't preclude you from changing later. In fact, I found it quite easy to switch from knowing a little Scheme to learning a lot of Clojure. If you just want to learn, and play around with a Lisp, or even build moderately comp...
3,528,697
3,528,737
What could be the fastest and least painful way to learn LISP for a C developer?
I have been working as a C developer on Linux platform for sometime now. Recently finished K & R and did a little study of implementing OOP in C. Beside that I have studied C++ and Java. All of it has been on Linux platform. Now I plan to learn LISP. I have gone through LISP discussions directed towards beginners on SO...
Possible duplicate You could do a lot worse than MIT Course 6.001 "Structure and Interpretation of Computer Programs". The class uses Abelson & Sussman's text; see also the book's main site for more information. The class uses Scheme, a dialect of LISP which is significantly cleaner and easier to use than Common LISP ...
3,535,954
3,536,349
Defining the defmacro function using only LISP primitives?
McCarthy's Elementary S-functions and predicates were atom, eq, car, cdr, cons He then went on to add to his basic notation, to enable writing what he called S-functions: quote, cond, lambda, label On that basis, we'll call these "the LISP primitives" (although I'm open to an argument about type predicates like numberp...
The problem with trying to do this on a machine like McCarthy's LISP machine is that there isn't a way to prevent argument evaluation at runtime, and there's no way to change things around at compile time (which is what macros do: they rearrange code before it's compiled, basically). But that doesn't stop us from rewri...