Dear all, I now have a preliminary macro
(defmacro key-if(test &key then else)
`(cond (,test
,then)
(t,else)))
and it is now correctly working as
> (key-if (> 3 1) :then 'ok)
OK
> (key-if (< 5 3) :else 'ok)
OK
> (key-if (> 3 1) :else 'oops)
NIL
> (key-if (> 3 1) :else 'oops :then 'ok)
OK
Now I want to e...
When I paste this code into a REPL, it works fine:
(use 'clojure.contrib.seq-utils)
(defn- random-letter [] (char (+ (rand-int 26) 97)))
(defn- random-digit [] (rand-int 10))
(defn- random-password
"Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa"
[]
(let [password (interpose '((random-digit))...
I'm trying to add, say, x to every element of a list.
For example:
(queue 3 '(1 2 3))
would give
((3 1) (3 2) (3 3))
The code below apparently does not do what I want.
Any hints please?
(defun queue(x y)
(cond
((null y) nil)
(t (cons x (queue x (rest y))))))
...
I now have a problem on using "reduce" to implement my own version of copy-list.
This is what I have done:
(defun my-copy-list (lst)
(reduce #'(lambda (x y)
(cons x y))
lst :initial-value nil :from-end t))
However, my teacher said there is no need to use that lambda, I am confused on this. How may we ac...
I've read through all the documentation, and most of the source of LFE. All the presentations emphasize basic lisp in traditional lisp roles - General Problem Solving, Hello world and syntax emulating macros.
Does anyone know how LFE handles messaging primitives? To specify a more precise question, how would you express this erlang:
...
I use ASP.NET during my day job, but I'm always looking to expand my programming knowledge. I've tinkered with everything from Ruby to 6502 assembly language, and now I want to learn Lisp. I guess I have Paul Graham to blame for that.
I've heard about "Practical Common Lisp" and I know how to Google, but I'm curious if there are any ....
I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks
...
I use emacs via Putty and since Putty doesn't send certain key combinations to the remote console I generally need to re-bind them to other key combinations.
After installing the amazing Zen-Coding mode I had some trouble with the preview it generated; I couldn't get it to insert the output it was previewing. I got around this with the ...
Can the Dancing Links implementation of Knuth's Algorithm X be used to solve this CSP? In this game the first and last number are always already in the board and I belive there's only one solution to each well formulated problem.
...
Hello,
Long story:
I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition.
I was looking over frameworks/libraries/ways of calling Lisp code from Java, or even better Lisp-Java intercommunication.
I have looked at Jacol, but it is old, and it does not ...
Dear all:
Hi, I've done the Graham Common Lisp Chapter 5 Exercise 5, which requires a function that takes an object X and a vector V, and returns a list of all the objects that immediately precede X in V.
It works like:
> (preceders #\a "abracadabra")
(#\c #\d #r)
I have done the recursive version:
(defun preceders (obj vec &optio...
In Lisp, suppose I have these two rules in the knowledge base:
(append nil ?x ?x)
(<- (append (cons ?x ?l1) ?l2 (cons ?x ?l3))
(append ?l1 ?l2 ?l3))
Then how could I infer that if we ask
(ask '(append (cons a (cons b nil))
(cons c nil)
?l)
'?l))
we will get the result '((cons a (cons b (cons c n...
I have a byte buffer 6 bytes long first four contains ip address last 2 contains port, in big endian notation.
to get the ip i am using,
(apply str (interleave (map int (take 4 peer)) (repeat ".")))
Is casting bytes to int safe to get the ip address?
and also in java i use,
int port = 0;
port |= peerList[i+4] & 0xFF;
po...
Can you have hash tables or dicts in Lisp? I mean the data structure that is a collection of pairs (key, value) where values can be acceded using keys.
...
Suppose I have this wonderful function foo
[92]> (defun foo () (lambda() 42))
FOO
[93]> (foo)
#<FUNCTION :LAMBDA NIL 42>
[94]>
Now, suppose I want to actually use foo and return 42.
How do I do that? I've been scrounging around google and I can't seem to come up with the correct syntax.
...
Hello every one, I wrote a test function to test my understanding of "return-from" in Lisp
(defun testp (lst)
(mapc #'(lambda (x y)
(if (null lst)
(return-from testp t)))
lst
(cdr lst)))
I think the test (testp 'nil) should return T but it returns NIL.
Could you please help my understandin...
Conventional wisdom states that OS kernels must be written in C in order to achieve the necessary levels of performance. This has been the justification for not using more expressive high level languages.
However, for a few years now implementations of Common Lisp such as SBCL have proven to be just as performant as C. What then are t...
There's a structure of the following format:
(setq dist '(((1 1) 1)
((0 2) 3)
((1 2) 1)
((2 3) 3)
((3 5) 4)))
Is there any function which, if I call
(myf '(0 2))
could give me
3
or
((0 2) 3)
Something like a reverse assoc
...
There is the whole new paradigm of "functional programming", which needs a total change of thought patterns compared to procedural programming. It uses higher order functions, purity, monads, etc., which we don't usually see in imperative and object oriented languages.
My question is how the implementation of these languages differs fr...
What's the difference between:
(cons 'a (cons 'b 'c)) ;; (A B . C)
and
(cons 'a '(b.c)) ;; (A B.C)
I need to create the following list ((a.b).c) using cons so i'm trying to understand what that "." represents.
L.E.: I have the following (cons (cons 'a 'b) 'c) but it produces ((A . B) . C) and not ((A.B).C) (Note the extra spaces)...