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 |
|---|---|---|---|---|
556,456 | 556,618 | Is it feasible to do (serious) web development in Lisp? | It obviously is possible to write almost any kind of application in almost any programming language, especially in such a powerful one as Lisp (be it Scheme or Common Lisp). But is it practical to use it for web development? If so, what should be a good starting point? Where can be found the proper resources (tools, li... | Yes, web development is one of Common Lisp's strengths today.
As a web server, use Hunchentoot, formerly known as tbnl, by Dr. Edmund Weitz.
You can run it as a back-end to Apache using mod_proxy as a reverse proxy, or as a stand-alone server.
Various HTML generation solutions are available, from PHP-style templates t... |
574,279 | 574,352 | How do the various ANSI CL implementations differ? | When I started learning CL from Practical Common Lisp, as is preached in the book, I started off with Allegro CL compiler. I stopped using it, since its commerical, yet free bit didn't impress me. It needed a connection to its remote server for some licensing stuffs.
I switched to 'clisp' and am using it. Now, I have b... | There are portions of ANSI CL that leave certain details up to the implementations to determine; you will find that for those parts of the standard, each implementation will have its own quirks.
Also, look for things that are important to the runtime but not defined in the language: things like threading and multiproce... |
578,290 | 578,350 | Common Lisp equivalent to C enums | I'm trying to learn some Lisp (Common Lisp) lately, and I wonder if there is a way to give constant numbers a name just like you can do in C via enums.
I don't need the full featureset of enums. In the end I just want to have fast and readable code.
I've tried globals and little functions, but that always came with a ... | The normal way to do enumerations in Lisp is to use symbols. Symbols get interned (replaced with pointers to their entries in a symbol table) so they are as fast as integers and as readable as enumerated constants in other languages.
So where in C you might write:
enum {
apple,
orange,
banana,
};
In Lisp yo... |
580,083 | 580,220 | How can ECL include ASDF dependencies in an executable? | I have this ecl-make.lisp:
(asdf:oos 'asdf:compile-op :stumpwm)
(defun system-objects (system)
(loop for component in (asdf:module-components (asdf:find-system system))
for pathname = (asdf:component-pathname component)
for directory = (pathname-directory pathname)
for name = (pathname-name pathname)
... | Oh, wow. Here's the answer:
Delete ecl-make.lisp , revert changes to stumpwm.asd
ecl -eval '(asdf:make-build :stumpwm :type :program)'
That's it. [ASDF doesn't see an asdf:build-op , however.]
EDIT: well, it also needs a prologue. ecl-examples now shows off asdf:make-build
|
581,182 | 581,194 | What are "downward funargs"? | Jamie Zawinski uses that term in his (1997) article "java sucks" as if you should know what it means:
I really hate the lack of downward-funargs; anonymous classes are a lame substitute. (I can live without long-lived closures, but I find lack of function pointers a huge pain.)
It seems to be Lisper's slang, and I co... | Downward funargs are local functions that are not returned or otherwise leave their declaration scope. They only can be passed downwards to other functions from the current scope.
Two examples. This is a downward funarg:
function () {
var a = 42;
var f = function () { return a + 1; }
foo(f); // `foo` is a f... |
595,556 | 596,619 | Porting Common Lisp code to Clojure | How practical is it to port a Common Lisp application to Clojure? To be more specific, what features exist in Common Lisp that do not exist in Clojure, and would have to be re-written?
| There's a list on clojure.org of differences between Clojure and other Lisps. Some other things I've noticed using Clojure:
Idiomatic Clojure leans heavily toward immutable data structures. Anywhere you see SETF in CL may have to be changed in Clojure to take full advantage. (You always have the option of using mut... |
604,808 | 605,242 | Option or Command key as Meta key for LispBox on Macintosh | I'm new to emacs and have just downloaded LispBox (from the Practical Common Lisp page) with SBCL to my Macintosh. I do know enough to realize I want either the option or Command key to be the meta key.
The emacs version delivered with LispBox doesn't pay attention to .emacs in my home directory.
Emacs as delivered wi... | Navigate to /Applications/Lispbox/Emacs.app/Contents/MacOS and edit lispbox.sh, removing the --no-init-file parameter. Then, inside ~/.emacs, add (setq mac-command-modifier 'meta)
|
605,785 | 606,273 | How do I get a list of Emacs lisp non-interactive functions? | How do I get a complete list of non-interactive functions that I can use in Emacs Lisp?
The interactive ones are easy enough to find in the help system, but I want a complete list of all the other functions I can use. For example concat, car, cdr, etc. (And preferably with documentation).
Thanks
Ed
Edit: Answered th... | Here's the basic idea - see the Emacs Lisp manual for any unclear concepts.
(flet ((first-line (text)
(if text
(substring text 0 (string-match "\n" text))
"")))
(mapatoms
(lambda (x)
(and (fboundp x) ; does x name a function?
(not (commandp ... |
605,846 | 605,868 | How do I access the contents of the current region in Emacs Lisp? | I want to access the contents of the current region as a string within a function. For example:
(concat "stringa" (get-region-as-string) "stringb")
Thanks
Ed
| buffer-substring together with region-beginning and region-end can do that.
|
606,533 | 606,585 | How do I get my brain moving in "lisp mode?" | My professor told us that we could choose a programming language for our next programming assignment. I've been meaning to try out a functional language, so I figured I'd try out clojure. The problem is that I understand the syntax and understand the basic concepts, but I'm having problems getting everything to "clic... | It's a little like riding a bike, it just takes practice. Try solving some problems with it, maybe ProjectEuler and eventually it'll click.
Someone mentioned the book "The Little Schemer" and this is a pretty good read. Although it targets Scheme the actual problems will be worth working through.
Good luck!
|
610,680 | 610,770 | Linearly recursive list-difference function in Common Lisp | I was going through this tutorial for fun, and got stuck on the very last thing he says, "Exercise: Give a linearly recursive implementation of union and difference." (for a list)
Union, no sweat.
Difference, sweat.
An attempt looks like this. . .
(defun list-diff (L1 L2)
(cond
((null L1) L2)
((null (membe... | The set difference operation L1 \ L2 is defined as all elements e such that e is in L1 but e not in L2. So it looks to me like your second attempt is actually correct:
Similarly, if I change the L2 in line
3 to "nil", then it just returns all
of L1 that aren't in L2, but none of
L2.
It looks like you're trying... |
622,785 | 622,803 | let vs def in clojure | I want to make a local instance of a Java Scanner class in a clojure program. Why does this not work:
; gives me: count not supported on this type: Symbol
(let s (new Scanner "a b c"))
but it will let me create a global instance like this:
(def s (new Scanner "a b c"))
I was under the impression that the only diff... | The problem is that your use of let is wrong.
let works like this:
(let [identifier (expr)])
So your example should be something like this:
(let [s (Scanner. "a b c")]
(exprs))
You can only use the lexical bindings made with let within the scope of let (the opening and closing parens). Let just creates a set of lex... |
629,699 | 629,745 | Common Lisp: Working with &rest parameters | Can anyone tell me how to work with the parameters stored in the value specified by &rest.
I've read around a lot and it seems as if authors only know how to list all the parameters as so.
(defun test (a &rest b) b)
This is nice to see, but not really that useful.
The best I've found so far is to use first, second, an... | The FIRST, SECOND and so on accessor functions are "just" utility functions on top of CAR/CDR or NTH. SO, I guess, the answer to your specific question is "use NTH or ELT" (or build your own specific acccessor functions).
If you want, you can define an ELEVENTH as:
(defun eleventh (list)
(nth 10 list))
I find, howe... |
652,901 | 653,000 | Lisp evaluation of let statements | I am writing a Scheme interpreter, and I am faced with a valid let statement such as:
;; should print 7
(let ((a 4) (b 3))
(let ((a (* a a))
(b (* b b)))
(+ a b)
(- a b)))
My interpreter implements only a purely functional subset of Scheme, so there will be no side effects such as set!. In... | You're right (almost): if you're implementing a purely functional subset of Scheme (i.e. no set!, set-car!, set-cdr!) then any expression but the last in a let will have their return value thrown away, and since you're guaranteed not to have side effects, there's no danger in silently ignoring them.
However, there is o... |
661,490 | 661,532 | elisp functions as parameters and as return value | I have the following code
(defun avg-damp(f)
#'(lambda(x) (/ (+ (funcall f x) x) 2.0)))
A call
(funcall (avg-damp #'(lambda(v) (* v v))) 10)
returns 55.0 (the correct value) in SBCL but crashes with the following stack in emacs lisp
Debugger entered--Lisp error: (void-variable f)
(funcall f x)
(+ (funcall ... | A tricky question, but finally got this figured out. The problem is that #' in the definition of avg-damp makes the compiler compile the lambda function at the time when avg-damp itself is compiled, before the actual value of f is known. You need to delay the compilation of this function to a later point in time, whe... |
664,288 | 664,308 | How can I tell if a list has a third item? | I have a function that takes a list that either has two or three elements.
;; expecting either ((a b c) d) or ((a b c) d e)
(define (has-third-item ls)
(if (null? (caddr ls))
false
true)
)
But this code fails with
mcar: expects argument of type <mutable-pair>; given ()
on the (null? (... | You don't want caddr, you want (if (null? (cddr ls)) ... Or just use length to find the length of the list, and compare it to the value you're interested in.
The '() that terminates a list will always be in the cdr position of a pair, so looking for it in the car position (which cad+r will do) isn't going to be product... |
664,373 | 665,177 | Can you return nothing from a function in Scheme? | I'm writing a scheme interpreter, and in the case of an if statement such as:
(if (< 1 0) 'true)
Any interpreter I've tried just returns a new prompt. But when I coded this, I had an if for whether there was an alternative expression. What can I return in the if such that nothing gets printed?
(if (has-alternative if-... | According to the R6RS specification:
If <test> yields #f and no <alternate>
is specified, then the result of the
expression is unspecified.
So go wild, return anything you want! Although #f or '() are what I, personally, would expect.
|
671,706 | 671,779 | How do I make a Java class immutable in Clojure? | I'd like to wrap java's PriorityQueue class in clojure for use in another part of my program. What I'm trying to figure out is if there is any way to do this in a lispy manner and make the priority queue immutable. Are there any good ways to do this, or am I just going to be better off using the PriorityQueue as a mu... | I don't think there is a simple way to wrap a mutable data structure as an immutable one. Immutable data structures become efficient when the new version can share data with the old version in clever ways, and I can't really see how this can be done without access to the internals of PriorityQueue.
If you really want a... |
694,669 | 694,790 | What is the Scheme function to find an element in a list? | I have a list of elements '(a b c) and I want to find if (true or false) x is in it, where x can be 'a or 'd, for instance. Is there a built in function for this?
| If you need to compare using one of the build in equivalence operators, you can use memq, memv, or member, depending on whether you want to look for equality using eq?, eqv?, or equal?, respectively.
> (memq 'a '(a b c))
'(a b c)
> (memq 'b '(a b c))
'(b c)
> (memq 'x '(a b c))
#f
As you can see, these functions retur... |
708,861 | 709,068 | Coping with, and minimizing, memory usage in Common Lisp (SBCL) | I have a VPS with not very much memory (256Mb) which I am trying to use for Common Lisp development with SBCL+Hunchentoot to write some simple web-apps. A large amount of memory appears to be getting used without doing anything particularly complex, and after a while of serving pages it runs out of memory and either g... | To limit the memory usage of SBCL, use --dynamic-space-size option (e.g.,sbcl --dynamic-space-size 128 will limit memory usage to 128M).
To find out who is using memory, you may call (room) (the function that tells how much memory is being used) at different times: at startup, after all libraries are loaded and then du... |
712,905 | 712,983 | Loading libraries in Dr Scheme | I am working through SICP using Dr Scheme.
How do I load external libraries in Dr Scheme? Say I want to use Math library then how do I ask Dr Scheme to load the particular library?
I tried with the following:
(require (lib "math.ss"))
Got the following error:
reference to undefined identifier: require
I have chosen R5R... | Change the language to Pretty Big. 'require' is not an R5RS feature.
|
717,177 | 717,208 | How can I apply a new Emacs C style to reformat all my source files? | I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here).
How can I apply this function to all my source files at once, so that they are all formatted and indented correctly according to the Google style?
| There are several pieces to this:
you need to come up with EMACS functions to do all the reformatting you want. indent-region is a start, but you might also want to untabify or some other things.
you need to invoke them on each file, and since the indent functions work on ranges, you need a function that sets mark to... |
717,963 | 718,022 | Clojure keyword arguments | In Common Lisp you can do this:
(defun foo (bar &key baz quux)
(list bar baz quux))
(foo 1 :quux 3 :baz 2) ; => (1 2 3)
Clojure doesn't have keyword arguments. One alternative is this:
(defn foo [bar {:keys [baz quux]}]
(list bar baz quux))
(foo 1 {:quux 3 :baz 2}) ; => (1 2 3)
That's too many nested brackets... | A simple way to simulate keyword args in clojure is using hash-map on rest parameters like this:
> (defn kwtest [x & e] (:foo (apply hash-map e)))
#'user/kwtest
> (kwtest 12 :bar "ignored" :foo "returned")
"returned"
Rich Hickey provided a macro in this message from the clojure google group that gives you keyword para... |
719,130 | 720,286 | Is it possible to deploy a Common Lisp (or other dialect) desktop application for several platforms? | I would like to develop a graphical application in Common Lisp or other Lisp dialect that could be deployed in Mac, Windows and Linux as a way of improving my knowledge of this language. Ideally:
would compile the code
would use a common graphical library
wouldn't need installation of the runtime environment.
I would... | I'm one of the developers of lispbuilder-sdl which is currently hosted on google code.
alt text http://img10.imageshack.us/img10/7664/mandelbrot.jpg
http://code.google.com/p/lispbuilder/
This gives you a way of running common lisp programs on linux, windows and mac machines without modification. We use the SDL library ... |
742,154 | 742,293 | Class introspection in Common Lisp | Java's java.lang.Class class has a getDeclaredFields method which will return all the fields in a given class. Is there something similar for Common Lisp? I came across some helpful functions such as describe, inspect and symbol-plist after reading trying out the instructions in Successful Lisp, Chapter 10 (http://www.... | You should use class-slots and/or class-direct-slots (both are from CLOS Metaobject Protocol, MOP). class-slots returns all slots that are present in given class, and class-direct-slots returns all slots are declared in class definition.
Different lisp implementations implement MOP slightly differently; use closer-mop ... |
742,482 | 742,582 | Windows Scheme/Lisp Implementation | With the thousands of implementations of LISP and Scheme available I'm having a very hard time finding just the right one to use for Windows development. I learned these languages in school and found them to be very elegant, however, I don't seem to be able to find an implementation that would be suitable for developi... | Corman Lisp could be interesting, but does not support 64bit code (AFAIK).
Clozure CL is just being ported to Windows, so it is probably not very mature and lacks a few things.
LispWorks and Allegro CL are great, though they don't support multiple concurrent Lisp threads. Currently LispWorks 6 is under development, whi... |
753,459 | 754,882 | Emacs: getting readable keyboard-macros | When using insert-kbd-macro to save a named keyboard macro I get "unreadable" Lisp code like
(fset 'ppsql
(lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([134217788 134217765 44 return 44 17 10 return 33 134217765 102 102 backspace 114 111 109 return 17 10 102 111 109 backs... | The keyboard macro functionality in Emacs stands of two modes: macros and kmacros. The former returns the macro in a way you like—the symbol form—, the latter provides the lambda form. So that, if you call name-last-kbd-macro you get a symbol form, if you call kmacro-name-last-macro, you get a lambda form.
|
756,090 | 756,956 | Ant (or NAnt) in Lisp | In his article The Nature of Lisp, Slava Akhmechet introduces people to lisp by using Ant/NAnt as an example. Is there an implementation of Ant/NAnt in lisp? Where you can use actual lisp code, instead of xml, for defining things? I've had to deal with creating additions to NAnt, and have wished for a way to bypass t... | Ant is a program that interprets commands written in some XML language. You can, as justinhj mentioned in his answer use some XML parser (like the mentioned XMLisp) and convert the XML description in some kind of Lisp data and then write additional code in Lisp. You need to reimplement also some of the Ant interpretati... |
757,564 | 757,593 | In Emacs Lisp, how do I check if a variable is defined? | In Emacs Lisp, how do I check if a variable is defined?
| you may want boundp: returns t if variable (a symbol) is not void; more precisely, if its current binding is not void. It returns nil otherwise.
(boundp 'abracadabra) ; Starts out void.
=> nil
(let ((abracadabra 5)) ; Locally bind it.
(boundp 'abracadabra))
=> t
(boundp 'abracadabra) ... |
764,412 | 764,906 | Python Macros: Use Cases? | If Python had a macro facility similar to Lisp/Scheme (something like MetaPython), how would you use it?
If you are a Lisp/Scheme programmer, what sorts of things do you use macros for (other than things that have a clear syntactic parallel in Python such as a while loop)?
| Some examples of lisp macros:
ITERATE which is a funny and extensible loop facility
CL-YACC/FUCC that are parser generators that generate parsers at compile time
CL-WHO which allows specifying html documents with static and dynamic parts
Parenscript which is a javascript code generator
Various simple code-wrappers, e.... |
765,484 | 765,557 | How to write a scheme function that takes two lists and returns four lists | I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How?
I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a member to the new list.
(define (checkResult lis1 lis2)
(cond......... | Like others have said, all you need to do is create separate functions to compute the intersection, union, and subtraction of the two sets, and call them from checkresult:
(define (checkresult a b)
(list (subtract a b)
(subtract b a)
(union a b)
(intersect a b)))
Here are some example union, ... |
787,145 | 787,229 | Does anyone have an Emacs macro for indenting (and unindenting) blocks of text? | Does anyone have an Emacs macro for indenting (and unindenting) blocks of text?
And I mean "indent" in the commonly-understood sense, not in Emacspeak. In other words, I want to mark a region, press C-u 2, run this macro, and have it add two spaces before every line in the region.
Or press C-u -2 before running the mac... | indent-rigidly (bound to C-x TAB) does what you want. It's in indent.el, which should be part of the standard emacs distribution.
Also, to have it complain/abort when there's not enough whitespace somewhere, you can do something like this: (quick ugly hack of the original indent-rigidly code)
(defun enough-whitespace... |
790,976 | 791,010 | How to set up MIT Scheme for 6.001 in Ubuntu 8.10 | I play to self-study 6.001 with the video lectures and lecture handouts. However, I have some problems setting up MIT Scheme in Ubuntu (intrepid).
I used package management and installed MIT-Scheme, but it's obviously the wrong version to use. It should be 7.5.1 instead of 7.7.90
I followed the instructions from this w... | Step 3 means that you should type export MITSCHEME_6001_DIRECTORY=${your_problems_path}. If you don't want to type it every time you launch Scheme, you should put it as a string in your ~/.bash_profile file(in case you use bash)
About the problem itself, Google instantly suggests a solution:
sudo sysctl -w vm.mmap_min_... |
791,812 | 791,874 | Unable to add a directory and all its subdirectories to load-path in Emacs | The question is similar to one.
However, it differs in putting all subdirectories achievable in the folder too.
Jouni's code which puts first level folders achievable
(let ((base "~/Projects/emacs"))
(add-to-list 'load-path base)
(dolist (f (directory-files base))
(let ((name (concat base "/" f)))
(when ... | My answer in the other question does handle multiple levels of subdirectories.
The code for reference
(let* ((my-lisp-dir "~/.elisp/")
(default-directory my-lisp-dir)
(orig-load-path load-path))
(setq load-path (cons my-lisp-dir nil))
(normal-top-level-add-subdirs-to-load-path)
(nconc load-path orig... |
890,689 | 891,842 | Drawing trees in Common Lisp | This question probably has an embarrassingly simple answer, but is there a Right Way to format/draw trees in Common Lisp? I've tried a few books as well as googling about, but the problem seems to fall between the cracks of the search terms.
Thanks in advance!
| What kind of trees do you want to draw?
SDRAW draws cons cell structures to a terminal. Similar: Draw Cons Tree.
If you have McCLIM, CLIM or a Lisp Machine, you can call the CLIM function CLIM:FORMAT-GRAPH-FROM-ROOT or CLIM:FORMAT-GRAPH-FROM-ROOTS.
If you use LispWorks, there is a graph pane.
If you want to draw plants... |
898,287 | 898,375 | How can I spot subtle Lisp syntax mistakes? | I'm a newbie playing around with Lisp (actually, Emacs Lisp). It's a lot of fun, except when I seem to run into the same syntax mistakes again and again.
For instance, here's something I've encountered several times. I have some cond form, like
(cond
((foo bar)
(qux quux))
((or corge
(grault warg))
(fred)
... | Highlight sexps
First of all, turn on the builtin paren match highlighting (show-paren-mode) if not already did so. It always gives you an idea what indentation level you are in.
There are also some more sophisticated packages. For example, see TJ's answer on mic-paren. Or though I didn't find it suitable for me, but t... |
908,427 | 908,491 | Why use #' with lambda? | Why should I use #' together with lambda? It is usually written that way, so I guess it is good form. But these lines seem equal to me:
> (mapcar #'(lambda (x) (+ x 1)) '(1 2 3))
(2 3 4)
> (mapcar (lambda (x) (+ x 1)) '(1 2 3))
(2 3 4)
Anyone care to enlighten a beginner about the difference?
| #' is shorthand for function, which returns a pointer to a function (instead of applying it). lambda returns a function, and it's usual to want a pointer to that function. Since this is so common, there is also a macro (in variable space) that does it for you, which is called lambda as well. Both lines of code are i... |
916,978 | 917,028 | Python equivalent of maplist? | What's the best Python equivalent of Common Lisp's maplist function? From the maplist documentation:
maplist is like mapcar except that
function is applied to successive
sublists of the lists. function is
first applied to the lists themselves,
and then to the cdr of each list, and
then to the cdr of the cdr... | You can write a little function for that
def maplist(func, values):
return [map(func, values[i:]) for i in xrange(len(values))]
>>> maplist(lambda a: a* 2, [1,2,3])
[[2, 4, 6], [4, 6], [6]]
[Edit]
if you want to apply the function on the sublists you can change the function to this:
def maplist(func, values):
... |
919,855 | 919,865 | What program can help a REPL shell remember and search history? | I'm playing with Paul Graham's arc, and it's getting really annoying that the up arrow inserts ^[[A instead of the previous command, and ^R doesn't work as in shell. I vaguely remember there being a simple way to run Arc's REPL in a program which will remember the input history - does anyone know what it is?
| Perhaps you're thinking of rlwrap?
|
928,163 | 930,566 | AllegroServe on SBCL 1.0.28 failing with `accept invalid keyword argument: :AUTO-CLOSE` | New version of SBCL 1.0.28 running on debian breaks AllegroServe 1.2.47 on incoming connection with following error:
aserve-accept-6: 05/26/09 - 21:11:01 - accept: error 0 on accept invalid
keyword argument: :AUTO-CLOSE (valid keys are
:INPUT, :OUTPUT, :ELEMENT-TYPE, ... | After some mucking around, I've come up with the following solution:
In my source files, after I declare my package, compile/load the appropriate modules but before I declare anything in my package, I added the following code:
(defmethod sb-bsd-sockets:socket-make-stream ((socket sb-bsd-sockets:socket)
... |
933,667 | 933,692 | Designing SQL alternative? | I'm thinking of designing & implementing my own SQL-equivalent (DDL+DML) that is...
a pure relational algebraic language, and
has an elegant Lisp-/Scheme-like syntax
Assuming an RDBMS such as MySQL, where exactly would I need to start my language design work? On top of the storage engine layer such as InnoDB?
I don't... | I suspect that the best way to go around this would be to create a translator between your language and SQL, mainly because you won't be able to get more functionality from a rdbms than what's provided via its SQL dialect.
MySQL existence has nothing to do with the difficulty of the work done by storage engines, storag... |
954,247 | 954,330 | Learn Macros in Scheme from On Lisp | I really want to learn Scheme macros. I glanced over the content of "On Lisp" and a lot of the chapters have been devoted to Lisp macros. However I do not know common lisp. Can I use it to learn Scheme Macros?
| Scheme macros ("hygienic macros") are completely different from traditional Lisp macros. Some implementations of Scheme offer Lisp macros in addition to Scheme macros, but this is not required by the Scheme standard.
I would recommend you look for instructional materials specific to Scheme macros if you would like to l... |
962,101 | 962,153 | how do I get CLSQL to look for mysql.h in non-standard directory? | in the error log:
CLSQL is doing:
gcc -I /usr/local/include/mysql -I /usr/include/mysql -I /sw/include/mysql -I /opt/local/include/mysql -I /usr/local/mysql/include -fPIC -c clsql_mysql.c -o clsql_mysql.o
and gets error:
clsql_mysql.c:34:19: mysql.h: No such file or directory
and a bunch of C errors because it doesn't... |
check that file exists and no permissions problem by inserting #include with full name at the beginning of clsql_mysql.c file:
#include "/usr/local/mysql/include/mysql/mysql.h"
if compiles well - undo changes and resolve path provided by -I parameter
if doesn't compile and says "file does'nt exist" - check that file e... |
971,734 | 971,845 | Lisp style: setq vs. setf | Peter Norvig mentions in Paradigms of Artificial Intelligence Programming, on page 50, the trade off between specificity and consistency and when choosing to use setq or setf to update a variable to a value. What do you recommend? Have you ever run into a situation where it mattered much beyond readability?
| Using setq is more low-level, but the performance of setf is not a problem. And setf allows you (or library writers) to provide custom setf behavior, like setting parts of custom data structures. I say: go with setf everywhere unless you have a reason not to.
Also see Practical Common Lisp, chapter 3: "The SETF macro i... |
973,106 | 974,286 | What is the clojure equivalent of the Python idiom "if __name__ == '__main__'"? | I'm dabbling in clojure and am having a little trouble trying to determine the clojure (and / or Lisp) equivalent of this common python idiom.
The idiom is that at the bottom of a python module there is often a bit of test code, and then a statement which runs the code, for example:
# mymodule.py
class MyClass(object):... | It's not idiomatic to run Clojure scripts over and over from the command line. The REPL is a better command line. Clojure being a Lisp, it's common to fire up Clojure and leave the same instance running forever, and interact with it rather than restart it. You can change functions in the running instance one at a ti... |
989,374 | 989,482 | Help me write a Clojure macro which automatically adds metadata to a function definition | I realize that the first rule of Macro Club is Don't Use Macros, so the following question is intended more as an exercise in learning Clojure than anything else (I realize this isn't necessarily the best use of macros).
I want to write a simple macro which acts as a wrapper around a regular (defn) macro and winds up a... | Updated:
The previous version of my answer was not very robust. This seems like a simpler and more proper way of doing it, stolen from clojure.contrib.def:
(defmacro defn-plus [name & syms]
`(defn ~(vary-meta name assoc :some-key :some-value) ~@syms))
user> (defn-plus ^Integer f "Docstring goes here" [x] (inc x))
#... |
1,002,091 | 1,002,172 | How to force Emacs not to display buffer in a specific window? | My windows configuration looks like this:
+----------+-----------+
| | |
| | |
| | |
| | |
| | |
| +-----------+
| | |
+----------+--------... | Well, someone already asked the same question for completion. And I wrote up an answer that seemed to work pretty well.
It looks like you could use that same solution, except instead of adding to special-display-buffer-names, you can use the variable special-display-regexps. So something along the lines of:
(add-to-l... |
1,020,968 | 1,020,997 | Separate Namespaces for Functions and Variables in Common Lisp versus Scheme | Scheme uses a single namespace for all variables, regardless of whether they are bound to functions or other types of values. Common Lisp separates the two, such that the identifier "hello" may refer to a function in one context, and a string in another.
(Note 1: This question needs an example of the above; feel free t... | The two different approaches have names: Lisp-1 and Lisp-2. A Lisp-1 has a single namespace for both variables and functions (as in Scheme) while a Lisp-2 has separate namespaces for variables and functions (as in Common Lisp). I mention this because you may not be aware of the terminology since you didn't refer to it ... |
1,021,523 | 1,021,749 | Emacs Lisp: make newly-created buffer visible before the function returns? | In the following function in emacs Lisp,
(defun show-life ()
(interactive)
(switch-to-buffer "*Life-Window*") ; show how life goes on while living
(live)) ; it takes 70 years to finish and return!
I'd like to create the buffer "Life-Window", and have the life event generated by (live) displayed continuously whi... | Add a call to 'sit-for just before the call to 'live, e.g.
(defun show-life ()
(interactive)
(switch-to-buffer "*Life-Window*") ; show how life goes on while living
(sit-for 0) ; perform redisplay
(live)) ; it takes 70 years to finish and return!
And, ... |
1,021,778 | 1,021,918 | Getting command line arguments in Common Lisp | How can I get the command line arguments in (specifically in GNU, if there are any differences) Common Lisp?
| I'm assuming that you are scripting with CLisp. You can create a file containing
#! /usr/local/bin/clisp
(format t "~&~S~&" *args*)
Make it executable by running
$ chmod 755 <filename>
Running it gives
$ ./<filename>
NIL
$ ./<filename> a b c
("a" "b" "c")
$ ./<filename> "a b c" 1 2 3
("a b c" "1" "2" "3")
|
1,033,468 | 1,465,584 | padding binary-block lazy sequences | I have Clojure function that takes a sequence of numbers chops it into the appropriate number of bits and returns a lazy sequence of the chunks (lowest order bits first). It pads the high order bits of the last block to fill out the block size and I need advice on the "best way(tm)" to record the amount of padding whil... | It's still not quite clear what you want to do, but it seems that you want to know the best way for block-seq to return the number of padded bits in the last chunk. Of course that's not possible up front if you want to be properly lazy, so the number would have to be returned with or after the last chunk.
Without usin... |
1,033,552 | 1,034,567 | How is Lisp related to F#, and is learning Lisp a useful leg up to F#? | This is the situation : I mostly program C# and have written types in it I don't want to lose. At the same time I would like to learn functional programming. The obvious answer of course is F#.
But for everything apart from C# I use emacs as an editor, and I really would like to learn Lisp too. (Learn your editors... | Lisp is a large family of languages and implementations. Scheme for example is a Lisp dialect with probably more than one hundred implementations (about ten of them mildly popular). Common Lisp is another dialect with about ten currently maintained implementations. Scheme and Common Lisp both have written standards th... |
1,035,320 | 1,035,341 | What is the time complexity of 'assoc' function in scheme? | What is the time complexity of this nifty function 'assoc'?
| I would assume that assoc is O(n)*, assuming that equal? is O(1) in your usage of the function. This is because it's trivial to write your own version of assoc:
(define (my-assoc v lst)
(cond ((null? lst) #f)
((equal? v (caar lst)) (car lst))
(else (my-assoc v (cdr lst)))))
You can see this simply sl... |
1,037,545 | 1,037,749 | How to replace forward slashes with backslashes in a string in Emacs Lisp? | I would like to replace forward slaches to backslashes in emacs lisp.
If I use this :
(replace-regexp-in-string "\/" "\\" path))
I get an error.
(error "Invalid use of `\\' in replacement text")
So how to represent the backslash in the second regexp?
| What you are seeing in "C:\\foo\\bar" is the textual representation of the string "C:\foo\bar", with escaped backslashes for further processing.
For example, if you make a string of length 1 with the backslash character:
(make-string 1 ?\\)
you get the following response (e.g. in the minibuffer, when you evaluate the ... |
1,041,603 | 1,048,403 | How do I write Push and Pop in Scheme? | Right now I have
(define (push x a-list)
(set! a-list (cons a-list x)))
(define (pop a-list)
(let ((result (first a-list)))
(set! a-list (rest a-list))
result))
But I get this result:
Welcome to DrScheme, version 4.2 [3m].
Language: Module; memory limit: 256 megabytes.
> (define my-list (list 1 2 3))
> (... | This is a point about using mutation in your code: there is no need to jump to macros for that. I'll assume the stack operations for now: to get a simple value that you can pass around and mutate, all you need is a wrapper around the list and the rest of your code stays the same (well, with the minor change that makes... |
1,041,671 | 1,041,748 | How do you compare two strings and ignore the case in Scheme? | I want to write a function like equalp, which gives #t for (equalp "Xy" "xY").
| Use (string-ci=? "Xy" "xY")
Reference
|
1,045,069 | 1,045,093 | How do I apply a symbol as a function in Scheme? | Is there a way I can apply '+ to '( 1 2 3)?
edit: what i am trying to say is that the function i get will be a symbol. Is there a way to apply that?
Thanks.
| (apply (eval '+) '(1 2 3))
Should do it.
|
1,045,076 | 1,045,274 | Position Independent Parameters to Scheme Functions | How do I pass position-independent parameters to scheme functions?
| In PLT Scheme you can use:
(define area
(lambda (x #:width y)
(* x y)))
(area 3 #:width 10)
or
(area #:width 10 3)
both would return 30.
|
1,050,602 | 1,050,962 | Unable to understand a line of Emacs Lisp | The line is
function info() {
emacs -eval "(progn (setq Man-notify-method 'bully) (info \"$1\"))"
}
I know from manuals that
Progn
progn is a special form in `C source
code'.
Setq
setq is a special form in `C source
code'. (setq SYM VAL SYM VAL ...)
Set each SYM to the value of its VAL.
The symbols SYM... | PROGN simply evaluates the expressions in order, returning the return value of the last one.
SETQ is the basic assignment operator.
INFO enters the emacs info browser.
So, what this does is first assign the symbol 'bully to the variable Man-notify-method, then enter the info browser. 'bully is likely the name of a fun... |
1,053,312 | 1,054,163 | Pattern Matching in Scheme | How do I accept the following input?
(list of 0 or more charcters and ends with 3) or
(list of 1 or more characters 4 and 0 or more characters after 4)
something like
(match ( list 3)) -> #t
(match ( list 1 2 3)) -> #t
(match (list 1 2 3 4)) -> #t
(match (list 1 2 3 4 5)) -> #t
(match (list 4)) -> #f
EDIT: TH... | You mention characters, but then use numbers in your example. I'm using numbers here, but switching to characters is trivial.
(require scheme/match)
(define satisfies
(match-lambda
[(list (? number?) ... 3) #t]
[(list (? number?) ..1 4 (? number?) ...) #t]
[_ #f]))
|
1,054,170 | 7,298,395 | Clojure Variables and Looping | From googling around, I found that using while loops or using variables is discouraged.
Now I implemented a very simple algorithm that will read characters from an inputstream and parse accordingly: if input is 10:abcdefghej it will parse out 10 then read next 10 bytes after the colon.
The thing I am kinda lost with is... | A bit late to this party, I suppose, but the problem is much simpler if you just treat the string as a sequence of characters and use Clojure's sequence-handling primitives:
(defn read-prefixed-string [stream]
(let [s (repeatedly #(char (.read stream)))
[before [colon & after]] (split-with (complement #{\:}) ... |
1,055,475 | 1,055,493 | A good source for lisp libraries? | Is there a PEAR kind library for lisp? I hope there is, but I read somewhere that one of the disadvantages of lisp is its lack of serious libraries. I find that hard to believe since lisp is half a century old now.
| The Common Lisp Wiki is a good place to start.
|
1,055,693 | 1,055,765 | Clojure loop reads one extra | When length is 4 following loop executes 5 times. Reading 5 characters from the stream.
(loop [i (.read stream) result "" counter length]
(let [c (char i)]
(println "=>" c)
(if (zero? counter)
result
(recur (.read stream) (str result c) (dec counter)))))
| You should test for zero? before you do the read. Note that your version will call read once even if length == 0 to begin with.
(loop [result "" counter length]
(if (zero? counter)
result
(let [c (char (.read stream))]
(println "=>" c )
(recur (str result c) (dec counter)))))
Another way which a... |
1,056,061 | 1,056,268 | adding metadata to a lazy sequence | When I try to add metadata to an infinite lazy sequence in Clojure, I get a stack overflow, and if I take off the metadata, then it works just fine. Why does adding the with-meta macro break the lazy seq?
First create an infinite seq of a very nice number:
(defn good []
(lazy-seq
(cons 42
(good))))
user>... | Because a LazySeq evaluates its body as soon as you call withMeta on the LazySeq. You lose your laziness.
public final class LazySeq extends Obj implements ISeq, List{
...
public Obj withMeta(IPersistentMap meta){
return new LazySeq(meta, seq());
}
...
}
seq() evaluates the lazy seq's body if ... |
1,059,372 | 1,059,393 | C++ code and objects from C? | Is there a simple way to work with C++ objects directly from C?
I want to expose some classes from C++ to C or to FFI(foreign function interface).
Sure, I can write a stuff like that:
class Foo{
....
};
void *make_foo(...){
Foo *ptr = new Foo(..)
return static_cast<void *>(ptr);
}
..
int *foo_method1(void *fooptr, ... | That, in general, is the simplest method.
Remember, too, that you'll need to use extern "C" on all of your C "wrapper" methods, as well.
|
1,089,574 | 1,089,767 | Why must 'require' be evaluated in a separate expression to use of the package | I have some lisp initialisation code:
(eval-when (:compile-toplevel :load-toplevel :execute)
(require 'asdf))
(eval-when (:compile-toplevel :load-toplevel :execute)
(push #p"c\:\\lisp\\clsql-4.0.4\\" asdf:*central-registry*))
Why does that version compile, while this version:
(eval-when (:compile-toplevel :load-t... | The following may be inaccurate in some details, but it is approximately like this:
There are four phases that the Lisp "engine" goes through: read time, macro expansion time, compile time, and run time.
Each top-level form is first read in completely. Reading, however, involves resolution of the respective symbols. ... |
1,091,751 | 1,091,944 | What is your recommended Emacs Lisp? | As for me, what I use is as follows recently
yasnippets -- http://code.google.com/p/yasnippet/
If there is a good code, Could you introduce it for me?
|
Obviously org-mode and remember-mode.
Highlight-parentheses
|
1,095,760 | 1,096,006 | Can I disassemble my code in PLTScheme? | Can I see the translated machine instruction of a scheme function like (disassemble) in LISP?
| There is a decompile module providing a function by the same name. It can be used to decompile a bytecode file into a kind of a human-readable form. However, this is not a linear assembly-language representation (that is what gets generated dynamically by the JIT), and it's questionable whether it will help you to lo... |
1,099,509 | 1,104,287 | How can I reuse a gethash lookup in Common Lisp? | I have a hash table where the keys are rather complex lists, with sublists of symbols and integers, and the value should be modified depending on the already existing value. The table is created with :test #'equal.
I do something similar to this a lot:
(defun try-add (i)
(let ((old-i (gethash complex-list table nil))... | Don't do anything special, because the implementation does it for you.
Of course, this approach is implementation-specific, and hash table performance varies between implementations. (But then optimization questions are always implementation-specific.)
The following answer is for SBCL. I recommend checking whether yo... |
1,105,522 | 1,105,539 | How do I 'get' Lisp? | I've read The Nature of Lisp. The only thing I really got out of that was "code is data." But without defining what these terms mean and why they are usually thought to be separate, I gain no insight. My initial reaction to "code is data" is, so what?
| Write Lisp code. The only way to really 'get' Lisp (or any language, for that matter) is to roll up your sleeves and implement some things in it. Like anything else, you can read all you want, but if you want to really get a firm grasp on what's going on, you've got to step outside the theoretical and start working w... |
1,109,643 | 1,113,063 | Newbie question about Lisp and Packages | Here is the back story skip to the bottom if you do not care and only want to see the question.
So I have been playing around in LISP for a little while. Some basic functions, some classes ,and file IO. When I run across this article:
http://www.adampetersen.se/articles/lispweb.htm
And I am excited to try and use lisp... |
Hmm... ok, well the hunchentoot site
says a lot of the basic packages are
in LispWorks. So I download that.
This just means that the author has written a lot of Lispworks-specific code in Hunchentoot. It does not mean that Hunchentoot only works on Lispworks.
Still not sure how to get the source for the packages... |
1,112,197 | 1,112,577 | Clojure/Java Mandelbrot Fractal drawing | I am trying to port this algorithm to clojure.
My code is
(defn calc-iterations [x y]
(let [c (struct complex x y)]
(loop [z (struct complex 0 0)
iterations 0]
(if (and (< 2.0 (abs z))
(> max-iterations iterations))
iterations
(recur (add c (multiply z z)) (inc it... | I've spotted two differences.
The Java implementation starts at z = (x, y) rather than yours which starts at (0, 0). As your recursive formula is z = z^2 + c, (0, 0)^2 + (x, y) = (x, y) so starting at (x, y) is the same as doing the first iteration. So the number of iterations will come out one less than yours because... |
1,114,646 | 1,116,589 | How to add up the elements for a structure in Scheme/Lisp | I have an input which is of this form:
(((lady-in-water . 1.25)
(snake . 1.75)
(run . 2.25)
(just-my-luck . 1.5))
((lady-in-water . 0.8235294117647058)
(snake . 0.5882352941176471)
(just-my-luck . 0.8235294117647058))
((lady-in-water . 0.8888888888888888)
(snake . 1.5555555555555554)
(just-my-luck . 1.3... | To avoid the wrong impression that CL is superior in any way, here is a PLT Scheme solution using the hash table approach. I've added a sort of the results for extra credit.
(define (data->movies data)
(define t (make-hasheq))
(for* ([x (in-list data)] [x (in-list x)])
(hash-set! t (car x) (+ (cdr x) (hash-ref... |
1,116,471 | 1,116,528 | How do I make a module in PLT Scheme? | I tried doing this:
#lang scheme
(module duck scheme/base
(provide num-eggs quack)
(define num-eggs 2)
(define (quack n)
(unless (zero? n)
(printf "quack\n")
(quack (sub1 n)))))
But I get this error:
module: illegal use (not at top-level) in:
(module duck scheme/base (pro... | You should remove the (module duck scheme/base line (and the closing paren).
When you start your code with #lang scheme, it's effectively putting your code in a module that uses the scheme language. You can also use #lang scheme/base if you want the smaller language instead.
(To really get convinced, do this:
(paramet... |
1,126,201 | 1,126,992 | How do you perform arithmetic calculations on symbols in Scheme/Lisp? | I need to perform calculations with a symbol. I need to convert the time which is of hh:mm form to the minutes passed.
;; (get-minutes symbol)->number
;; convert the time in hh:mm to minutes
;; (get-minutes 6:19)-> 6* 60 + 19
(define (get-minutes time)
(let* ((a-time (string->list (symbol->string time)))
(h... | You can find a definition for string-split here. It will enable you to split a string at delimiters of your choice. Then you can define get-minutes like this:
(define (get-minutes time)
(let* ((fields (string-split (symbol->string time) '(#\:)))
(hour (string->number (first fields)))
(minutes (strin... |
1,132,996 | 1,133,185 | Rule of thumb for capitalizing the letters in a programming language | I was wondering if anyone knew why some programming languages that I see most frequently spelled in all caps (like an acronym), are also commonly written in lower case. FORTRAN, LISP, and COBOL come to mind but I'm sure there are many more.
Perhaps there isn't any reason for this, but I'm curious to know if any of t... | Some of it has to do with the version of the language (i.e. FORTRAN 77 vs. Fortran 90). From the Fortran Wikipedia entry (emphasis mine):
The names of earlier versions of the language through FORTRAN 77 were conventionally spelled in all-caps (FORTRAN 77 was the version in which the use of lowercase letters in keywor... |
1,144,106 | 1,144,135 | About "If.." in Scheme (plt-scheme) | I had a pretty simple requirement in my Scheme program to execute more
than one statement, in the true condition of a 'if'. . So I write my
code, something like this:
(if (= 1 1)
((expression1) (expression2)) ; these 2 expressions are to be
; executed when the condition is true
(expr... | In MIT-Scheme, which is not very different, you can use begin:
(if (= 1 1)
(begin expression1 expression2)
expression3)
Or use Cond:
(cond ((= 1 1) expression1 expression2)
(else expression3))
|
1,144,661 | 1,144,970 | How to write the Average Function for this Data structure in Scheme/Lisp? | I want to find the price of a new-item based on the average prices of similar items.
The function get-k-similar uses k-Nearest Neighbors but returns me this output
((list rating age price) proximity).
For example, 2-similar would be:
(((5.557799748150248 3 117.94262493533647) . 3.6956648993026904)
((3.0921378389849963... | You can do the simple thing and just pull out every third value:
(define (average-prices a-list)
(/ (apply + (map fourth a-list)) (length a-list)))
This is a little inefficient since it builds an intermediate list, and my guess is that this is why you tried foldl. Here's the right way to do that:
(define (average-p... |
1,149,119 | 1,149,230 | How do you debug Clojure in NetBeans IDE? | I have a main function but NetBeans needs a main class in order for stepping. How do you guys debug Clojure in NetBeans?
| Using the enclojure plugin, I am able to setup a breakpoint in the editor, and then start the debugger inside of Netbeans. Java breakpoints within the project are hit, however, the clojure breakpoints fail with errors like:
Not able to submit breakpoint LineBreakpoint defpackage.clj : 8,
reason: Line number informati... |
1,162,989 | 1,164,165 | What is the difference between procedure and #'procedure in Lisp/Clojure? | What is the difference between the evaluation of double and #'double in Clojure/Lisp?
1:2 user=> double
#<core$double__4077 clojure.core$double__4077@1acd47>
1:3 user=> #'double
#'clojure.core/double
| In Clojure, #'foo is a shorthand for (var foo), which returns the variable object foo refers to, as opposed to its value. Look it up in the reference:
Macro Characters
var.
I am not sure if you also want to know the meaning in Lisp: In Common Lisp, #'foo is a shorthand for (function foo), which is used to access th... |
1,168,059 | 1,168,220 | Which Function is the best in terms of Stack Usage Efficiency and Time | I wrote 3 functions that count the number of times an-element appears in a-list.
I tried various inputs and profiled it but I still dont know which function is the best in terms of stack usage efficiency and time efficiency. Please Help me out.
;; Using an accumulator
(defn count-instances1 [a-list an-element]
... | The loop/recur version is the right way. Clojure cannot optimize tail calls due to limitations of the JVM.
|
1,179,735 | 1,180,120 | How do I go about splitting Lisp code into multiple source files? | Right now, everything I do manages to fit in a single source file, and a surprisingly small one at that. How do you decide how much and what to split off into separate files?
With Java, it's easy to decide what goes in one file (the decision is made for you already), but in Lisp I find I write many small functions tha... | When you start writing a Lisp program then it might be useful to start with a single file. Once the code gets too large (whatever that is) you can split it up. When you are approaching something that needs organization, then you should invest some work into it.
A few hints:
There are a few tools to manage source file ... |
1,187,262 | 1,187,367 | Lisp: CHAR is neither declared nor bound | I have decided to learn (Common) Lisp a few days ago and I realize that this is quite a newbie question and it is probably extremely trivial to someone with at least a bit of experience.
So basically what happens is that I load up Emacs + Slime (via Lisp in a Box) and write my program (included below):
(defun last-char... | The warning means that char is not being recognized as a function, as it should, for some reason (it's reporting that the symbol is unbound, it has no value).
It might have something to do with your implementation. I've run your code using C-c M-k in my SBCL + Emacs/Slime (and in Clozure) and I get the following repor... |
1,209,097 | 1,209,221 | Good resources on using functional programming in game development? | I'm quite new to that functional programming paradigm, but so far I like it. Since I'm into game development, I want to try it out in writing some games in purely functional programming style. I don't mind the language - be it Erlang, Haskell, Lisp, or even Ruby (I found out it supports functional programming traits).
... | Well, you could do worse than studying the code of some of these haskell games.
Some of these use FRP (functional reactive programming), which some people are working on as a pure, high-level technique for games and other things. But most are a typical haskellish mixture of effectful and pure functional code.
Bloggers ... |
1,216,458 | 1,216,525 | How to embed a common lisp interpreter into a gui application | I want to know how to embed a lisp interpreter into a gui application, i.e. something like what pyshell does for Python.
| Some options:
Write the complete application including the GUI in Lisp: lots of Lisp systems support that
Write the application in Lisp and link C code to it, if you need to call some external GUI libraries: Lisp systems can load and call C (and compatible) libraries.
Embed Lisp into your application: ECL (Embeddable ... |
1,219,185 | 1,219,249 | Which is better?: (reduce + ...) or (apply + ...)? | Should I use
(apply + (filter prime? (range 1 20)))
or
(reduce + (filter prime? (range 1 20)))
Edit: This is the source for prime in clojure from optimizing toolkit.
(defn prime? [n]
(cond
(or (= n 2) (= n 3)) true
(or (divisible? n 2) (< n 2)) false
:else
(let ... | If you are asking in terms of performance, the reduce is better by a little:
(time (dotimes [_ 1e6] (apply + (filter even? (range 1 20)))))
"Elapsed time: 9059.251 msecs"
nil
(time (dotimes [_ 1e6] (reduce + (filter even? (range 1 20)))))
"Elapsed time: 8420.323 msecs"
nil
About 7% difference in this case, but YMMV d... |
1,220,149 | 1,220,229 | Can you show me how to rewrite functions in lisp? | Consider this javascript:
function addX(n)
{
return 3 + n;
}
alert(addX(6)); //alerts 9
eval('var newFunc = ' + addX.toString().replace("3", "5") + ';');
alert(newFunc(10)); //alert 15
Please ignore the fact that it's of dubious use and methodology, dangerous, difficult to follow in a large codebase, and so on. It ... | The difficult part is that Common Lisp (and some other Lisps) gets rid of the source code. Especially when a compiler is involved. By default the source code is gone and all is left is the machine code then. How to recover the Lisp source and in what shape?
The reason behind this: why should a CL program be required to... |
1,223,394 | 1,223,791 | can I use two different lisp+slime/swanks from the same emacs? | can I use common lisp and Clojure from within emacs at the same time?
I would like to have each lisp-REPL in its own buffer, and If i did this how could I controll which buffer sent its data to which lisp?
| Yes. In the documentation to Slime you will find slime-lisp-implementations. Here is how I have it defined in my .emacs:
(setq slime-lisp-implementations
'((cmucl ("/usr/local/bin/lisp") :coding-system iso-8859-1-unix)
(sbcl ("/usr/local/bin/sbcl" "--core" "/Users/pinochle/bin/sbcl.core-with-swank") :init (lamb... |
1,224,374 | 1,224,394 | What features of Lisp are present in Ruby? | I've read that Ruby has inherited many features from Lisp.
What features does Ruby have that likely have a Lisp heritage?
| This is a good read: http://www.randomhacks.net/articles/2005/12/03/why-ruby-is-an-acceptable-lisp
See also, "how ruby borrowed a decades-old idea from LISP" http://patshaughnessy.net/2012/9/18/how-ruby-borrowed-a-decades-old-idea-from-lisp
|
1,238,858 | 1,239,183 | Can a compiled language be homoiconic? | By definition the word homoiconic means:
Same representation of code and data
In LISP this means that you could have a quoted list and evaluate it, so (car list) would be the function and (cdr list) the arguments. This can either happen at compile- or at run-time, however it requires an interpreter.
Is it possible t... | 'Homoiconic' is kind of a vague construct. 'code is data' is a bit clearer.
Anyway, the first sentence on Wikipedia for Homoiconic is not that bad. It says that the language has to have a source representation using its data structures. If we forget 'strings' as source representation (that's trivial and not that helpfu... |
1,238,975 | 1,239,015 | Can all language constructs be first-class in languages with offside-rules? | In LISP-like languages all language constructs are first-class citizens.
Consider the following example in Dylan:
let x = if (c)
foo();
else
bar();
end;
and in LISP:
(setf x (if c (foo) (bar)))
In Python you would have to write:
if c:
x = foo();
else:
x = bar();
Because Py... | I don't see the relation with first-classness here - you're not passing the if statement to the function, but the object it returns, which is as fully first class in python as in lisp. However as far as having a statement/expression dichotomy, clearly it is possible: Haskell for instance has indentation-based syntax, ... |
1,249,008 | 1,249,117 | Help in designing a small Unit Test Macro in Clojure | I have a small unit test macro
(defmacro is [expr value]
`(if (= ~expr ~value)
'yes
(println "Expected " ~value "In" ~expr "But Evaluated to" ~expr)))
How do I correctly write the error message?
Right now it gives
Clojure 1.0.0-
1:1 user=> (is (+ 2 2) 4)
user/yes
1:2 user=> (is (+ 2... | Original Answer
I think this is what you are looking for:
(defmacro is [expr value]
`(if (= ~expr ~value)
true
(println "Expected " ~value "In" (str (quote ~expr))
"But Evaluated to" ~expr)))
what (quote ~expr) does is bring the s-expression represented by expr into your "templ... |
1,249,991 | 1,250,089 | Variable references in lisp | Another newbie (Common) LISP question:
Basically in most programming languages there's a mean for functions to receive references to variables instead of just values, that is, passing by reference instead of passing by value. Let's say, for the sake of simplicity, I want to write a LISP function that receives a variabl... | With lexical scope one does not have access to variables that are not in the current scope. You also cannot pass lexical variables to other functions directly. Lisp evaluates variables and passes the values bound to these variables. There is nothing like first-class references to variables.
Think functional!
(let ((a 1... |
1,252,062 | 1,252,123 | Emacs exercises to become more comfortable and familiar with the editor itself as well as Lisp? | There's a great project called the Ruby Koans, it's a series of tasks to exercise yourself in the Ruby language, stepping you through the standard library using the Ruby Unit Testing suite as a learning tool. It's a great project.
I'd love to see something similar for Emacs.
Can anyone recommend any Lisp exercises t... | There used to be lesson in .el format (emacs lisp) at http://www.gnuvola.org/software/elisp-tutorial/.
You can find a copy of the tutorial here now.
I learned a lot from them. You read them in emacs in lisp interactive mode, and practice within the text.
|
1,257,028 | 1,257,066 | Why should I use 'apply' in Clojure? | This is what Rich Hickey said in one of the blog posts but I don't understand the motivation in using apply. Please help.
A big difference between Clojure and CL is that Clojure is a Lisp-1, so funcall is not needed, and apply is only used to apply a function to a runtime-defined collection of arguments. So, (apply f ... | You would use apply, if the number of arguments to pass to the function is not known at compile-time (sorry, don't know Clojure syntax all that well, resorting to Scheme):
(define (call-other-1 func arg) (func arg))
(define (call-other-2 func arg1 arg2) (func arg1 arg2))
As long as the number of arguments is known at ... |
1,263,775 | 1,264,056 | How might I format an alist in common lisp? | I'm beginning to write me some Common Lisp and am just getting the hang of consing things together and formatting them.
Let's suppose I have an alist, like this:
(defvar *map* '((0 . "zero") (1 . "one") (2 . "two")))
How do I format it like this?
0: zero
1: one
2: two
I was thinking something like (format t "~{~{~a: ... | The #cl-gardeners channel on Freenode suggests doing a destructuring loop bind like this:
(loop for (a . b) in *mapping*
do (format t "~a: ~a" a b))
|
1,264,850 | 1,264,888 | Source code of well designed functional web apps? | What are examples of well designed functional (as opposed to object oriented) web apps that make their source code available? I am currently studying the Hacker News source but I'd like to see some other non-trivial examples, ideally in clojure.
For MVC there are lots of Rails and PHP apps, frameworks, and tutorials to... | There's:
Compojure (clojure)
PLT Scheme Webserver (PLT Scheme)
Erlyweb (erlang)
Seaside (smalltalk)
That list is enough to keep you busy giving a sample of functional languages with different characteristics:
Clojure: multi-paradigm?, flexible? it isn't a pure functional language and although it is preferred that yo... |
1,275,547 | 1,275,667 | How can I do web programming with Lisp or Scheme? | I usually write web apps in PHP, Ruby or Perl. I am starting the study of Scheme and I want to try some web project with this language. But I can't find what is the best environment for this.
I am looking for the following features:
A simple way of get the request parameters (something like: get-get #key, get-post #ke... | Racket has everything that you need. See the Racket web server tutorial and then the documentation. The web server has been around for a while, and it has a lot of features. Probably the only thing that is not included is a mysql interface, but that exists as a package on PLaneT (Racket package distribution tool).
U... |
1,275,880 | 1,279,160 | What is the best open source common lisp implementation that works with Eclipse? | I have started working my way through Practical Common Lisp and am looking for a Common LISP implementation that works on Eclipse. It would be nice if it had some kind of IDE integration besides the editor and the REPL (although I'm not sure what that would be). Also, I have Linux, Windows, and OS X, although my primar... | Cusp is an awesome plug-in. You do not necessarily need to use the SBCL implementation.
Here is the group.
The repository has moved to here.
|
1,277,259 | 1,282,889 | How to write an empty list using S, K and I combinators? | I know that:
(cons [p] [q]) is ((s ((s i) (k [p]))) (k [q]))
(car [lst]) is ([lst] k)
(cdr [lst]) is ([lst] (k i))
I want to write a list like this
(cons [a] (cons [b] (cons [c] [nil])))
, which is going to be something like this:
((s ((s i) (k [a]))) (k ((s ((s i) (k [b]))) (k ((s ((s i) (k [c]))) (k [nil]))))))
Bu... | The only thing you need from a nil representation is to be able to identify it -- write some null? predicate that returns "true" for nil and "false" for all other pairs. This means that the answer depends on your representation of true/false. With the common choice of λxy.x and λxy.y, a convenient encoding for nil is... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.