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 |
|---|---|---|---|---|
1,988 | 63,737 | How far can LISP macros go? | I have read a lot that LISP can redefine syntax on the fly, presumably with macros. I am curious how far does this actually go? Can you redefine the language structure so much that it borderline becomes a compiler for another language? For example, could you change the functional nature of LISP into a more object or... | That's a really good question.
I think it's nuanced but definitely answerable:
Macros are not stuck in s-expressions. See the LOOP macro for a very complex language written using keywords (symbols). So, while you may start and end the loop with parentheses, inside it has its own syntax.
Example:
(loop for x from 0 be... |
4,724 | 4,755 | Why should I learn Lisp? | I really feel that I should learn Lisp and there are plenty of good resources out there to help me do it.
I'm not put off by the complicated syntax, but where in "traditional commercial programming" would I find places it would make sense to use it instead of a procedural language.
Is there a commercial killer-app out ... | One of the main uses for Lisp is in Artificial Intelligence. A friend of mine at college took a graduate AI course and for his main project he wrote a "Lights Out" solver in Lisp. Multiple versions of his program utilized slightly different AI routines and testing on 40 or so computers yielded some pretty neat results... |
6,512 | 6,566 | How to implement continuations? | I'm working on a Scheme interpreter written in C. Currently it uses the C runtime stack as its own stack, which is presenting a minor problem with implementing continuations. My current solution is manual copying of the C stack to the heap then copying it back when needed. Aside from not being standard C, this solution... | I remember reading an article that may be of help to you: Cheney on the M.T.A. :-)
Some implementations of Scheme I know of, such as SISC, allocate their call frames on the heap.
@ollie: You don't need to do the hoisting if all your call frames are on the heap. There's a tradeoff in performance, of course: the time to ... |
10,149 | 10,161 | How do I bind a regular expression to a key combination in emacs? | For context, I am something of an emacs newbie. I haven't used it for very long, but have been using it more and more (I like it a lot). Also I'm comfortable with lisp, but not super familiar with elisp.
What I need to do is bind a regular expression to a keyboard combination because I use this particular regex so of... | You can use macros, just do C-x ( then do everything for the macro, then C-x ) to end the macro, then C-x e will execute the last defined macro. Then, you can name it using M-x name-last-kbd-macro which lets you assign a name to it, which you can then invoke with M-x TESTIT, then store the definition using M-x insert-... |
23,166 | 23,179 | What's a good beginning text on functional programming? | I like to study languages outside my comfort zone, but I've had a hard time finding a place to start for functional languages. I heard a lot of good things about Structure and Interpretations of Computer Programs, but when I tried to read through it a couple of years ago it just seemed to whiz over my head. I do way ... | The Little Schemer teaches recursion really well, and it's fun and simple to read.
I also liked The Scheme Programming Language for a broader introduction into the language.
|
31,561 | 31,603 | Keeping CL and Scheme straight in your head | Depending on my mood I seem to waffle back and forth between wanting a Lisp-1 and a Lisp-2. Unfortunately beyond the obvious name space differences, this leaves all kinds of amusing function name/etc problems you run into. Case in point, trying to write some code tonight I tried to do (map #'function listvar) which, ... | Map is more general than mapcar, for example you could do the following rather than using mapcar:
(map 'list #'function listvar)
How do I keep scheme and CL separate in my head? I guess when you know both languages well enough you just know what works in one and not the other. Despite the syntactic similarities they a... |
45,227 | 45,233 | List operations in Lisp | I have been searching everywhere for the following functionality in Lisp, and have gotten nowhere:
find the index of something in a list. example:
(index-of item InThisList)
replace something at a specific spot in a list. example:
(replace item InThisList AtThisIndex) ;i think this can be done with 'setf'?
return an... | You can use setf and nth to replace and retrieve values by index.
(let ((myList '(1 2 3 4 5 6)))
(setf (nth 4 myList) 101); <----
myList)
(1 2 3 4 101 6)
To find by index you can use the position function.
(let ((myList '(1 2 3 4 5 6)))
(setf (nth 4 myList) 101)
(list myList (position 101 myList))... |
59,428 | 59,434 | Which environment, IDE or interpreter to put in practice Scheme? | I've been making my way through The Little Schemer and I was wondering what environment, IDE or interpreter would be best to use in order to test any of the Scheme code I jot down for myself.
| Racket (formerly Dr Scheme) has a nice editor, several different Scheme dialects, an attempt at visual debugging, lots of libraries, and can run on most platforms. It even has some modes specifically geared around learning the language.
|
60,260 | 60,267 | My first Lisp macro; is it leaky? | I've been working through Practical Common Lisp and as an exercise decided to write a macro to determine if a number is a multiple of another number:
(defmacro multp (value factor)
`(= (rem ,value ,factor) 0))
so that :
(multp 40 10)
evaluates to true whilst
(multp 40 13)
does not
The question is does this macro l... | Siebel gives an extensive rundown (for simple cases anyway) of possible sources of leaks, and there aren't any of those here. Both value and factor are evaluated only once and in order, and rem doesn't have any side effects.
This is not good Lisp though, because there's no reason to use a macro in this case. A function... |
60,910 | 60,948 | Changing the font in Aquamacs? | I've recently had a need to do a bit of lisp editing and I found the nifty Ready Lisp package for OS X, which is great, except Aquamacs automatically uses a proportional font (which is idiotic, IMHO) and I want to change it to a monospace font. However, I'm not really much of an EMACS user, and the preferences menu in ... | This is what I have in my .emacs for OS X:
(set-default-font "-apple-bitstream vera sans mono-medium-r-normal--0-0-0-0-m-0-mac-roman")
Now, I'm not sure Bitstream Vera comes standard on OS X, so you may have to either download it or choose a different font. You can search the X font names by running (x-list-fonts "sea... |
64,953 | 77,554 | Anyone using Lisp for a MySQL-backended web app? | I keep hearing that Lisp is a really productive language, and I'm enjoying SICP. Still, I'm missing something useful that would let me replace PHP for server-side database interaction in web applications.
Is there something like PHP's PDO library for Lisp or Arc or Scheme or one of the dialects?
| newLisp has support for mysql5 and if you look at the mysql5 function calls, you'll see that it's close to PDO.
|
65,607 | 65,641 | Writing a ++ macro in Common Lisp | I've been attempting to write a Lisp macro that would perfom the equivalent of ++ in other programming languages for semantic reasons. I've attempted to do this in several different ways, but none of them seem to work, and all are accepted by the interpreter, so I don't know if I have the correct syntax or not. My id... | Remember that a macro returns an expression to be evaluated. In order to do this, you have to backquote:
(defmacro ++ (variable)
`(incf ,variable))
|
66,542 | 1,685,449 | How do I run Oracle plsql procedure from Lisp? | How do I get started?
| I have found the easiest way to achieve this by using Clojure.
Here is the example code:
(ns example
(:require [clojure.contrib.sql :as sql])
(:import [java.sql Types]))
(def devdb {:classname "oracle.jdbc.driver.OracleDriver"
:subprotocol "oracle"
:subname "thin:username/password@localho... |
77,934 | 104,227 | How do I display an image with ltk? | I have written code to read a windows bitmap and would now like to display it with ltk. How can I construct an appropriate object? Is there such functionality in ltk? If not how can I do it directly interfacing to tk?
| It has been a while since I used LTK for anything, but the simplest way to display an image with LTK is as follows:
(defpackage #:ltk-image-example
(:use #:cl #:ltk))
(in-package #:ltk-image-example)
(defun image-example ()
(with-ltk ()
(let ((image (make-image)))
(image-load image "testimage.gif")
... |
94,792 | 101,194 | Using Vim for Lisp development | I've been using Lisp on and off for a while but I'm starting to get more serious about doing some "real" work in Lisp. I'm a huge Vim fan and was wondering how I can be most productive using Vim as my editor for Lisp development. Plugins, work flow suggestions, etc. are all welcome.
Please don't say "use emacs" as I've... | Limp aims to be a fully featured Common Lisp IDE for Vim. It defaults to SBCL, but can be changed to support most other implementations by replacing "sbcl" for your favourite lisp, in the file /usr/local/limp/latest/bin/lisp.sh
When discussing Lisp these days, it is commonly assumed to be Common Lisp, the language stan... |
96,249 | 96,477 | How do I append to an alist in scheme? | Adding an element to the head of an alist (Associative list) is simple enough:
> (cons '(ding . 53) '((foo . 42) (bar . 27)))
((ding . 53) (foo . 42) (bar . 27))
Appending to the tail of an alist is a bit trickier though. After some experimenting, I produced this:
> (define (alist-append alist pair) `(,@alist ,pair))
... | You don't append to an a-list. You cons onto an a-list.
An a-list is logically a set of associations. You don't care about the order of elements in a set. All you care about is presence or absence of a particular element. In the case of an a-list, all you care about is whether there exists an association for a give... |
100,048 | 100,109 | I need to join two lists, sort them and remove duplicates. Is there a better way to do this? | I have two unsorted lists and I need to produce another list which is sorted and where all the elements are unique.
The elements can occur multiple times in both lists and they are originally unsorted.
My function looks like this:
(defun merge-lists (list-a list-b sort-fn)
"Merges two lists of (x, y) coordinates so... | Our neighbourhood friendly Lisp guru pointed out the remove-duplicates function.
He also provided the following snippet:
(defun merge-lists (list-a list-b sort-fn test-fn)
(sort (remove-duplicates (append list-a list-b) :test test-fn) sort-fn))
|
101,487 | 101,504 | Is it correct to use the backtick / comma idiom inside a (loop ...)? | I have some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 100 downto 1
collect `(,x . ,y))
My question is, is it correct to use `(,x . ,y) in this situation?
Edit: This sample is not about generating a table of 100x1... | It would be much 'better' to just do (cons x y).
But to answer the question, there is nothing wrong with doing that :) (except making it a tad slower).
|
105,816 | 105,990 | How do I access a char ** through ffi in plt-scheme? | I'm mocking about with plt-scheme's ffi and I have a C-function that returns a char ** (array of strings). If I declare my function as (_fun _pointer -> _pointer), how do I convert the result to a list of strings in scheme?
Here are the relevant C-declarations:
typedef char **MYSQL_ROW; /* return data as array of str... | I think that what you want is the cvector:
http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3acvector)
A cvector of _string/utf-8 or whichever encoding you need seems reasanable.
But that's from a quick survey of the docs - I haven't tried this myself. Please let me know if it works!
|
106,597 | 107,649 | Why are fixnums in Emacs only 29 bits? | And why don't they change it?
Edit:
The reason ask is because I'm new to emacs and I would like to use Emacs as a "programmer calculator". So, I can manipulate 32-bit & 64-bit integers and have them behave as they would on the native machine.
| Emacs-Lisp is a dynamically-typed language. This means that you need type tags at runtime. If you wanted to work with numbers, you would therefore normally have to pack them into some kind of tagged container that you can point to (i.e. “box” them), as there is no way of distinguishing a pointer from a machine intege... |
108,081 | 108,142 | Are there any High Level, easy to install GUI libraries for Common Lisp? | Are there any good, cross platform (SBCL and CLISP at the very least) easy to install GUI libraries?
| Ltk is quite popular, very portable, and reasonably well documented through the Tk docs. Installation on SBCL is as easy as saying:
(require :asdf-install)
(asdf-install:install :ltk)
There's also Cells-Gtk, which is reported to be quite usable but may have a slightly steeper learning curve because of its reliance on... |
108,169 | 108,248 | How do I take a slice of a list (A sublist) in scheme? | Given a list, how would I select a new list, containing a slice of the original list (Given offset and number of elements) ?
EDIT:
Good suggestions so far. Isn't there something specified in one of the SRFI's? This appears to be a very fundamental thing, so I'm surprised that I need to implement it in user-land.
| The following code will do what you want:
(define get-n-items
(lambda (lst num)
(if (> num 0)
(cons (car lst) (get-n-items (cdr lst) (- num 1)))
'()))) ;'
(define slice
(lambda (lst start count)
(if (> start 1)
(slice (cdr lst) (- start 1) count)
... |
108,537 | 108,619 | What are the main differences between CLTL2 and ANSI CL? | Any online links / resources?
| Bill Clementson has http://bc.tech.coop/cltl2-ansi.htm which is a repost of http://groups.google.com/group/comp.lang.lisp/msg/0e9aced3bf023d86
I also found http://web.archive.org/web/20060111013153/http://www.ntlug.org/~cbbrowne/commonlisp.html#AEN10329 while answering the question. I've not compared the two.
As the po... |
108,940 | 269,758 | How do I use (require :PACKAGE) in clisp under Ubuntu Hardy? | I am trying to evaluate the answer provided here, and am getting the error: "A file with name ASDF-INSTALL does not exist" when using clisp:
dsm@localhost:~$ clisp -q
[1]> (require :asdf-install)
*** - LOAD: A file with name ASDF-INSTALL does not exist
The following restarts are available:
ABORT :R1 ABOR... | use clc:clc-require in clisp. Refer to 'man common-lisp-controller'. I had the same error in clisp and resolved it by using clc:clc-require. sbcl works fine with just require though.
|
110,433 | 115,898 | Are there any Common Lisp implementations for .Net? | Are there any Common Lisp implementations for .Net?
| I haven't looked at it recently, but at least in the past there were some problems with fully implementing common lisp on the CLR, and I'd be a little surprised if this has changed. The issues come up with things like the handling of floats where .net/clr has a way to do it that is a) subtly incorrect b) disagrees wit... |
110,911 | 129,009 | What is the closest thing to Slime for Scheme? | I do most of my development in Common Lisp, but there are some moments when I want to switch to Scheme (while reading Lisp in Small Pieces, when I want to play with continuations, or when I want to do some scripting in Gauche, for example). In such situations, my main source of discomfort is that I don't have Slime (ye... | You also might consider Scheme Complete:
http://www.emacswiki.org/cgi-bin/wiki/SchemeComplete
It basically provides tab-completion.
|
116,654 | 116,661 | Non-C++ languages for generative programming? | C++ is probably the most popular language for static metaprogramming and Java doesn't support it.
Are there any other languages besides C++ that support generative programming (programs that create programs)?
| The alternative to template style meta-programming is Macro-style that you see in various Lisp implementations. I would suggest downloading Paul Graham's On Lisp and also taking a look at Clojure if you're interested in a Lisp with macros that runs on the JVM.
Macros in Lisp are much more powerful than C/C++ style and... |
123,234 | 123,410 | What is the best SQL library for use in Common Lisp? | Ideally something that will work with Oracle, MS SQL Server, MySQL and Posgress.
| if you mean common lisp by lisp, then there's cl-rdbms. it is heavily tested on postgres (uses postmodern as the backend lib), it has a toy sqlite backend and it also has an OCI based oracle backend. it supports abstracting away the different sql dialects, has an sql quasi-quote syntax extension installable on e.g. the... |
126,790 | 129,402 | If you already know LISP, why would you also want to learn F#? | What is the added value for learning F# when you are already familiar with LISP?
|
Static typing (with type inference)
Algebraic data types
Pattern matching
Extensible pattern matching with active patterns.
Currying (with a nice syntax)
Monadic programming, called 'workflows', provides a nice way to do asynchronous programming.
A lot of these are relatively recent developments in the programming la... |
130,475 | 131,334 | Why is Lisp used for AI? | I've been learning Lisp to expand my horizons because I have heard that it is used in AI programming. After doing some exploring, I have yet to find AI examples or anything in the language that would make it more inclined towards it.
Was Lisp used in the past because it was available, or is there something that I'm jus... | Lisp WAS used in AI until the end of the 1980s. In the 80s, though, Common Lisp was oversold to the business world as the "AI language"; the backlash forced most AI programmers to C++ for a few years. These days, prototypes usually are written in a younger dynamic language (Perl, Python, Ruby, etc) and implementations ... |
130,636 | 130,752 | How to compile Clisp 2.46? | When I try to compile the newest version of Clisp on Ubuntu 8.04 I always get this error after running configure:
Configure findings:
FFI: no (user requested: default)
readline: yes (user requested: yes)
libsigsegv: no, consider installing GNU libsigsegv
./configure: libsigsegv was not detected, thus some feat... | Here are my notes from compiling CLISP on Ubuntu in the past, hope this helps:
sudo apt-get install libsigsegv-dev libreadline5-dev
# as of 7.10, Ubuntu's libffcall1-dev is broken and I had to get it from CVS
# and make sure CLISP didn't use Ubuntu's version.
sudo apt-get remove libffcall1-dev libffcall1
cvs -z3 -d:ps... |
131,023 | 131,246 | List Comprehension Library for Scheme? | I know there is a list-comprehension library for common lisp (incf-cl), I know they're supported natively in various other functional (and some non-functional) languages (F#, Erlang, Haskell and C#) - is there a list comprehension library for Scheme?
incf-cl is implemented in CL as a library using macros - shouldn't it... |
Swindle is primarily a CLOS emulator library, but it has list comprehensions too. I've used them, they're convenient, but the version I used was buggy and incomplete. (I just needed generic functions.)
However, you probably want SRFI-42. I haven't used it, but it HAS to have fewer bugs than the Swindle list comprehens... |
131,433 | 133,356 | Sources for learning about Scheme Macros: define-syntax and syntax-rules | I've read JRM's Syntax-rules Primer for the Merely Eccentric and it has helped me understand syntax-rules and how it's different from common-lisp's define-macro. syntax-rules is only one way of implementing a syntax transformer within define-syntax.
I'm looking for two things, the first is more examples and explanatio... | To answer your second question: syntax-case is the other form that goes inside define-syntax. Kent Dybvig is the primary proponent of syntax-case, and he has a tutorial on using it [PDF].
I also read the PLT Scheme documentation on syntax-case for a few more examples, and to learn about the variation in implementation.... |
138,056 | 138,357 | When editing Lisp code, can emacs be configured to display each nested level of parentheses in a different color? | In other words, a block of code like this:
(setq initial-major-mode
(lambda ()
(text-mode)
(font-lock-mode)
))
... would come out looking like something like this:
If something like this already exists, what is it? And if it doesn't exist, how should I go about writing it?
| I think you are looking for something like mwe-color-box.el
|
144,661 | 144,864 | Python vs. Ruby for metaprogramming | I'm currently primarily a D programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can't be done in a statically compiled language like D.
I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that ... | There's not really a huge difference between python and ruby at least at an ideological level. For the most part, they're just different flavors of the same thing. Thus, I would recommend seeing which one matches your programming style more.
|
145,699 | 145,731 | Combining Lisp and PHP code in the same application | At the moment I use PHP for almost everything I develop for the Web but its linguistic limitations are starting to annoy me. However, as I developed some practices and maintain some PHP libraries that help me a lot, I don't feel I'd be ready to just switch to LISP throwing away all my PHP output. It could even be impos... | It's not a mutually-exclusive choice, you can run both on one system, in the same way that perl and php (for example) are run side-by-side on many systems.
There's a good post here on a similar topic, which suggests using sockets to communicate between both languages -
If you want to go the PHP<->Lisp route the easyes... |
146,081 | 146,191 | Emacs: How do you store the last parameter supplied by the user as the default? | I'm writing an interactive function that I'd like to have remember the last argument the user supplied and use it as the default.
(defun run-rake (param)
(interactive "sTask: ")
(shell-command (format "rake %s" task)))
The first time the function is invoked I want it to remember the argument the user supplied so... | You can see how the compile command does this. Bring up the help text for the compile command with C-h f compile, move the cursor over the name of the file that contains the function, then hit RETURN. This will bring up the source file for compile.
Basically, there's a dynamic/global variable compile-command that hol... |
147,918 | 148,139 | SBCL on Vista crashes. Do you know how to make it work? | I've searched a lot for an answer for this question in the web: they say it's true, SBCL doesn't work under Vista.
But I really need to work with lisp on my home Vista laptop and VM doesn't help really...
And CL is not so interesting because of speed...
If you have any recommendation, please share!
| Have you seen these articles?
http://robert.zubek.net/blog/2008/04/09/sbcl-emacs-windows-vista/
http://brainrack.wordpress.com/2008/05/29/running-sbcl-on-windows/
|
172,798 | 173,676 | Lisp in the real world | I have experimented with Lisp (actually Scheme) and found it to be a very beautiful language that I am interested in learning more about. However, it appears that Lisp is never used in serious projects, and I haven't seen it listed as a desired skill on any job posting. I am interested in hearing from anyone who has ... | Franz, Inc. provides an inexhaustive list of success stories on their website. However:
Please don't assume Lisp is only
useful for Animation and Graphics, AI,
Bioinformatics, B2B and E-Commerce,
Data Mining, EDA/Semiconductor
applications, Expert Systems, Finance,
Intelligent Agents, Knowledge
Management... |
187,219 | 187,393 | How do I get a terminal program to honour cursor keys? | I'm using ccl/openmcl on Mac OS X. (latest versions of both). When the lisp prompt is displayed, using the cursor keys to navigate the current line results in escape codes, rather than movement, eg:
Welcome to Clozure Common Lisp Version 1.2-r9226-RC1 (DarwinX8664)!
? (^[[D
Here I've pressed the ( key, and then the le... | If Clozure CL doesn't provide native readline/editline/whatever support or is configured not to use it, you can run it with rlwrap, for example:
rlwrap openmcl
rlwrap can be obtained via MacPorts or directly from http://utopia.knoware.nl/~hlub/rlwrap/.
|
192,049 | 192,336 | Is it possible to have an alias for the function name in Lisp? | ...just like packages do.
I use Emacs (maybe, it can offer some kind of solution).
For example (defun the-very-very-long-but-good-name () ...) is not to useful later in code. But the name like Fn-15 or the first letters abbreviation is not useful too.
Is it possible either to have an alias like for packages or to acces... | You want defalias. (defalias 'newname 'oldname) will preserve documentation and even show "newname is an alias for `oldname'" when its documentation is requested.
|
192,602 | 192,972 | Are there documented, organized collections of libraries for Common Lisp? | I am a college student at a school that teaches mainly in Java. One of the strong points of Java, which I quite enjoy, is the large collection of libraries. What makes these libraries especially useful is the extensive documentation and organization presented via JavaDoc. Are there any library collections for Common Li... | No, there is no comprehensive, consistently documented library collection. The inexistence of such a thing is Common Lisp's biggest problem right now. If you're interested in helping the Lisp community, this may well be the thing to attack first.
Also, while there are various JavaDoc equivalents, there is no widely a... |
208,835 | 208,940 | Function pointers, Closures, and Lambda | I am just now learning about function pointers and, as I was reading the K&R chapter on the subject, the first thing that hit me was, "Hey, this is kinda like a closure." I knew this assumption is fundamentally wrong somehow and after a search online I didn't find really any analysis of this comparison.
So why are C-st... | A lambda (or closure) encapsulates both the function pointer and variables. This is why, in C#, you can do:
int lessThan = 100;
Func<int, bool> lessThanTest = delegate(int i) {
return i < lessThan;
};
I used an anonymous delegate there as a closure (it's syntax is a little clearer and closer to C than the lambda eq... |
213,538 | 213,566 | centering text in common lisp | I have a string that I would like to print . Is it possible to center it when printing ?
| Use the ~< formatting directive. This will return "hello there" centered within 70 columns.
(format nil "~70:@<~A~>" "hello there")
|
215,883 | 614,707 | Creating a lambda from an s-expression | I have an s-expression bound to a variable in Common Lisp:
(defvar x '(+ a 2))
Now I want to create a function that when called, evaluates the expression in the scope in which it was defined. I've tried this:
(let ((a 4))
(lambda () (eval x)))
and
(let ((a 4))
(eval `(lambda () ,x)))
But both of these create a ... | You need to create code that has the necessary bindings. Wrap a LET around your code and bind every variable you want to make available in your code:
(defvar *x* '(+ a 2))
(let ((a 4))
(eval `(let ((a ,a))
,*x*)))
|
223,468 | 223,484 | Can someone help explain this scheme procedure | Question:
((lambda (x y) (x y)) (lambda (x) (* x x)) (* 3 3))
This was #1 on the midterm, I put "81 9" he thought I forgot to cross one out lawl, so I cross out 81, and he goes aww. Anyways, I dont understand why it's 81.
I understand why (lambda (x) (* x x)) (* 3 3) = 81, but the first lambda I dont understand what ... | This needs some indentation to clarify
((lambda (x y) (x y))
(lambda (x) (* x x))
(* 3 3))
(lambda (x y) (x y)); call x with y as only parameter.
(lambda (x) (* x x)); evaluate to the square of its parameter.
(* 3 3); evaluate to 9
So the whole thing means: "call the square function with the 9 as parameter".
EDIT:... |
231,649 | 232,638 | Lisp introspection? when a function is called and when it exits | With common lisp and I am assuming the introspection properties. How can I add code to common lisp code that will tell me when a function is called and when has finished executing. I want to take any lisp code and this particular modification to the code. I figure with lisp's AST analysis, this should be possible.
| You can use (trace function) for a simple mechanism. For something more involved, here is a good discussion from comp.lang.lisp.
[CL_USER]>
(defun fac (n)
"Naïve factorial implementation"
(if (< 1 n)
(* n (fac (- n 1)))
1))
FAC
[CL_USER]> (trace fac)
;; Tracing function FAC.
(FAC)
[CL_USER]> (fa... |
232,486 | 234,842 | Best Common Lisp IDE | I've used Slime within Emacs as my primary development environment for Common Lisp (or Aquamacs on OS X), but are there other compelling choices out there? I've heard about Lispworks, but is that [or something else] worth looking at? Or does anyone have tips to getting the most out of Emacs (e.g., hooking it up to the ... | There are some flashier options out there, but I don't think anything's better than Emacs and SLIME. I'd stick with what you're using and just work on pimping your Emacs install.
|
233,171 | 5,944,667 | What is the best way to do GUIs in Clojure? | What is the best way to do GUIs in Clojure?
Is there an example of some functional Swing or SWT wrapper?
Or some integration with JavaFX declarative GUI description which could be easily wrapped to s-expressions using some macrology?
Any tutorials?
| I will humbly suggest Seesaw.
Here's a REPL-based tutorial that assumes no Java or Swing knowledge.
Seesaw's a lot like what @tomjen suggests. Here's "Hello, World":
(use 'seesaw.core)
(-> (frame :title "Hello"
:content "Hello, Seesaw"
:on-close :exit)
pack!
show!)
and here's @Abhijith and @dsm's ... |
238,174 | 243,288 | Cross-compiling with SBCL | I have SBCL running on a Ubuntu machine. I want to write a little program that I want to give to a friend who has only Windows running. What is the quickest way to cross-compile it on my machine into a "standalone" windows program (i.e. the usual runtime+core combination)?
| SBCL is able to do a cross-compilation, but due to code being evaluated during the process, you need access to the target architecture. SBCL's build processed is well explained by Christophe Rhodes in SBCL: a Sanely-Bootstrappable Common Lisp
.
If you don't have directly access to a Windows machine, I suppose you could... |
245,677 | 247,229 | What are some things that you've used Scheme macros for? | Many examples of macros seem to be about hiding lambdas, e.g. with-open-file in CL. I'm looking for some more exotic uses of macros, particularly in PLT Scheme. I'd like to get a feel for when to consider using a macro vs. using functions.
| I only use Scheme macros (define-syntax) for tiny things like better lambda syntax:
(define-syntax [: x]
(syntax-case x ()
([src-: e es ...]
(syntax-case (datum->syntax-object #'src-: '_) ()
(_ #'(lambda (_) (e es ...)))))))
Which lets you write
[: / _ 2] ; <-- much better than (lambda (x) (/ x 2))
... |
248,180 | 248,385 | Lisp DO variable syntax reasoning | In Peter Seibel's Practical Common Lisp, he gives this example:
(do ((nums nil) (i 1 (1+ i)))
((> i 10) (nreverse nums))
(push i nums))
I can see how it works, using nums inside the loop but not giving it a step-form. Why would you put nums in the variable-definition rather than do this:
(let (nums) (do ((i 1 (... | Because it's convenient and saves indentation. Furthermore, the accumulator conceptually belongs to the loop, so why not put it there?
|
256,507 | 257,224 | How do I memoize a recursive function in Lisp? | I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the number of terms in a Collatz sequence (for problem 14 in Project Euler). My code as of yet is:
(defun collatz-steps (n)
(if (= 1 n) 0
(if (evenp n)
(1+ (collatz-steps (/ n 2)))
(1+ (collatz-steps (1+ (* 3... | I assume you're using Common-Lisp, which has separate namespaces for variable and function names. In order to memoize the function named by a symbol, you need to change its function binding, through the accessor `fdefinition':
(setf (fdefinition 'collatz-steps) (memoize #'collatz-steps))
(defun p14 ()
(let ((mx 0) ... |
260,685 | 260,705 | What is the best Scheme implementation for working through SICP? | I have been using PLT Scheme, but it has some issues. Does anyone know of a better implementation for working through SICP?
| Use MIT Scheme.
It's recommended by the authors of SICP, and is used at MIT for the 6.001: Structure and Interpretation of Computer Programs course.
|
262,628 | 262,684 | Using Lisp (or AutoLisp) how good is the associative lists performance? | I'm doing an AutoLisp project which uses long associative structures to do heavy geometrical processing - so I'm curious about the associative list intense use timing results.
How simple/complex is the implementation? It uses some data structure or a normal list of dotted pairs?
The are any extension for b-tree or some... | In Common Lisp and Emacs Lisp association lists are linked lists, so they have linear search time. Assuming that AutoLisp is the same (and if it isn't, then their use of the term "Associative List" is misleading), you can assume that all operations will be linear in the length of the list. For example, an alist with ... |
269,009 | 269,200 | What is the preferred way to serve web applications written in Lisp? | I've been researching modules for Nginx (my preferred webserver) to serve a Lisp webapp, but I haven't been able to find anything.
Is there modules for Nginx, or is there better ways to serve Lisp webapps? If so, what are they?
| If Nginx support proxying, you could always proxy to a Hunchentoot server running on localhost.
|
275,273 | 275,313 | How do I choose what language to use in DrScheme? | I recently downloaded PLT Scheme and DrScheme. When I open DrScheme, I am told to choose a language. However, I'm not familiar with any of my options, and the help guides don't really break it down to help me easily choose which choice.
So, first - is DrScheme and PLT Scheme really the tools I need to learn Lisp and/or... | Just go for "Pretty Big". That will be all you need until you know what the rest are for. I find that R5RS is good, but it does lack the extensions that PLT has added to DrScheme.
edit: I just checked and I guess that both "Pretty Big" and "R5RS" are considered "legacy" in DrScheme 4 and the "Module" language is favore... |
279,696 | 280,299 | Beginner at Common Lisp: Macro Question For Defining Packages on the Fly | Still struggling to understand what best practices are with respect to macros. I'm attempting to write a macro which defines packages on the fly.
(defmacro def-dynamic-package (name)
`(defpackage ,(intern (string-upcase name) "KEYWORD")
(:use :common-lisp)))
This works fine only for expressions such as:
(def-d... | defpackage is a macro. As such, it's expanded at compile-time, not run-time. What you want is something that is called at run-time in order to make a new package. Therefore, defpackage can't do anything for you.
Fortunately, there's also make-package, which provides defpackage's features as a function. Use it inste... |
282,905 | 629,463 | Are there any good editors for Lisp programming, other than Emacs? | I'm looking for an alternative, since I find emacs difficult to use. I'd rather use an editor that supports all the usual shortcuts I'm used to, such as arrow keys to move the cursor around, CTRL+SHIFT+RightArrow to select the next word, etc.
Basically, I don't want to have to relearn all my familiar shortcuts just so ... | Try LispIDE. It's kind of rudimentary but may improve things a bit for you.
|
293,040 | 293,118 | Function persistence in Common Lisp | Is there any persistence solution for Common Lisp, such as Elephant, that allows function persistence? Currently my app stores an identifier on the db and later searches in a function table which it is, but this method does not allow dynamically created functions to be stored.
| It's not a database persistence mechanism, but most Common Lisps have a way of writing FASLs for all kinds of objects, including functions. For example:
cl-user(1): (compile (defun hello () (format t "~&Hello~%")))
hello
nil
nil
cl-user(2): (excl:fasl-write (symbol-function 'hello) "/tmp/hello.fasl")
t
cl-user(3): (exc... |
293,567 | 293,580 | Side-effects in closures, are they still purely functional? | Being relatively new to functional programming, I expend lots of energy wondering “is this the functional way to do things?” Obviously recursion vs. iteration is pretty straightforward and it’s obvious that recursion is the functional way of doing things. But take closures for instance.
I’ve learned about closures usi... | You're right, using closures to manipulate state is not purely functional. Lisp allows you to program in a functional style, but it doesn't force you to. I actually prefer this approach because it allows me to strike a pragmatic balance between purely functional and the convenience of modifying state.
What you might tr... |
294,779 | 294,789 | Function names as strings in Lisp? | I have a big list of global variables that each have their own setup function. My goal is to go through this list, call each item's setup function, and generate some stats on the data loaded in the matching variable. However, what I'm trying now isn't working and I need help to make my program call the setup functions.... | It's because MAKE-SYMBOL returns an uninterned symbol. You should use INTERN instead.
|
294,852 | 295,510 | References Needed for Implementing an Interpreter in C/C++ | I find myself attached to a project to integerate an interpreter into an existing application. The language to be interpreted is a derivative of Lisp, with application-specific builtins. Individual 'programs' will be run batch-style in the application.
I'm surprised that over the years I've written a couple of compiler... | Short answer:
The fundamental reading list for a lisp interpreter is SICP. I would not at all call it overkill, if you feel you are overqualified for the first parts of the book jump to chapter 4 and start interpreting away (although I feel this would be a loss since chapters 1-3 really are that good!).
Add LISP in Sma... |
309,440 | 310,182 | Lisp In A Box - Why is it starting a server? | I've decided to get back into LISP (haven't used it since my AI classes) to get more comfortable with functional programming in general, so I downloaded Lisp In A Box (which we actually used in a previous class) which comes with CLISP and Emacs.
When I run it, it says:
Connected on port 1617. Take this REPL, brother, ... | Sockets are more flexible than pipes. For one, SLIME lets you connect to Swank servers on the network, which is very useful for doing live fixes on remote machines with long-running processes (such as web servers). Given this, why would you add another layer of complexity by abstracting communication in such a way as... |
318,785 | 318,913 | Emacs mode that highlight Lisp forms | What is the Emacs mode or package that highlights Lisp forms changing the color of the backgrounds so that the form you are in has one color, the outer form another, the outer outer form another and so on?
| You may want to try mwe-color-box (screenshot below) or read Five approaches to s-expression highlighting by Lemondor.
(source: foldr.org)
|
318,952 | 319,029 | Convert string to code in Scheme | How do I convert a string into the corresponding code in PLT Scheme (which does not contain the string->input-port method)? For example, I want to convert this string:
"(1 (0) 1 (0) 0)"
into this list:
'(1 (0) 1 (0) 0)
Is it possible to do this without opening a file?
| Scheme has procedure read for reading s-expressions from input port and you can convert a string to input stream with string->input-port. So, you can read a Scheme object from a string with
(read (string->input-port "(1 (0) 1 (0) 0)"))
I don't have Scheme installed, so I only read it from reference and didn't actually... |
330,371 | 330,582 | Are Databases and Functional Programming at odds? | I've been a web developer for some time now, and have recently started learning some functional programming. Like others, I've had some significant trouble apply many of these concepts to my professional work. For me, the primary reason for this is I see a conflict between between FP's goal of remaining stateless see... | First of all, I would not say that CLOS (Common Lisp Object System) is "pseudo-OO". It is first class OO.
Second, I believe that you should use the paradigm that fits your needs.
You cannot statelessly store data, while a function is flow of data and does not really need state.
If you have several needs intermixed, mi... |
334,691 | 340,089 | The tool for visual programming | I need the tool for graphical representing of work flow in a program (like electronic circuits are described with graphical representation). The representation has to be like the following: functions are boxes and arrows between boxes are "messages". Like this:
alt text http://img372.imageshack.us/img372/8471/functions... | What about using something like Graphviz?
|
340,989 | 341,002 | Elisp performance on Windows and Linux | I have the following dead simple elisp functions; the first removes the fill breaks from the current paragraph, and the second loops through the current document applying the first to each paragraph in turn, in effect removing all single line-breaks from the document. It runs fast on my low-spec Puppy Linux box using ... | As the first try, you should download and install Emacs 22.3 for your Windows box and then compare the speed.
Speed difference shouldn't be that big after upgrade.
|
369,122 | 369,332 | "Don't know how to create ISeq from: Symbol" error in Clojure | I have the following Clojure code and I'm not sure why it's not working:
(defn match (x y &optional binds)
(cond
((eql x y) (values binds t))
((assoc x binds) (match (binding x binds) y binds))
((assoc y binds) (match x (binding y binds) binds))
((var? x) (values (cons (cons x y) binds) t))
((var? y) (... | The problem is that I'm using parentheses ('(' and ')'), rather than square brackets ('[' and ']'), for the arguments list.
It should start out like this:
(defn match [x y &optional binds]
(I found the answer in Programming Clojure by Stuart Halloway.)
|
378,972 | 379,071 | How do I make an Emacs keybinding to set a variable? | I've got a variable in Emacs called my-var that I'd like to set whenever I press C-v. How do I do that? I tried this:
(defun set-my-var (value)
"set my var"
(interactive)
(defvar my-var value
"a variable of mine")
)
(global-set-key "\C-v" 'set-my-var)
But that fails:
call-interactively: Wrong number of argu... | Actually, defvar doesn't do what you think it does either: it only changes the value IF there was no value before. Here's a chunk that does what you're looking for, using the CTRL-u argument:
(defun set-my-var (value)
"Revised version by Charlie Martin"
(interactive "p")
(setq my-var value))
and here's an examp... |
379,136 | 379,970 | Can I extend lisp with c++? | Can I call a function from lisp from a library written in c or c++? How can I extend lisp?
This is useful when you want to do some system calls or stuff like that.
| It is unusual to call non-lisp code from lisp, and rarely necessary. CLX (the X11 client implementation for CL) doesn't link to the Xlib implementation but "speaks" X11 directly. On any system, your CL implementation is likely to already have excellent operating system hooks rendering this unnecessary.
That said, the a... |
384,419 | 384,716 | LISP Displaying binary tree level by level | I have a list that looks like (A (B (C D)) (E (F))) which represents this tree:
A
/ \
B E
/ \ /
C D F
How do I print it as (A B E C D F) ?
This is as far as I managed:
((lambda(tree) (loop for ele in tree do (print ele))) my-list)
But it prints:
A
(B (C D))
(E (F))
NIL
I'm pretty new to Comm... | Taking your question at face value, you want to print out the nodes in 'breadth-first' order, rather than using one of the standard, depth-first orderings: 'in-order' or 'pre-order' or 'post-order'.
in-order: C B D A E F
pre-order: A B C D E F
post-order: C D B F E A
requested order: A B E C D F
In your tree structur... |
386,854 | 464,210 | How do you type lisp efficiently, with so many parentheses? | I try to keep my fingers on home row as much as possible.
Typing all the parentheses makes me move away from there a fair bit.
I use Emacs; the parentheses themselves are no issue, I'm comfortable with them. And I don't like modes that type them for me automatically.
I've thought about remapping the square brackets t... | I would personally recommend the lethal combo of Emacs, SLIME & paredit.el
Paredit allows you to pseudo-semantically edit the LISP code at sexp level, and that makes the parentheses disappear almost completely. You can move around sexps as if they are simple words and even mutate them with just a couple of key-strokes.... |
398,579 | 398,585 | What's the best way to learn LISP? | I have been programming in Python, PHP, Java and C for a couple or years now, and I just finished reading Hackers and Painters, so I would love to give LISP a try!
I understand its totally diferent from what i know and that it won't be easy. Also I think (please correct me if I'm wrong) there's way less community and d... | Try reading Practical Common Lisp, by Peter Seibel.
|
405,165 | 405,188 | Please advise on Ruby vs Python, for someone who likes LISP a lot | I am a C++ developer, slowly getting into web development. I like LISP a lot but don't like AllegroCL and web-frameworks available for LISP. I am looking for more freedom and ability to do cool hacks on language level. I don't consider tabs as a crime against nature.
Which one is closer to LISP: Python or Ruby?
I can'... | I'd go with Ruby. It's got all kinds of metaprogramming and duck punching hacks that make it really easy to extend. Features like blocks may not seem like much at first, but they make for some really clean syntax if you use them right. Open classes can be debugging hell if you screw them up, but if you're a responsible... |
406,426 | 406,455 | Logical Languages - Prolog or Lisp/Smalltalk or something else? | So, I am writing some sort of a statistics program (actually I am redesigning it to something more elegant) and I thought I should use a language that was created for that kind of stuff (dealing with huge data of stats, connections between them and some sort of genetic/neural programming).
To tell you the truth, I jus... | Is there any particular reason not to use R? It's sort of a build vs. buy (or in this case download) decision. If you're doing a statistical computation, R has many packages off the shelf. These include many libraries and interfaces for various types of data sources. There are also interface libraries for embedding... |
407,658 | 409,281 | How to save all functions I entered in LispBox/Slime? | Situation: I entered several functions while working with REPL in Emacs.
Problem: There is junk like "; Evaluation aborted" when I'm simply saving buffer.
What I want: clear descriptions of all the functions I entered in their latest revision.
Can I do that? Thanks.
| I agree that the best work flow method is to write your code in a separate buffer and evaluate in that, rather than enter the functions in the repl.
Assuming you have gone the repl way, I guess, C. Martin's solution to save the repl log and manually go through it are your only options.
If you entered the functions and ... |
420,300 | 425,000 | Lisp: Need help getting correct behaviour from SBCL when converting octet stream to EUC-JP with malformed bytes | The following does not work in this particular case, complaining that whatever you give it is not a character.
(handler-bind ((sb-int:character-coding-error
#'(lambda (c)
(invoke-restart 'use-value #\?))))
(sb-ext:octets-to-string *euc-jp* :external-format :euc-jp))
Where *euc... | There's an expression in SBCL 1.0.18's mb-util.lisp that looks like this:
(if code
(code-char code)
(decoding-error array pos (+ pos bytes) ,format
',malformed pos))
I'm not very familiar with SBCL's internals, but this looks like a bug. The consequent returns a character, while the altern... |
426,991 | 427,020 | LISP very simple list question | Im learning lisp and im pretty new at this so i was wondering...
if i do this:
(defparameter *list-1* (list 1 2))
(defparameter *list-2* (list 2 3))
(defparameter *list-3* (append *list-1* *list-2*))
And then
(setf (first *list-2*) 1)
*list-3*
I will get (1 2 1 4)
I know this is because the append is going to "save r... | One defensive tactic is to avoid sharing structure.
(defparameter *list-3* (append *list-1* *list-2* '()))
or
(defparameter *list-3* (append *list-1* (copy-list *list-2*)))
Now the structure of the new *list-3* is all new, and modifications to *list-3* won't affect *list-2* and vice versa.
|
427,332 | 427,333 | asdf-installing libraries from the command-line | Coming from a Perl background, I have to say I prefer cpan Foo::Bar to the having to start sbcl, (require :asdf-install) and finally (asdf-install:install :foo-bar). Is there anything more convenient than this around?
| There is clbuild:
http://common-lisp.net/project/clbuild/
But I add this to my .bashrc:
function asdf_install {
sbcl --eval "(asdf:operate 'asdf:load-op :asdf-install)" --eval "(asdf-install:install :$1)" --eval "(quit)"
}
function asdf_oos {
rlwrap sbcl --eval "(asdf:operate 'asdf:$2 :$1)"
}
|
437,312 | 437,584 | Trying to learn: Object Reorientation, and generic functions in LISP! | im reading Practical common Lisp as a result of another question.
I just read chapter 16 and 17 where you can find how LISP manages objects. But after a couple of years of thinking how Java manages objects, i cant really seem to understand how you would implement bigger architectures in LISP using the CLOS.
So i ask y... | Perhaps take a look at the example applications that are walked through in the later chapters. You will see that classes and objects are just another tool in your box. Resist the urge to program Java with Lisp syntax.
Another place to look at is Successful Lisp, chapters 7 and 14 for the basics, and chapters 31 and a... |
445,594 | 445,807 | Weird HTTP problem/mistake with Lisp | I'm attempting to learn a little more about handling sockets and network connections in SBCL; so I wrote a simple wrapper for HTTP. Thus far, it merely makes a stream and performs a request to ultimately get the header data and page content of a website.
Until now, it has worked at somewhat decently. Nothing to brag ho... | A few things. First, to your concern about the 400 errors you are getting back, a few possibilities come to mind:
"Host:" isn't actually a valid header field in HTTP/1.0, and depending on how fascist the web server you are contacting is about standards, it would reject this as a bad request based on the protocol you c... |
459,323 | 459,381 | What is the best Scheme or LISP implementation for OS X? | I am looking for a version of Scheme or even LISP that I can use to recover some lost Lisp development skills. Some web capabilities would be nice but not essential.
I've looked at Plt and MIT scheme and, while both look pretty good, the Plt seems to be more feature rich. I've also looked at Lisp implementations but... | I'd go with Racket. It may not be as fast as SBCL, but it does have excellent libraries and documentation, as well as an integrated environment that's designed to get you developing and running Scheme programs right out of the gate. What I really like about Racket's IDE, DrRacket, is what you don't have to do—you don't... |
463,463 | 463,837 | Dynamic and Lexical variables in Common Lisp | I am reading the book 'Practical Common Lisp' by Peter Seibel.
In Chapter 6, "Variables" sections
"Lexical Variables and Closures" and "Dynamic, a.k.a. Special, Variables".
http://www.gigamonkeys.com/book/variables.html
My problem is that the examples in both sections show how (let ...) can shadow global variables and ... | When a variable is lexically scoped, the system looks to where the function is defined to find the value for a free variable. When a variable is dynamically scoped, the system looks to where the function is called to find the value for the free variable. Variables in Common Lisp are all lexical by default; however, dyn... |
473,967 | 474,031 | What is the best approach for a tail-optimized function for calculating the length of a list? | Here is an example that a forum poster gave, I can't tell if this tail optimized. Also, could someone give a laymans description of how a tail optimized version would trump the normal version.
(defun mylength (s)
(labels ((mylength-inner (s x)
(if (car s) (mylength-inner (cdr s) (+ x 1)) x)))
... | A function can be tail-call optimized if it returns a straight call to itself or no call to itself. The function mylength-inner will return either x or (mylength-inner (cdr s) (+ x 1)), and so it can be tail-optimized.
This means the compiler can turn it into a loop instead of calling the function recursively. Either... |
480,083 | 585,784 | What is a Lisp image? | Essentially, I would like to know what a Lisp image is? Is it a slice of memory containing the Lisp interpreter and one or more programs or what?
| The Lisp image as dumped memory
The image is usually a file. It is a dump of the memory of a Lisp system. It contains all functions (often compiled to machine code), variable values, symbols, etc. of the Lisp system. It is a snapshot of a running Lisp.
To create an image, one starts the Lisp, uses it for a while and t... |
481,803 | 481,858 | Converting some LISP to C# | I'm reading Paul Graham's A Plan for Spam and want to understand it better but my LISP is really rusty. He has a snippet of code that calculates probability as such:
(let ((g (* 2 (or (gethash word good) 0)))
(b (or (gethash word bad) 0)))
(unless (< (+ g b) 5)
(max .01
(min .99 (float (/ (min 1... | I think it's something like this (warning, possible errors ahead. This snippet is intended as a guide, not a solution):
var g = 2 * (gethash(word, good) | 0);
var b = gethash(word, bad) | 0;
if( (g + b) >= 5)
{
return Math.Max(
0.01,
Math.Min(0.99,
Math.Min(1, b / nbad) /
... |
486,360 | 486,523 | Uses for both static strong typed languages like Haskell and dynamic (strong) languages like Common LIsp | I was working with a Lisp dialect but also learning some Haskell as well. They share some similarities but the main difference in Common Lisp seems to be that you don't have to define a type for each function, argument, etc. whereas in Haskell you do. Also, Haskell is mostly a compiled language. Run the compiler to... | Programming languages are tools for thinking with. You can express any program in any language, if you're willing to work hard enough. The chief value provided by one programming language over another is how much support it gives you for thinking about problems in different ways.
For example, Haskell is a language tha... |
487,209 | 487,310 | Loop over variables in Lisp | I wrote the function
(defun test ()
(let ((str1 "foo") (str2 "bar"))
(loop for s in '(str1 str2) do (message s))))
but it does not work. The Elisp Backtrace message is:
Debugger entered--Lisp error: (wrong-type-argument stringp str1)
How can I make it work?
P.S.: the following modified version works perfectly,... | The quote operator (for which the apostrophe is syntactic sugar) means that its arguments are not evaluated, i.e. (quote (str1 str2)) returns a list of two symbols. Use list instead: (list str1 str2).
|
497,890 | 499,046 | Learning Clojure without Java Knowledge | Ok, so I'm psyched about another list. I got myself a copy of the beta Clojure programming book...
And the one thing I'm noticing most is that it's assumed I know... like all the major java classes.
Except, generally, I don't really care about Java. I just want enough knowledge of it for Clojure to be an option for m... | My main recommendation for you, you've already accomplished by buying Programming Clojure. I've avoided and loathed Java for years and years, and (Programming) Clojure rehabilitated it enough that the language now excites me. Who'd've thought that a famously onerous system would let you interactively (map #(.getName ... |
500,026 | 500,448 | What is a good mathematically inclined book for a Lisp beginner? | I am looking for a mathematical book on Lisp. Some ideas?
| Structure and Interpretation of Computer Programs uses mathematical examples. It's not really a book for learning a particular version of Lisp, but you'll learn the concepts.
|
506,167 | 506,194 | Building a Texas Hold'em playing AI..from scratch | I'm interested in building a Texas Hold 'Em AI engine in Java. This is a long term project, one in which I plan to invest at least two years. I'm still at college, haven't build anything ambitious yet and wanting to tackle a problem that will hold my interest in the long term. I'm new to the field of AI. From my data s... | The following may prove useful:
The University of Alberta Computer Poker Research Group
OpenHoldem
Poker Hand Recognition, Comparison, Enumeration, and Evaluation
The Theory of Poker
The Mathematics of Poker
SpecialKPokerEval
|
517,113 | 520,268 | Lisp grammar in yacc | I am trying to build a Lisp grammar. Easy, right? Apparently not.
I present these inputs and receive errors...
( 1 1)
23 23 23
ui ui
This is the grammar...
%%
sexpr: atom {printf("matched sexpr\n");}
| list
;
list: '(' members ')' {printf("matched list\n");}
| '('')' {... | The error is really in the lexer. Your parentheses end up as the last "." in the lexer, and don't show up as parentheses in the parser.
Add rules like
\) { return RPAREN; }
\( { return LPAREN; }
to the lexer and change all occurences of '(', ')' to LPAREN and RPAREN respectively in the parser. (also, you need ... |
522,222 | 522,344 | Functional Programming in C# vs LISP | What are the primary differences between LISP and C# with regards to functional programming? In specific, if a LISP programmer was to switch to using C#, what are the features they are most likely to miss?
| Doing functional programming in C# is technically possible (well, any language that has function pointers or delegates equivalent can be "functional") -- but C# gets very very painful if you try to do much.
Off the top of my head, in no particular order:
Type inference
Only exists for locals now
Should apply to pr... |
533,960 | 641,231 | How Do I Run Sutton and Barton's "Reinforcement Learning" Lisp Code? | I have been reading a lot about Reinforcement Learning lately, and I have found "Reinforcement Learning: An Introduction" to be an excellent guide. The author's helpfully provice source code for a lot of their worked examples.
Before I begin the question I should point out that my practical knowledge of lisp is minimal... | That code is for Macintosh Common Lisp (MCL). It will only run there. Using Clozure CL (CCL) will not help. You would have to comment the graphics code. The random state stuff also is slightly special for MCL. You have to port it to portable Common Lisp (make-random-state, etc.). Also the file names are special for the... |
535,277 | 535,284 | The Clojure (or Lisp) Equivalent of a Compound Boolean Test | In C++ I'd write something like this:
if (a == something && b == anotherthing)
{
foo();
}
Am I correct in thinking the Clojure equivalent is something like this:
(if (= a something)
(if (= b anotherthing)
(foo)))
Or is there another way to perform a logical "and" that I've missed? As I said the latter... | In Common Lisp and Scheme
(and (= a something) (= b another) (foo))
|
541,407 | 541,522 | Lisp Code Formatting | One of the people who took the time to comment on my other question about Clojure/LISP syntax pointed out that I had not written my sample code in the standard LISP way. So he was kind enough to rewrite the code snippet and that's a big help. But it raised another question in my mind. Why would this:
(if (= a someth... | The closing parentheses on extra lines don't really help with seeing the structure of the code, because you can get the same information from the level of indentation. However, the second form takes up almost twice as many lines, forcing you to scroll more often when reading code.
And if you need to inspect the nested ... |
543,579 | 543,661 | What is the most impressive Lisp application? | I know that this is subjective and all, but still, can you provide some list of serious applications that were written in Lisp (perhaps along with what Lisp it is)?
| ITA Software's airline-fare search service. See here to understand why this is impressive.
|
553,281 | 553,506 | What is wrong with the following Common Lisp macro using gensym? | Learning Common Lisp (using GNU CLISP 2.43) .. so might be a noob mistake. Example is the 'print prime numbers between x and y'
(defun is-prime (n)
(if (< n 2) (return-from is-prime NIL))
(do ((i 2 (1+ i)))
((= i n) T)
(if (= (mod n i) 0)
(return NIL))))
(defun next-prime-after (n)
(do ((i (... | Use DO* instead of DO.
DO Initializes the bindings in a scope where they are not yet visible. DO* initializes the bindings in a scope where they are visible.
In this particular case var needs to reference the other binding loop-start.
|
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 2