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 |
|---|---|---|---|---|
4,625,645 | 4,625,836 | Problem with list in Lisp | I am trying to write a simple procedure in Lisp to insert an element into binary search tree.
I represented the tree as a list:
the first element in the tree is the root
the second element is the left sub-tree
the third element is the right sub-tree
This is my code:
(define Insert
(lambda (x T)
(if (null? T)
... | '(1 '()) is equivalent to (list 1 (list 'quote nil)). I suspect that if you drop the "internal" quote characters, you will be fine.
So, the quoted expression that generates an expression that is equal to (list 1 '() '()) is '(1 () ()).
|
4,626,613 | 4,627,125 | Slime: frame-source-location not implemented / is my sldb Backtrace output normal? | I'm debugging my (Common) Lisp code in Slime tied to clisp.
When the debugger generates the Backtrace it's my understanting that I can hit 'v' on a frame to take me to the source.
However, when I do this on the any frame I get:
frame-source-location not implemented
Is this expected, am I missing anything?
Edit1: In a... | Since posting the question I have found this link which seems to indicate the Slime and clisp integration is not quite working as it should be.
So, in the meantime I have installed Steel Bank Common Lisp (sbcl), as easy as (on Ubuntu/Debian)
sudo apt-get install sbcl
and configured Slime to use that instead of clisp:
... |
4,632,030 | 4,632,036 | Is there some lispy language that seamlessly integrates with Python? | Is there a language based on S-expressions with powerful macros that allows as seamless integration with Python as Clojure with JVM?
I want to try using such syntax and features while having access to all usual python libraries (including PyQt).
| I've been working a project to do this: psil. I have a series of blog posts talking about what I've done. Here's the short manifesto:
Psil is a new general-purpose programming language in the Lisp family of languages. Psil is implemented on top of Python, allowing easy access to existing Python libraries.
Best featur... |
4,632,461 | 4,632,553 | Do property lists in Common Lisp refer to some global state? | The code below has z as a local variable, yet it behaves as if it is a global:
(defun foo (m)
(let ((z '(stuff nil)))
(push m (getf z 'stuff))
(print z)))
(foo 1)
(foo 2)
(foo 3)
I would expect the output to be
(STUFF (1))
(STUFF (2))
(STUFF (3))
T
but when running it with SBCL I see
(STUFF (1))
(STUFF... | In foo, z is bound to the literal expression '(stuff nil). The function destructively alters z, thus destructively changing the value of the literal. How LISP behaves in circumstances like this is implementation-dependent. Some implementations will obediently alter the literal value (as in your case). Other impleme... |
4,638,710 | 4,638,720 | Maximum debug info from Steel Bank Common Lisp & Slime | What's the best way to initialise a Lisp session (I'm using Slime and sbcl) such that functions are always compiled with the maximum amount of debug information?
| (sb-ext:restrict-compiler-policy 'debug 3) in the repl or your .sbclrc will do it.
|
4,640,528 | 4,640,604 | SB-KERNEL:TWO-ARG - what does this mean when used in debugger backtrace? | I'm (a newbie) debugging my Lisp code (Common Lisp, Steel Bank, SLIME).
The first frame in my backtrace is:
0: (SB-KERNEL:TWO-ARG-> 1 NIL)
My question is:
what exactly does "SB-KERNEL:TWO-ARG" mean/check/do ?
where should I have looked this up online myself? (I tried searching for it but cann't find any reference to... | You can use "v" on a frame to jump to the definition of the function in the debugger.
In this case, the function sb-kernel:two-arg-> sounds like a specialized version of > that is called when there are exactly two arguments provided. If the arguments are 1 and NIL, you'll get an error because NIL is not a number.
I'm n... |
4,640,556 | 4,640,595 | How would one write down this mathematical expression programmatically? |
The sum of f(i) for all integers i =
k, k + 1, .., continuing only as long
as the condition p(i) holds.
I'm going for:
for (i = 0; i <= V_COUNT; i++) {
sum += sine_coeff[i] * pow(E, e_factor[i]) * sin(
(solar_coeff[i] * solar_anomaly)
+ (lunar_coeff[i] * lunar_anomaly)
+ (moon_coeff[i] * moon_argu... | Define a function p(), e.g.:
bool_t p(int i)
{
// some conditional code here, that returns TRUE or FALSE
}
It seems like you need to loop for an arbitrarily long time (i.e. there's no hard upper limit), and you need to stop looping when p(i) returns FALSE. Therefore, you probably want a loop something like this:
i... |
4,641,513 | 4,641,535 | Can lisp be used to write viruses or other malware? | I'm just curious. I always hear about C or assembly being the language of choice for viruses, and I wonder if any of the more arcane languages like lisp or scheme can be used for it too
| Yes - the important thing is not the language but whether the environment in which it runs has permission to modify files.
The AutoCAD W32/Bursted virus was written in a Lisp variant called AutoLISP.
See also:
Debugging what this LISP Virus is doing
|
4,641,802 | 4,642,323 | SDRAW is not working in my computer | i have installed clisp in my ubuntu machine. I am trying to use sdraw to display the cons structure. But this SDRAW is not working in my computer.I tried to use the examples given in the book A gentle indtroduction to symbolic computation. Can anybody tell me how can i enable it to work?
[edit]
i used following command... | yes i finally got the answer. we need to load the file sdraw.generic and we can have to load the file using the command.
>(load "sdraw.generic")
then use the sdraw command to display the cons art.
>BreakBreak 40 [45]> (sdraw '(1 2 (10)))
[*|*]--->[*|*]--->[*|*]--->NIL
| | |
... |
4,657,798 | 4,658,945 | Copy/Yank entire Lisp form in Slime | Is there a way to copy/yank a whole a form in Slime/Emacs?
For instance, if I have the following function:
(myfunc (lst)
(myotherfunc lst))
I'd like to yank/copy:
(myotherfunc lst)
by issuing a keyboard shortcut when my cursor is at the opening or closing parenthesis for that form (at the point where Slime/Emacs ... | In my Emacs, function kill-sexp is bound to C-M-k. That is, assuming the point is just before an opening delimiter of a balanced expression, press Control, Meta, and k at the same time.
This same command works in various other non-Lisp modes, such as killing brace-delimited blocks in a C-style mode, though the kill-sex... |
4,665,416 | 4,667,547 | Help me write my LISP :) LISP environments, Ruby Hashes | I'm implementing a rudimentary version of LISP in Ruby just in order to familiarize myself with some concepts. I'm basing my implementation off of Peter Norvig's Lispy (http://norvig.com/lispy.html).
There's something I'm missing here though, and I'd appreciate some help...
He subclasses Python's dict as follows:
clas... | If variable bindings in your Lisp are immutable, then copying environments is equivalent to linking them. But consider the following case:
(define main
(lambda ()
(define i 0)
(define increment-i
(lambda ()
(set! i (+ i 1))))
(increment-i)
i))
(main)
If increment-i's environment is co... |
4,682,576 | 4,684,913 | Find the most nested list inside a list in Common Lisp | I'm new to Common Lisp and functional programming, but I have a lot of experience in languages like C, C++, C#, Java and so on. I'm having trouble finding the most nested list inside a list. My input is something like this:
(0 1 (2 3) 4 (5 (6 (7) 8)) 9)
I would like to get the most nested list inside this list which i... | Here is my (not very clean) solution in CL:
(defun deepest-list (lst)
(let ((max-depth 0) ret)
(labels ((inner-deepest-lst (lst depth)
(cond
((null lst) depth)
((listp (car lst))
(let ((local-max (max
(inner-deepest-lst (first lst) (1+ depth))
... |
4,685,676 | 4,685,782 | Is there big syntax differences between Clojure and Lisp | I want to learn new language and I thought to start with Lisp. I want to know if I learn Lisp do I also know Clojure ( with minimal effort ), is there big syntax differences between Lisp and Clojure ?
| There are not big syntax differences (mostly because Lisp family languages have almost no syntax), but there are certainly differences in other areas. Clojure has a lot of modern programming features particularly suited to high scalability (actors, references, etc) that are not present as such in a "classic" Lisp (such... |
4,687,178 | 6,035,502 | Y Combinator in Scheme using Define | In order to learn what a fixed-point combinator is and is used for, I wrote my own. But instead of writing it with strictly anonymous functions, like Wikipedia's example, I just used define:
(define combine (lambda (functional)
(functional (lambda args (apply (combine functional) args))))
I've tested... | The answer is no, because according to the blog referred to in the previous answer, it doesn't even meet the definition of combinator, since 'combine' is a free variable.
|
4,693,428 | 4,693,963 | Is there a suitable replacement for C++, when I would like to write video processing applications? | I want to write a video editing software, and the "logical" conclusion is that the language I must to use is C++... But I don't like it (sorry c++ fans)
I would like to write it with something cool, like Lisp or Haskell or Erlang... But I don't know if the open source implementation of those languages (I don't have mon... | I can't speak to Lisp, but both Erlang and Haskell are capable of the performance necessary for video processing. Achieving that performance is likely to be more difficult than with C++ because there are fewer existing libraries in the domain, so you'll have to implement more yourself. Which means you'll have to be c... |
4,695,806 | 4,696,828 | Finding the maximum number of child nodes in a tree | First, I should make it clear that this is required for an academic project. I am trying to find the maximum number of child nodes for any node in a tree, using Common Lisp.
My current code is shown below - I'm not 100% on the logic of it, but I feel it should work, however it isn't giving me the required result.
(defu... | First, standard formatting:
(defun breadth (list y)
(setf l y)
(mapcar #'(lambda (element)
(when (listp element)
(when (> (breadth element (length element)) l)
(setf l (breadth element (length element))))))
list)
l)
(defun max-breadth (list)
(breadth... |
4,707,399 | 4,707,516 | robot programming with lisp? | I'm looking for some examples of robot/AI programming using lisp. Are there any good online examples available anywhere (preferably not too academic in nature)?
| XS Lisp on Lego Mindstorms: http://www.xslisp.com/ilc03.pdf
There are multiple references online on Clojure and Lego Mindstorms dealing with a Clojure API for Lego Mindstorms. In fact Lisp (in some form) and Leog Mindstorms's seems not uncommon: here's a AAAI paper on Lisp and Mindstorms with some code with a decided ... |
4,741,459 | 4,743,312 | are there any lisp implementations or 3rd party libraries that support dotnet or com interop | Any lisp environment supporting the following
1. using com objects.
2. acting as a com server...
| Allegro Common Lisp and IronScheme has built-in support for COM. You can get any Common Lisp that runs on Windows to talk to COM components or make it act as a COM server by using CFFI.
|
4,753,630 | 4,759,552 | How to loop using recursion in ACL2? | I need to make something like this but in ACL2:
for (i=1; i<10; i++) {
print i;
}
It uses COMMON LISP, but I haven't any idea how to do this task...
We can't use standard Common Lisp constructions such as LOOP, DO. Just recursion.
I have some links, but I find it very difficult to understand:
Gentle Intro to ACL2... | The section "Visiting all the natural numbers from n to 0" in A Gentle Introduction to ACL2 Programming explains how to do it.
In your case you want to visit numbers in ascending order, so your code should look something like this:
(defun visit (n max ...)
(cond ((> n max) ...) ; N exceeds MAX: nothing to... |
4,763,910 | 4,803,391 | ABCL compilation and primitives | Does anyone know how (or if) you can use ABCL to compile Lisp code to .class files and create a main method so that the whole thing could be packaged into a .jar file and run?
Also, does anyone know how to access primitives Java types from ABCL code?
| Didier Verner posted his experiences with just such a packaging question the other day.
|
4,766,084 | 4,772,643 | Programming Language for Berkeley Overmind Starcraft AI competition | Does anyone know which programming language the Berkeley Overmind submission to the Starcraft AI competition this past year was?
| You can download all of the bots here. The Overmind bot is written in Java.
The bot-Overmind directory in the distribution contains a large number of Java class files. It appears to use bwapi-jbridge to bridge the gap between the C++ BroodWar API and the Java code.
|
4,771,346 | 4,771,390 | exp in SBCL is wrong? | CL-USER> (exp 1)
2.7182817
Why? It should be 2.7182818 (rounded from 2.7182818284590452353602874713526624977572470936999595749669...)
SBCL 1.0.29.11.debian
| It is a rounding error inherent in the IEEE single-float format.
CL-USER> (exp 1.0d0)
2.718281828459045d0
|
4,785,333 | 4,785,634 | browse definitions in LISP | I am very new to LISP. I am using allegro-cl. I am having difficulty calling a function I have defined and loaded. I would like to know what are some ways I can browse the things I have defined, for instance listing all methods in a certain package, or listing just variables, or listing package names, etc.
| I'm not using Allegro CL, so I can only tell you about the tools CL itself provides for this. You might want to check what the Allegro CL IDE has to offer for this task.
You can get a list of all packages with the function LIST-ALL-PACKAGES. You could use it like this to print their names:
(dolist (p (list-all-packages... |
4,831,941 | 4,831,999 | What's the Clojure equivalent of inject:into: in Smalltalk? | I'm trying to learn Clojure but my synapses seem to be hard-wired to Smalltalk.
What's the equivalent of this function?
[:n :k | (1 to: k) inject: 1 into: [:c :i | c * (n - k + i / i)]]
this is the binomial coefficient for n, k - also known as "choose" function, representing the number of combinations of n things ta... | The clojure equivalent of lst inject: s into: f is (reduce f s lst)
|
4,833,953 | 4,842,661 | Permuting output of a tree of closures | This a conceptual question on how one would implement the following in Lisp (assuming Common Lisp in my case, but any dialect would work). Assume you have a function that creates closures that sequentially iterate over an arbitrary collection (or otherwise return different values) of data and returns nil when exhausted... | You'll clearly need some way of using each value returned by a generator more than once.
In addition to Rainer Joswig's suggestions, three approaches come to mind.
Caching values
permute-closures could, of course, remember every value returned by each generator by storing it in a list, and reuse that over and over. Th... |
4,842,913 | 4,843,410 | Conditional anaphoric collection best practices? | I trying to iterate through a sequence, conditionally perform an operation on each element and then collect it (but only if it matched the criteria). Here is a simplified example that works, I just want to know if this is proper or best practice in lisp:
(loop for n in '(1 2 3 4 5)
when (when (equal (mod n 2)... | I don't see why you need anaphor here.
(loop for n in '(1 2 3 4 5)
when (evenp n)
collect n and
do (format t "~A" n))
Delete the keyword AND if you want the FORMAT unconditionally.
|
4,843,237 | 4,978,994 | Transforming expression given in prefix notation, identifying common subexpressions and dependencies | I am given a bunch of expressions in prefix notation in an ANSI text file. I would like to produce another ANSI text file containing the step-by-step evaluation of these expressions. For example:
- + ^ x 2 ^ y 2 1
should be turned into
t1 = x^2
t2 = y^2
t3 = t1 + t2
t4 = t3 - 1
t4 is the result
I also have to identi... | The problem consists of two subproblems: parsing and symbolic manipulation. It seems to me the answer boils down to two possible solutions.
One is to implement everything from scratch: "I do recommend creating the full expression tree if you want to retain maximum flexibility for handling tricky cases." - proposed by R... |
4,846,515 | 4,846,654 | Lisp Exercises Involving List Manipulation | I trying to complete this exercise;
Write a Lisp function that takes as input a list of elements, such as (A B C)
, and returns a list in which the position of each element follows it, such as (A 1 B 2 C 3)
I'm trying to do it with two functions, however its not working correctly, I'm just getting the same list. Her... | Positions in Lisp start with 0. In insertIndex the variable len is not defined. The LOOP does not return any useful value.
If you want to solve it with recursion, the solution is much simpler.
You need to test for the end condition. If the list is empty, return the empty list.
Otherwise create a new list with the FIRST... |
4,847,558 | 4,848,166 | How to get dotted pairs in Lisp? | I've searched google and other places for a while but I can't find out how to generate or create dotted pairs. I ask this because, I need to turn a list that looks like this:
(X Y Z)
To a list that is in this format:
((X . 1) (Y . 2) (Z . 3))
Where the numbers represent the index. I have a function that turns the lis... | Your code has a very basic mistake:
(defun listFormat (l)
(defun place-index (idx l) ; <<<---- This DEFUN is wrong
(if (null l)
nil
(append (list (first l)) (list idx)
(place-index (+ idx 1) (rest l)))))
(place-index 1 l))
Don't nest DEFUN. That's just wrong. ... |
4,852,251 | 4,905,458 | Is there a software-engineering methodology for functional programming? | Software Engineering as it is taught today is entirely focused on object-oriented programming and the 'natural' object-oriented view of the world. There is a detailed methodology that describes how to transform a domain model into a class model with several steps and a lot of (UML) artifacts like use-case-diagrams or c... | Thank God that the software-engineering people have not yet discovered functional programming. Here are some parallels:
Many OO "design patterns" are captured as higher-order functions. For example, the Visitor pattern is known in the functional world as a "fold" (or if you are a pointy-headed theorist, a "catamorph... |
4,858,975 | 4,859,057 | In Emacs-lisp, what is the correct way to use call-process on an ls command? | I want to execute the following shell command in emacs-lisp:
ls -t ~/org *.txt | head -5
My attempt at the following:
(call-process "ls" nil t nil "-t" "~/org" "*.txt" "| head -5")
results in
ls: ~/org: No such file or directory
ls: *.txt: No such file or directory
ls: |head -5: No such file or directory
Any help wo... | The problem is that tokens like ~, *, and | aren't processed/expanded by the ls program. Since the tokens aren't processed, ls is look for a file or directory literally called ~/org, a file or directory literally called *.txt, and a file or directory literally called | head -5. Thus the error message you received about... |
4,868,375 | 4,868,419 | Is there anything like Lisp's SLIME for Python/Django? | I know about the Django console and it's useful to an extent but it would be really nice to be able to edit your code with the console open, lime SLIME in Emacs. Is there anything that facilitates this for Django or, failing that, at least Python?
| I do not know if this is exactly what you are looking for, but Workzeug provides a interactive debugging tool, which can be used like that. Just do a assert False and you can use the CLI as demonstrated in this screencast: http://ericholscher.com/blog/2008/sep/12/screencast-django-command-extensions/
|
4,873,810 | 4,873,847 | What does # mean in LISP | For example, #'functionname, is it necessary?
| #'functionname in Common Lisp
Common Lisp and some other Lisp dialects have more than one namespace. Here the ones for functions and values are different. To get the function value of a name, we need to write:
(function functionname)
Since that is a bit long to write, there is a shorter notation:
#'functionname
To sh... |
4,874,744 | 4,874,783 | Lisp and Erlang Atoms, Ruby and Scheme Symbols. How useful are they? | How useful is the feature of having an atom data type in a programming language?
A few programming languages have the concept of atom or symbol to represent a constant of sorts. There are a few differences among the languages I have come across (Lisp, Ruby and Erlang), but it seems to me that the general concept is the... | A short example that shows how the ability to manipulate symbols leads to cleaner code: (Code is in Scheme, a dialect of Lisp).
(define men '(socrates plato aristotle))
(define (man? x)
(contains? men x))
(define (mortal? x)
(man? x))
;; test
> (mortal? 'socrates)
=> #t
You can write this program using c... |
4,876,851 | 4,877,926 | Conflicting(?) 'FORMAT' function of emacs and SBCL | I have emacs with SLIME and SBCL. And I got stuck with the problem that emacs has definition of 'FORMAT' as format string &rest objects, so at REPL when I'm trying to evaluate something like (format t "hello"), I get error: Wrong type argument: stringp, t.
Is this the case of function to be overridden? How can I make e... | Emacs Lisp and Common Lisp (SBCL is an implementation of it) are two different languages; it is as if you were asking how to call Java's System.out.println from your Emacs Lisp.
Emacs Lisp is used to extend and customize the behavior or Emacs.
Common Lisp is a general purpose programming language, of which there are se... |
4,878,867 | 4,879,061 | emacs extension to do system call, sleep, then reload buffer | I want to write an emacs extension such that when I do M-x, b, k, e the following things occur:
a system/shell call is executed where the last argument is the full path to the file of the buffer that is currently selected.
wait for the command to terminate or sleep for 3 seconds if it isn't possible to block for the r... | This should be close:
(defun bke ()
(interactive)
(let ((buf-name (buffer-file-name)))
(with-temp-buffer
(shell-command (concat "your-command-here " buf-name) t))
(revert-buffer t t t))
|
4,879,609 | 4,881,301 | Why isn't REPL-style development more common in Ruby? | It looks like Lisp and Clojure programmers often develop programs directly in the REPL. cf. Clojure Development: IDE or REPL?
My question is, why isn't this approach more common in Ruby, via irb? Is this just a cultural difference, or are there structural (language-specific) reasons why REPL-centric development is more... | Lisp syntax seems to lend itself very nicely for a combined REPL-and-source-file approach. It is much easier to move code snippets around programmatically when the textual limits of each form are clear.
|
4,881,382 | 4,882,050 | Function which returns all values associated with a symbol | For example, I want a function that gives me all the values assigned to the one I give:
-> (giveme 'x '((x y) (x z) (b d) (x q)))
-> (y z q)
So the function should return in this case y z and q, as these are associated to x in pairs. Reason I ask this because I know there is a map function for it in one line.
| In Common Lisp:
CL-USER > (defun give-me (item list)
(mapcan (lambda (e)
(and (eq item (first e)) (list (second e))))
list))
GIVE-ME
CL-USER > (give-me 'x '((x y) (x z) (b d) (x q)))
(Y Z Q)
|
4,882,361 | 4,882,593 | Which command could be used to clear screen in CLISP? | Such as cls for cmd.exe. It's very annoy if I can't do this.
| You can use screen:clear-window to do this:
(screen:with-window (screen:clear-window screen:*window*))
For more information see the documentation on screen. Also note that these functions are specific to clisp.
|
4,888,480 | 4,888,975 | Practical use of curried functions? | There are tons of tutorials on how to curry functions, and as many questions here at stackoverflow. However, after reading The Little Schemer, several books, tutorials, blog posts, and stackoverflow threads I still don't know the answer to the simple question: "What's the point of currying?" I do understand how to curr... | One effective use of curried functions is decreasing of amount of code.
Consider three functions, two of which are almost identical:
(define (add a b)
(action + a b))
(define (mul a b)
(action * a b))
(define (action kind a b)
(kind a b))
If your code invokes add, it in turn calls action with kind +. The same ... |
4,892,822 | 15,926,020 | Automatic differentiation library in Scheme / Common Lisp / Clojure | I've heard that one of McCarthy's original motivations for inventing Lisp was to write a system for automatic differentiation. Despite this, my Google searches haven't yielded any libraries/macros for doing this. Are there any Scheme/Common Lisp/Clojure libraries (macros) out there for taking a function F and returning... | There are two other packages, both for automatic differentiation in Scheme. The second is based on the first, but reworked as a chicken egg. These support both forward and reverse mode.
https://github.com/qobi/R6RS-AD
https://github.com/abarbu/AD
|
4,894,522 | 4,894,571 | in emacs-lisp, how do I correctly use replace-regexp-in-string? | Given a string, I want to replace all links within it with the link's description. For example, given
this is a [[http://link][description]]
I would like to return
this is a description
I used re-builder to construct this regexp for a link:
\\[\\[[^\\[]+\\]\\[[^\\[]+\\]\\]
This is my function:
(defun flatten-string... | Your problem is that split-string is clobbering the match data, which
replace-regexp-in-string is relying on being unchanged, since it is going to
go use that match data to decide which sections of the string to cut out. This
is arguably a doc bug in that replace-regexp-in-string does not mention that
your replacement ... |
4,900,342 | 4,901,010 | Why is the hyphen conventional in symbol names in LISP? | What's the reason of this recommendation? Why not keeping consistent with other programming languages which use underscore instead?
| I think that LISP uses the hyphen for two reasons: "history" and "because you can".
History
LISP is an old language, and in the early days typing an underscore could be challenging. For example, the first terminal I used for LISP was an ASR-33 teletype. On some hosts and teletype models, the key sequence for the unde... |
4,906,203 | 4,906,352 | Pushing item locations in Casting SPELs | I'm going through Casting SPELs in Lisp and this is the proposed solution to handling picking up objects:
(define *location* 'living-room)
(define *object-locations*
'((whiskey-bottle living-room)
(bucket living-room)
(chain garden)
(frog garden)))
(define (pickup-object object)
(cond [(is-at? object ... | There are a few problems with the code:
The list *object-locations* is a literal. Literals should not be modified. You can't change the location of frog destructively. So you need to push a new location in front.
The list grows as you walk through the game.
STRING-APPEND creates a new string for each pickup action.
B... |
4,906,255 | 4,906,282 | What's the difference between ' and #' in Lisp? | It seems both
(mapcar 'car '((foo bar) (foo1 bar1)))
and
(mapcar #'car '((foo bar) (foo1 bar1)))
work as the same.
And I also know ' means (quote symbol) and #' means (function function-name).
But what's the underlying difference? Why these 2 both work in previous mapcar?
| 'foo
evaluates to the symbol FOO.
#'foo
evaluates to the function bound to the name FOO.
In Lisp a symbol can be called as a function when the symbol FOO has a function binding. Here CAR is a symbol that has a function binding.
But this does not work:
(flet ((foo (a) (+ a 42)))
(mapcar 'foo '(1 2 3 4 5)))
That's b... |
4,906,920 | 4,906,966 | Does ' have an effect in special forms in Lisp? | Will ' affect the evaluation of special forms? Example: (function 'function-name). If this doesn't work, why?
| 'name is read to (quote name).
FUNCTION expects a name for a function, a list (setf some-name) or a lambda expression.
(quote name) is neither. So it is an error to use it.
|
4,909,940 | 4,910,056 | I'm a lisp noobie, and I need a hash table class. | I'm kind of new to lisp, and after coming from languages like C, Java, and Python, where there is a well defined set of standard libraries, I'm a little lost in the sea of implementations and libraries out there.
I'm looking for a few nice data structures to use as primitives, such as RB trees and dictionaries.
| Common Lisp has a specification: CL HyperSpec.
Hash tables are part of that.
|
4,914,636 | 4,916,708 | lisp as a shebang script vs lisp running in SLIME | I just started with common-lisp, having come from C++ and Python. I'm trying to run a simple SDL program that does nothing other than show an image on-screen. I can get it working from within SLIME. The problem is, it won't work when run from the shell as a script.
My program looks like this:
#!/usr/bin/sbcl --script
... | As the man page for sbcl says, --script implies --no-sysinit --no-userinit --disable-debugger --end-toplevel-options, which means that initialization files are not read, and so if you set up ASDF registry there it is not set up, and so it cannot find the lispbuilder-sdl system. You need to either set up the registry in... |
4,914,867 | 4,915,009 | lisp on emacs: how to comment a multi-line expression? | For example, if I want to comment this:
(defun noop ()
nil)
Every time I try to put a semicolon before the "(defun", the defun runs away to the next line. So how is that supposed to be done?
GNU Emacs 23.1.1
Edit: by "running away" I mean when I insert a semicolon before "(defun", a newline is automatically inserted... | Ron, do a CTRL-H m and look at the minor modes. You have some "helpful" minor mode active. (Maybe paredit but I dont think that's it.) I remember there was something like that when I tried the EMACS Starter Kit. It lasted maybe thirty seconds before I screamed and found how to kill it.
In any case, that's not defau... |
4,926,237 | 4,926,450 | Help reducing a Lisp function | I have a Lisp function which returns either the MAX of two values, or the MIN of two values. Right now my code has some relatively complex expressions to evaluate VALUE1 and VALUE2.
(defun treemax (bilist &optional ismin)
(cond
;; Compute minimum
(ismin (min (COMPLEX_EXPRESSION_1) (COMPLEX_EXPRESSION_2)))
... | (defun treemax (bilist &optional ismin)
(funcall (if ismin #'min #'max)
(COMPLEX_EXPRESSION_1)
(COMPLEX_EXPRESSION_2)))
|
4,927,567 | 4,927,786 | Calling functions by name at runtime | I realize that a function can be referenced using #'PRINT to reference the PRINT function. If we have a list S where the first element is 'PRINT , can we reference this using #(car S) ?
Say I'm looking at a list where the elements in the list are atoms which are the names of some functions. Currently, I can do this:
... | #(car S) makes no sense. The syntax exists but means a vector with symbols CAR and S.
use
(funcall (first somelist) someargument)
or
(apply (first somelist) a-list-of-arguments)
Your function is non-Lispy formatted.
Trailing parentheses are not used in proper Lisp code. You also don't need to quote numbers. Numbers a... |
4,928,085 | 4,928,715 | How could I improve this solution to the "create index entries" exercise of Emacs Lisp Intro? | I've programmed this solution for the exercise from section 11.4 (Looping Exercise):
(defun texinfo-index-dfns-in-par ()
"Create an index entry at the beginning of the paragraph for every '@dfn'."
(interactive)
(save-excursion
(forward-paragraph)
(let ((bound (point)))
(backward-paragraph)
(le... | One thing to look at is narrowing. You can use narrowing to get around a lot of the bouncing back and forth you're doing.
(mark-paragraph)
(narrow-to-region)
Will limit the scope of your function to the current paragraph and move point to the beginning. You can then start your forward search without worrying about mov... |
4,930,493 | 4,931,427 | A function to compare sets; help improving efficiency | I am attempting to write a function which compares two lists to see if they represent the same set. That is '(a b c d d) and '(d c b a d) represent the same set. The elements can be in any order.
This is what I have, which works:
(defun samesetp (list1 list2)
(cond
((null list1) (null list2))
((eq list2 (re... | (defun samesetp (list1 list2)
(cond
((null list1) (null list2))
((eq list2 (remove (car list1) list2 :count 1)) nil)
(t (samesetP (cdr list1) (remove (car list1) list2 :count 1))))
)
)
First let's format it correctly:
(defun samesetp (list1 list2)
(cond ((null list1) (null list2))
... |
4,942,367 | 4,945,869 | Neural networks in Lisp - advice | Can anybody suggest a good tutorial or book for neural networks in Lisp, or a blog, or share some code sample?
I have experience with neural netowrks in the imperative languages C++, Java, C#, but I want to try it in Lisp.
| The seminal book AI: a modern approach includes LISP source code on the website: link
Specifically, check out the Learning chapter (perceptron etc)
In the same vein you have Paradigms of AI in Lisp, but it doesn't really touch neural networks if I remember correctly.
|
4,969,840 | 4,970,521 | Common Lisp Concatenate and newline | I am currently writing a LISP program which analyses the CR results in the form of lists like following:
("I" 0 10 0 20) << (word X0 X1 Y0 Y1)
It must build the whole text using positions of words.
My code has a cluster analyser which finds out cluster layouts like paragraphs with left- alignment or right or even both... | I can't quite follow your program, but it's much easier to work with string-streams and use format, write-string, write-line, terpri, and related functions, e.g.
(let ((lines '("Hi," "Here is my entry" "Good bye")))
(with-output-to-string (stream)
(dolist (line lines)
(write-line line stream)
(terpri ... |
4,970,111 | 4,970,594 | what does &rest mean in elisp? | What does the &rest mean in this: (append &rest sequences)
I have finished the book "elisp_intro",but I didn't find the answer. I will be very grateful if you can help me.
| It indicates that the following argument is the "rest" argument. In the case of your example, sequences is the rest argument.
Unlike a normal argument, the rest argument will consume the "rest" of any parameters provided by the user. It is a way of making a function that accepts a variable number of arguments. Inside t... |
4,980,520 | 4,980,585 | What can you do with Lisp macros that you can't do with first-class functions? | I think I understand Lisp macros and their role in the compilation phase.
But in Python, you can pass a function into another function
def f(filename, g):
try:
fh = open(filename, "rb")
g(fh)
finally:
close(fh)
So, we get lazy evaluation here. What can I do with mac... | First of all Lisp has first-class functions too, so you could as well ask: "Why do I need macros in Lisp if I already have first-class functions". The answer to that is that first-class functions don't allow you to play with syntax.
On a cosmetic level, first-class functions allow you to write f(filename, some_function... |
4,982,559 | 4,982,632 | elisp mapcar + lambda + defmacro help | I am trying to generate functions using a macro:
(defmacro make-my-emacs-command-region (cmd name)
(list 'defun (intern (format "my-emacs-command-%s-%s" cmd name))
'(&optional arg)
(list 'interactive "p")
(list (intern (format "mark-%s" name)) 'arg)
(list (intern (format "my-emacs-comm... | My elisp is a bit rusty, but until someone comes up with the actual explanation: I could get your examples to work a bit more as expected my replacing cmd with (eval cmd) (possibly same with name) in the macro definition body.
Hope this helps.
|
4,989,500 | 4,989,564 | Lisp: Why and how does '(nil nil) evaluate to true? | (if '(nil nil)
'print-true
'print-false)
(if '(nil)
'print-true
'print-false)
In the code above, why does the Lisp interpreter always evaluate these forms to true (print-true). I thought nil represented false in Common Lisp.
I am using GNU CLISP.
| nil is false. Anything else is true. '(nil) is a list with one element, namely nil. '(nil nil) is a list with two elements, namely nil and nil. Neither of these expressions is the same as nil by itself, so if sees it as true.
|
4,992,177 | 4,993,903 | Using emacs local variables to specify a path to be used in a command | I use emacs+AucTeX to write LaTeX files. At the bottom of the .tex file are some local variables:
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master-file"
%%% End:
These are added by AucTeX when I create the file.
What I'd like to do is write a lisp function that will do the following:
Check whether a par... | I don't know if you really want a complete solution, or would rather explore more yourself, but here are a few things that should help. Post again if you're stuck:
The variable file-local-variables-alist holds the values you're looking for. You'd want to use one of the assoc functions to get the value of pdf-copy-path... |
5,019,724 | 5,020,049 | In Emacs, what does this error mean? "Warning: cl package required at runtime" | I am byte-compiling a module. It gives me this warning:
Warning: cl package required at runtime
Why is this a warning? I am well aware that I am using the cl package. In fact there is a (require 'cl) statement in the module.
Is there something wrong with using the cl stuff?
If so, is there a list of published wo... | The reason of this warning is a GNU policy which does not want a package cl to be used in Elisp. But it would be foolish as well to prohibit it completely. So they decided to show a warning.
You can find more information here
|
5,020,957 | 5,021,573 | How is Lisp code structured? What are Packages and Systems? | I'm learning Lisp (SBCL) and I'm confused about how lisp code is structured. I believe that Lisp Packages are like Python's Modules?
I want to do something like this.
utilities.py:
def foo():
print "And there is silence!"
main.py:
import utilities as u
u.foo()
I've looked up packages, loading and asdf systems. I... | A package is a namespace for symbols. One can import and export symbols from and to symbols. A symbol maybe interned in one package. Packages can be used by other packages.
A program is structured into systems. A system is a collection of files, dependencies, build rules, default information and more - depebding on the... |
5,022,753 | 5,022,841 | How do I tell if a list contains NILs? | I have the following list:
(X O X O X NIL X NIL O)
If I do (find 'x (X O X O X NIL X NIL O)) it returns X, so I know the list contains X. But If I do (find nil (X O X O X NIL X NIL O)) I get NIL, which is meaningless because I'd get NIL even if my list didn't contain NIL.
How can I tell if my list contains NILs or not... | You can use position
(position NIL '(X O X O X NIL X NIL O))
--> 5
|
5,030,285 | 5,030,318 | Is ECMAScript really a dialect of Lisp? | A friend of mine drew my attention the welcome message of 4th European Lisp Symposium:
... implementation and application of
any of the Lisp dialects, including
Common Lisp, Scheme, Emacs Lisp,
AutoLisp, ISLISP, Dylan, Clojure,
ACL2, ECMAScript, ...
and then asked if ECMAScript is really a dialect of Lisp. Ca... | Brendan Eich wanted to do a Scheme-like language for Netscape, but reality intervened and he ended up having to make do with something that looked vaguely like C and Java for "normal" people, but which worked like a functional language.
Personally I think it's an unnecessary stretch to call ECMAScript "Lisp", but to ea... |
5,036,149 | 5,038,259 | how to make sbcl automatically load a core? | I have the core saved. How do I make sbcl load it automatically?
| The -core command line argument should do it. From the man page:
--core <corefilename>
Use the specified Lisp core file instead of the default. (See the FILES section for the
standard core, or the system documentation for SB-EXT:SAVE-LISP-AND-DIE for information
about how to create a custom cor... |
5,038,155 | 5,038,335 | In Common Lisp, is there a function that returns a symbol from a given string? | I want
>(??? "car")
CAR
>((??? "car") '(1 2))
1
I can't seem to find a function that does this.
| Are you looking for this?
(eval (read-from-string "(car '(1 2))"))
Gives: 1
UPDATE:
How about (funcall (intern "CAR") '(1 2)) ? :)
|
5,042,809 | 5,047,306 | Scheme Function to reverse elements of list of 2-list | This is an exercise from EOPL.
Procedure (invert lst) takes lst which is a list of 2-lists and returns a list with each 2-list reversed.
(define invert
(lambda (lst)
(cond((null? lst )
'())
((= 2 (rtn-len (car lst)))
( cons(swap-elem (car lst))
(invert (cdr lst))))
("... | The EOPL language provides the eopl:error procedure to exit early with an error message. It is introduced on page 15 of the book (3rd ed.).
The EOPL language does also include the map procedure from standard Scheme. Though it may not be used in the book, you can still use it to get a much shorter solution than one with... |
5,044,454 | 5,044,617 | Scheme: Why does evaluating this recursive function defined in letrec fail? | I am writing a silly letrec in Scheme (DrRacket Pretty Big):
(letrec
((is-creative?
(lambda (writing)
(if (null? writing)
#f
(is-creative?
(eval writing))))))
(is-creative?
(quote is-creative?)))
Syntax check was ok, but running it fails with:
reference to und... | Eval does not see local variables. In the scope where the eval is running, is-creative? is bound as a local variable but, because it's inside the (letrec) and not after it, it hasn't been bound in the global scope yet. See the documentation for eval, which discusses this:
http://docs.racket-lang.org/guide/eval.html
I d... |
5,046,007 | 5,046,255 | eval command onto other buffer in Emacs | I have a broken meta key and am trying to do M-x viper-mode onto an org file.
I want elisp to run (viper-mode) onto the example.org file from the scratch buffer.
| In Lisp, call set-buffer to switch to a different buffer for editing operations (this doesn't affect what buffer the user interacts with).
(save-excursion
(set-buffer "example.org")
(viper-mode))
The save-excursion form executes its arguments, then returns to the originally current buffer. Here, you could actually... |
5,055,717 | 5,056,278 | Need help putting radial distant into reverse polish notion for a lisp program | The distance formula for polar coordinated is shown here:
http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distancepolar.htm
I've tried doing it this way:
(defun distant-formula (r1 r2 t1 t2)
(setq d ( sqrt (*(-(+ (expt r1 2)(expt r2 2))(* 2 r1 r2))
(cos(- t1 t2))))))
but the extra parenthesis... | The variable D in your code is of no use. You should not assign values to undefined variables. Lisp also returns the value of the computation. That makes such an assignment especially useless.
You can write the formula like this:
(defun distant-formula (r1 r2 t1 t2)
(+ (expt r1 2)
(expt r2 2)
(* -2 r1 r2 (c... |
5,067,497 | 5,117,620 | Installing lisp/opengl on FreeBSD | I'm trying to make some simple graphics with OpenGL and LISP but I can't install the cl-opengl library on FreeBSD, so:
How do I install cl-opengl (or something similar) on FreeBSD?
| cl-opengl depends on native opengl libraries for the given platform. It is basically a lispy wrapper around libGl. Make sure you have one installed before attempting to install cl-opengl.
cl-opengl work with any lisp implementation that supports cffi. This means SBCL, ECL, CCL, ABCL and probably CLisp are ok.
|
5,074,781 | 5,119,355 | Editing programs "while they are running"? Why? | I've been getting more into Lisp and Lispy languages lately, and I'm finding them quite powerful.
One thing I've been reading all over the net is that a benefit of writing in Lisp, Clojure, etc, is that you can edit your program "while it's running".
Perhaps I'm missing something, but what is the point?
Sure, it might ... | There are some extremely cool use cases. One example is in GUI programming - I saw this while developing a GUI app in real time as it was running beside my Emacs: I added code for a new button and hit "C-c C-c" to compile that single function, and the button just appeared in the window! Didn't have to close and reopen ... |
5,093,513 | 5,093,808 | How to see docstrings and other symbol information in Common Lisp REPL? | I'm completely new to CL, and I'd like to learn how to read documentation strings and get other help information from the REPL. Something like help(symbol) in Python, or symbol? in iPython, or :t and :i in Haskell's GHCi.
So, given a symbol name, I'd like to be able to know:
what kind of value it is bound to, if any (... | As mentioned Common Lisp has standard functions: DESCRIBE, INSPECT and DOCUMENTATION. Typical Lisp IDEs also have these bound to keys and menus.
For standard Common Lisp functionality most IDEs directly link to the Common Lisp HyperSpec documentation with a keystroke.
Most IDEs also have keystrokes to show the arglist ... |
5,094,255 | 5,145,633 | Problem with macro behaviour in lisp | If in the REPL I do this:
(dolist (x (1 2 3))
(print x))
then I get an error since in (1 2 3) the digit 1 is not a symbol or a lambda expr.
If I do:
(dolist (x (list 1 2 3))
(print x))
then it works ok.
My question is why the following works:
REPL> (defmacro test (lst)
(dolist (x lst)
... | Macros get their arguments passed unevaluated. They may choose to evaluate them. dolist does that for its list argument. It works with an unquoted list passed in for lst in your macro test:
(defmacro test (lst)
(dolist (x lst)
(print x)))
That's because at macro-expansion time the dolist sees lst as its argument... |
5,097,561 | 5,098,163 | Killing buffers whose names start with a particular string | Here's my problem:
I use Emacs and get lots of buffers that are pretty useless all the time, like *Messages* or *Completions*.
I want to bind \C-y to close all buffers that start with * except for *shell* (and *shell* < k >) buffers.
To do that, I'd like to add some Emacs-Lisp in my .emacs file:
(defun string-prefix s1... | An alternate approach:
(require 'cl)
(defun is-useless-buffer (buffer)
(let ((name (buffer-name buffer)))
(and (= ?* (aref name 0))
(not (string-match "^\\*shell\\*" name)))))
(defun kill-useless-buffers ()
(interactive)
(loop for buffer being the buffers
do (and (is-useless-buffer buffer) ... |
5,120,780 | 5,121,387 | Can one safely ignore the difference between a macro and a built-in? | I'm starting out with Clojure, which is also my first lisp. There's obviously a lot to take in, and in an attempt to lessen the cognitive load, I try to find the parts which I can safely ignore (for now).
Can one safely treat forms with macros and forms with built-ins the same, or are there pitfalls that will spring up... | Macros in general compose very differently. Macros are not "first class citizens": you can't pass them to map etc., you can't store them in variables and you can't apply them to a list of arguments. Initially you don't need to worry about these because they will obviously not work: a subtle, hard-to-detect error would ... |
5,123,490 | 5,123,526 | Expanding a &rest parameter in Common Lisp | Suppose I get tired of writing "format t ..." all the time, and want something a little fewer keystrokes.
So I write this:
(defun puts (fstring &rest vars)
(format t fstring vars))
(puts "~a ~a" 1 2)
;; error message results, because vars became (1 2)
Now, vars has been transformed into a list of whatever params ... | You can use apply for that: (apply #'format t fstring vars) expands vars into separate arguments to format.
|
5,125,774 | 5,125,778 | Design your own connection to MySQL or PostgreSQL? | I am interested in creating my own connection to MySQL or PostgreSQL in Common Lisp. I know there are a few libraries that already exist for Common Lisp, but I want to have a better understanding of the respective database languages and Common Lisp by doing so myself. I searched around google and stackoverflow a bit, b... | Generally the language in which clients and servers communicate is called a protocol. Search "mysql protocol" or "postgres protocol" for the specification you need to implement.
http://dev.mysql.com/doc/internals/en/client-server-protocol.html
http://developer.postgresql.org/pgdocs/postgres/protocol.html
|
5,129,777 | 5,129,838 | Basic Scheme Recursion | I have a file like this:
declare
a = aexpress
b = bexpress
begin
My scheme program sets the current input port to this file then calls
(declarations (read))
What im getting back, is #f.
or rather the console says "The object #f is not applicable."
I have been over my parenthesis use and cant find an... | I've fixed the code formatting for you, which reveals what the problem is: you have too many layers of brackets around the (eq? token 'begin). The fixed version would look like this:
(define declarations
(lambda (token)
(cond ((eq? token 'begin) '())
(else (let* ((name token)
(eqs... |
5,150,374 | 5,150,396 | Why my merge sort implementation in Scheme is so slow? | I'm aware of Racket's stdlib, but I want to implement a sorting function by myself as an excercise. I decided to use merge sort algorithm as it is naturally defined in recursive terms. Pretty soon I've come up with working code, but it works too slow. It seems to me that the running time is exponential of the list size... | In split, you are calling (split tail) twice rather than using let to run it once and store the result into a variable. That is probably making split take exponential time.
|
5,151,685 | 5,151,877 | Shouldn't this function return the list back with all elements in it? | (defun r (list)
(let ((o ()))
(dolist (x list o)
(cons o x))))
(r (list 1 2 3))
It does not. it returns nil
| You need to change o somewhere. PUSH for example has the desired side-effect. CONS does not.
(defun r (list)
(let ((o ()))
(dolist (x list o)
(push x o))))
> (r (list 1 2 3))
(3 2 1)
|
5,153,817 | 5,154,000 | lisp format string that consumes one argument and prints in multiple directive places | I want to do this
(format nil "One occurence of ~X , another one: ~X , and yet another one: ~X" #\some-char)
Is there any X format directive that can do this?
| Found it: It is ~:* It tells lisp to reuse the last argument. Like rewinding the arguments one place back.
For the whole explanation paragraph see: http://www.gigamonkeys.com/book/a-few-format-recipes.html (it is near the bottom of the page)
So it becomes
(format nil "One occurence of ~C , another one: ~:*~C , and yet... |
5,155,160 | 5,155,631 | Print lisp function readably | I'm trying out lisp and working through the book Practical Common Lisp at http://www.gigamonkeys.com/book/.
Is there a command which can print a function which was previously defined at the REPL in a way that can later be read? I've tried
(print #'function-name)
but this results in output enclosed in #<> which can't ... | Function objects can't be read back.
1) You can use the function DRIBBLE, which causes the REPL input to be saved into a file.
2) Evaluating from an editor into the REPL is common. You don't need to type to the REPL, you can type into a editor text buffer and send the expressions from there to the REPL.
3) Common Lisp ... |
5,163,302 | 5,164,109 | Common Lisp Error: Expected-type: REAL datum: NIL | I'm working on actually writing something on my own in Common Lisp for once, implementing the Shunting-yard Algorithm. I thought it went okay, even if it came out rather ugly and if I doubt its Lispy-ness, but upon testing out the function in the REPL, I get the error in the title.
The code is as follows, with the test... | There are several errors:
First:
(defun determine-precedence (operator)
(case operator
(('+ '-) 2)
(('* '/) 3)
('^ 4)))
The quotes need to go. All.
Second:
(mapcar #'(lambda (x) (eq token x)) '(+ - * / ^))
Above is not doing what you think. Replace it with a call to MEMBER.
Third:
(when (< token-p... |
5,174,199 | 5,564,318 | Is there a simple way to use Python libraries from Common Lisp? | One thing I really miss when writing Common Lisp code is access to Python libraries, both standard library and third party modules. CLPython provides a limited subset of Python functionality which precludes the use of most libraries, so that's not really useful to me. I would like to be able to call Python code from Co... | One solution is python-on-lisp. It should be ASDF-installable. It hasn't been maintained or updated for a couple years, so there may be something better available.
|
5,186,816 | 5,186,902 | Any good implementation of Qt + Lisp? | I was searching for a good Qt + Lisp implementation on the internet and couldn't find any. Most projects were closed down or so.
Does anybody know of a good Common Lisp + Qt integration?
Thanks in advance.
| CommonQT
http://common-lisp.net/project/commonqt/
is a binding that may be able to help you.
|
5,214,206 | 5,268,353 | Getting CUSP working in Eclipse | I have just installed the latest unofficial version of Cusp to go along with this tutorial on Cusp. I do exactly as it says, verbatim, and when I save my main.lisp file, I see an error on the (in-package :new-lisp1) line which says
Package NEW-LISP1 not loaded
Right click on corresponding .asd file and select
Load Pack... | Okay, so I'm still not sure what caused the problem, but I reinstalled Eclipse fresh and then manually added the older, official release of Cusp to Eclipse. Everything is working fine.
In addition, I tried installing the newer Cusp on Eclipse on the Leopard machines at school, and it works fine. So perhaps it is a prob... |
5,215,849 | 5,216,239 | Continuation passing style - function composition | I'm learning about CPS with Racket, and I've managed to write up these functions:
;lift a regular single-arg function into CPS
(define (lift/k f)
(lambda (x k)
(k (f x))))
;compose two CPS functions
(define (compose/k f g)
(lambda (x k)
(g x (lambda (y)
(f y k)))))
They seem to work correctly
(... | The continuation-passing-style transform can be partial, or complete. You're usually working with a system where certain primitives (+, -, etc.) are stuck in non-cps-land. Fortunately, CPS works fine either way.
The steps in CPSing:
Pick which functions are going to be primitive.
CPS-transform so that all non-primit... |
5,217,213 | 5,217,523 | Lisp match keywords and find values | Say I have a list with keywords:
'(("element1" :keyword1 "a" :keyword2 "b")
("element2" :keyword3 "c" :keyword4 "d")
("element3" :keyword2 "e" :keyword4 "f"))
Which functions can I use to find which list elements contain :keyword2 and find its value in each list? I'm trying to do this in Emacs Lisp but I think wi... |
(require 'cl)
(defvar *data* '(("element1" :keyword1 "a" :keyword2 "b")
("element2" :keyword3 "c" :keyword4 "d")
("element3" :keyword2 "e" :keyword4 "f")))
(find :keyword2 *data* :test #'find)
;;=> ("element1" :keyword1 "a" :keyword2 "b")
(getf (cdr (find :keyword2 *data* :test #'... |
5,217,215 | 5,220,329 | Is anyone using Racket commercially? | I've been reading about how Racket is used for academic research, but I'm having a problem finding commercial success stories in business and/or start ups. Is anyone having any success using Racket commercially or am I barking up the wrong tree? I ask because I've got an idea for a start up and am evaluating languages ... | Several companies are using Racket commercially. One significant example is Untyped, which built their scheduling/workflow tracker system Kahu in Racket, and also uses it for other projects.
|
5,224,524 | 5,224,696 | Lisp and Prolog for Artificial Intelligence? | Now since i've taken a class 3 years ago in A.I. im clearly proficient enough to ask this question......just kidding just kidding ;)
but seriously, what is it about these languages that make them so popular for A.I. research. Even though A.I. research is "old"...it's came probably the longest way in the past 5-10 years... | Can't really speak to Prolog, but here's why Lisp:
Lisp is a homoiconic language, which means that the code is expressed in the same form (s-expressions) as data structures in the language. i.e. "code is data". This has big advantages if you are writing code that modifies/manipulates other code, e.g. genetic algorithm... |
5,225,695 | 5,225,748 | What varieties of LISP are there? | What are the different varieties of LISP and what are the most significant differences between them?
| The most popular dialects today are: Common Lisp, Scheme, and Clojure
The Clojure website has a page comparing and contrasting all three. Lisp diehards tend to prefer CL or Scheme. Clojure is the "hot new thing" and is a hybridization of Lisp and Java.
Common Lisp and Scheme both have a large number of implementations... |
5,226,767 | 6,251,535 | Does anybody know a good documentation that compares different Scheme implementations? | I am looking for a comparison of Chicken, SISC, Guile etc. I tried to compare them by myself, but I'm wondering whether something about it already exists.
| This is a table that shows the implementation status of various defined features across a series of Scheme implementations: http://web.mit.edu/~axch/www/scheme/choices.html
|
5,228,328 | 5,232,657 | LISP functions that perform both symbolic and numeric operations on expressions using +, -, *, and / | I'm currently working on a LISP exercise for a small project and need severe help. This may be more or less of a beginner's question but I'm absolutely lost on writing a certain function that takes in two unevaluated functions and spits out the result dependent on if the variables were given an assignment or not.
An ex... | Here's a full solution. It's pretty straightforward, so I'll leave out a full explanation. Ask me in the comments if there's anything you can't figure out yourself.
(Using eval to do the actual evaluation might not be what you want in your exercise/project. Look up "meta-circular interpreter" for another way.)
(defun a... |
5,230,399 | 5,231,993 | Setting up SLIME via macports | I followed the instructions as best I could for installing terminal SLIME on Mac OS X, but when I press M-x it does not prompt me.
I installed emacs and Lisp using the following two sudo commands:
sudo port install emacs +carbon
sudo port install sbcl slime
I got the following instructions:
(add-to-list 'load-path "... | Looks like you're on the right track already. Since you've only installed sbcl, and not the other lisps, just cut your initialization code down to this:
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime")
(require 'slime-autoloads)
(setq slime-lisp-implementations `((sbcl ("/opt/local/bin/sbcl")))
(add-ho... |
5,242,586 | 5,242,664 | Using lists with Common LISP | I'm just starting out with LISP, as in, just opened the book, I'm two pages into it. I'm trying to understand what is and what is not an acceptable fn call. Every time I try to execute
(1 2 3 4)
I get an illegal fn call error
same goes for
(cdr (1 2 3 4))
(first (1 2 3 4))
(a b c d)
Are CL programs unable to return ... | You need to quote lists if you are using them as constants. Otherwise, the system will try to call the function 1 on the arguments 2 3 4, which will not work (note that function calls have the same syntax as lists). Your examples should be:
'(1 2 3 4)
(cdr '(1 2 3 4))
(first '(1 2 3 4))
'(a b c d)
|
5,246,677 | 5,247,027 | Declaring design pattern in a Macro in Clojure | One of the virtues of Lisp is Macros. I have been reading a lot that in Java you write design patterns again and again. Not in Lisp/Clojure.
In Lisp/Clojure you’d declare the pattern in a macro and you’d only have to write the actual code.
Ok, nice and dandy but seeing is believing.
Would you please provide me (or refe... | Most of the existing design patterns originated and makes sense only in the Object Oriented world. As soon as you step into functional programming, and maybe especially Lisp dialects such as Clojure, your need for design patters gets smaller and smaller. There's an intresting discussion about design patterns and FP her... |
5,261,213 | 5,263,319 | Bug in s-expr printing function | To practice my Haskell skills, I'm following the Write Yourself a Scheme tutorial. I've implemented a parser for s-expressions, but I'm having trouble with the printing function.
When I run the following program
main :: IO ()
main = do args <- getArgs
putStrLn $ readExpr (args !! 0)
it parses the s-expre... | I found out myself:
showsVal (Pair x y) = ("(" ++) . showsPair x y . (++ ")")
should have been
showsVal (Pair x y) = ("(" ++) . showsPair x y . (")" ++)
-- ^^^^^^
|
5,261,262 | 5,278,728 | Multiple source files, directory structures and namespaces in functional programming | I was surprised to see that the source code for Hacker News is just one big file containing a flat list of function definitions.
Git Hub - news.arc
Is that typical for functional programming? Is it uncommon to have source in a lot of short files in a potentially deep directory structure as is common in OOP projects?
Ar... | There are many Functional Programming Languages (FPL) and they are very different. As are Lisp dialects (like Scheme, Common Lisp, Logo, Arc and others).
Often they are not organized around classes (or similar concepts) and classes are often not conflated with namespaces.
In some object oriented languages programs are ... |
5,282,089 | 5,282,309 | Listing directories in CLISP | I've been trying to see get a list of all files within a directory in CLISP, but I've only been able to get all non-directory files within a directory.
I'm currently trying this in Windows 7 with cygwin, so that may influence my results. I'm pretty new to CLISP (and LISP over all), and what I'm currently trying to do ... | See the CLISP implementation notes, section 20.3.2:
"If you want all the files and subdirectories in the current directory, you should use (NCONC (DIRECTORY "*/") (DIRECTORY "*"))."
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.