I wanted to try and learn lisp, but I very quickly gave up. I figured I'd try again. I'm looking at Problem 2 on Project Euler - finding the sum of all the even Fibbonacci numbers under 4 Million.
I wrote the following code which works, but is all kinds of ugly. Chief among them is the fact that it's so slow - because it's doing naiv...
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, and so on to get ...
Being a newbie to Lisp I'm wondering if the Lisp syntax could be "fixed"?
Some people say the syntax in Lisp is one of its biggest strengths. I don't quite understand this.
Isn't it possible to replace "obvious" parentheses with a combination of white spaces, new lines and indenting? Just like in Python?
It looks to me like parenthe...
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 a purely functio...
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 f x) x)
(/ (...
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? (caddr ls)) expr...
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-expr)
(eval (a...
I'm working on a web app using Hunchentoot (on SBCL and Linux), and usually I just run it from Emacs (SLIME), but for deployment I want something that's easier to automate. So I'm trying to figure out ASDF, because that seems to be what everybody's using these days.
myapp.asd:
(in-package #:asdf)
(defsystem :myapp
:name "my app"
:...
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 mutable data structur...
Has anyone got langutils working with sbcl?
...
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 know LISP, could you please change this into C-based sytnax for me (ie. C/C++/C#/Java ..etc)?
(let ((g (* 2 (or (gethash word good) 0)))
(b (or (gethash word bad) 0)))
(unless (< (+ g b) 5)
(max .01
(min .99 (float (/ (min 1 (/ b nbad))
(+ (min 1 (/ g ngood))
...
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 goes crazy using all...
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 R5RS as the langua...
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?
...
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 to have to typ...
I have been doing object-oriented programming for a few years now, and I have not done much functional programming. I have an interest in flight simulators, and am curious about the functional programming aspect of Lisp. Flight simulators or any other real world simulator makes sense to me in an object-oriented paradigm.
Here are my qu...
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 like to make a l...
In Emacs, how can I enforce a maximum line length of, say, 80 characters? I want it to insert proper line breaks in my code, much like fill-paragraph for text, if possible, with the correct insertion of the second part of the line.
Here a little example:
LongNameType<PrettyLong, AlsoLong> doSomethingWithLongFunctionName(int a, int b);
...
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.psg.com/~dlamkins/s...