common-lisp

Common Lisp - how to say if a pathname points to a regular file or a directory?

Is it possible to 'stat' a file and find its file type - regular or directory? ...

Difference between a procedure and a combinator?

I've been using Scheme and Common Lisp for a while and there is one thing about nomenclature that I never got: I know that combinators are procedures with no free variables, but I seldom see them being called "combinators", except for those that deal with lists and other sequences. Is my perception correct? Or is there some other defini...

How do I increment (add one to) or decrement (subtract one from) a number, in Common Lisp?

It's all in the title, really. ...

Does "The whole language always available" hold in case of Clojure?

Ninth bullet point in Paul Graham's What Made Lisp Different says, 9. The whole language always available. There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or run code while compiling, and read or compile code at runtime. Running code at read-time le...

How to unload a lisp file in CLisp REPL?

Am able to load and call the functions but I would like to reload the file after making some corrections. Cant find either an unload or reload function? ...

Accessing active symbol table in Common Lisp

I have heard that the active symbol table is accessible within the Common Lisp runtime. Have I misunderstood? ...

Basic Lisp Macro Question

Hi , Little help here please . I am trying to create this lisp macro which takes a list (of numbers) as input and returns the sum of those numbers. The code (setf g (list 1 2 3 4)) (defmacro add-test(var) `(+ ,@var)) (add-test g) gives this error *The value G is not of type LIST. [Condition of type TYPE-ERROR]* At the s...

What are examples of Symbolic Programming?

I have to do a term project in my symbolic programming class. But I'm not really sure what a good/legitimate project would be. Can anyone give me examples of symbolic programming? Just any generic ideas because right now I'm leaning towards a turn based fight game (jrpg style basically), but I really don't want to do a game. ...

A Complete RPN Expr-Eval Program Inside a Tweet? -- "YES WE CAN!", Using LISP

The Program (115 Chars) (defun rpn(e)(let((s()))(dolist(x e)(if(numberp x)(push x s)(push(eval(reverse(list(pop s)(pop s)x)))s)))(car s))) A simple test: CL-USER> (rpn '(1 2 3 * + 4 2 / +)) And it returns 9 Anyone has some good ideas about writing an Infix-to-RPN program inside one single tweet? I failed. I can wrote that one in 2...

Displaying a string while using cond in Lisp

Hi, I'm just starting off with Lisp and need some help. This is technically homework, but I gave it a try and am getting somewhat what I wanted: (defun speed (kmp) (cond ((> kmp 100) "Fast") ((< kmp 40) "Slow") (t "Average"))) However, if I run the program it displays "Average" instead of just Ave...

What is the future of LISP? Should I learn it?

I know this is not a very technical question, but it's for all technical people, that's why I ask it here. Here is my question: Can someone help me understand the current and future of learning LISP? One of my papers in university uses LISP for a project (it's a big project - may be two semester long), and I am not able to decide wheth...

Design By Contract LIbrary(ies) for Common Lisp?

Coming from a background in Clojure, I am taken with the potential that its pre-/post-conditions provide as a basis for design by contract: ;; sqr.clj (defn sqr [n] {:pre [(not= 0 n) (number? n)] :post [(pos? %) (number? %)]} (* n n)) (sqr 10) ;=> 100 (sqr 0) ; Assertion error Is there a similar pre/post capability in Commo...

Why am I getting this lambda expression error, and what can I do about it?

I'm pretty new to lisp; I was wondering if anyone here could help me out. I have the following code snippet: (defun write-lookup (binding-list pattern fact) (cond ; No bindings have been stored ; Return the binding list with a new one! ((not binding-list) (cons (cons pattern fact) nil)) ; A list of bind...

functions in lisp

Hi.... I have this question for a homework assignment.... I'm having difficulty with cost-of-applying-operator and estimated-distance-from-goal Basically its the 2 jug problem one 4ltr jug and one 3 ltr jug and we need to get 2 ltrs in one... we're provided with the a-star code and i've done the jug-problem.lisp just not sure how to w...

Hunchentoot/cl-who page composition

Hunchentoot/cl-who Page Composition I'm trying to put together a few pages in hunchentoot as an experiment, and I'm running into an unexpected wall. As an example, I have the following template macro. (defmacro page-template ((&key title) &body body) `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) ...

Problem with access of slots in Lisp (CLOS)

I have a Node class that has an 'element' slot which contains a list with numbers and one letter, for example: '(1 2 3 b 4 5 6) (defclass node () ((element :reader get-element :writer set-element :initform '() :initarg :element :documentation "The element")) Part of the program is su...

Why is read-line run twice for reading from a file in Lisp?

This is the code to implement the 'cat' command with lisp, as is explained in the book ANSI Common Lisp, page 122. (defun pseudo-cat (file) (with-open-file (str file :direction :input) (do ((line (read-line str nil 'eof) (read-line str nil 'eof))) ((eql line 'eof)) (format t "~A~%" line)))) Why is ...

How to do Pattern Matching in Common Lisp

I have no idea if there exists a pattern matching function for Common Lisp, nevertheless I have to make my own function. I have no idea about Lisp. Can somebody give heads-up on learning Lisp and most importantly, how to go about doing pattern matching in Lisp. I will have to pass a pattern and a fact and say if they match. An example wo...

How to return control from a function in lisp

(defun returnFirstCharacter(p) (if (symbolp p) (char (symbol-name p) 0) nil) ) (defun returnRestCharacters (p) (let () (intern (subseq(string p) 1)) ) ) (defun val (x a) (cond ((null a) nil) ((equal (car(cdr a)) x) (cdr (cdar a))) (t (val x (cdr a))) ) ) (defun match (pattern data) (cond ...

How can I read the contents of a file into a list in Lisp?

I want to read in the contents of a file into a list. Some of my attempts so far have been - (defun get-file (filename) (let ((x (open filename))) (when x (loop for line = (read-line x nil) while line do (list line))) (close x))) (defun get-file (filename) (let ((x (open filename :if-does-not-exist nil)) (content...