common-lisp

How do I stop tracing a function in clisp?

I've been tracing a function example with this call (trace example) and now I wish to stop tracing it, how can I do this? ...

Are there open source Common Lisp COM wrappers?

I have an application that is written in SBCL and is deployed as an executable on Windows. The need has arisen for it to interact with Excel via COM and another application via DDE (I know, I know). DDE is simple enough for me to have quickly wrapped what I needed in a very small, simple to maintain C library. COM, on the other hand, se...

cross-package defgeneric/defmethod in Common Lisp?

What is the right way to define a generic in package A and to provide a method for this generic in package B in CLOS? Thank you in advance! Example: (defpackage :common (:use :cl)) (in-package :common) (defgeneric compare (a b)) (defmethod compare ((a number) (b number)) (cond ((< a b) -1) ((= a b) 0) (T 1))) ...

Lisp chaining functions macro

Is there a ready made lisp macro that allows chaining (piping) of functions? I couldn't find one. I'll try to explain what I mean with this example. Instead of using let* with lots of unused intermediate variables like this: (let* ((var1 (f1 x y)) (var2 (f2 x var1)) (var3 (f1 var2 z))) var3) I would like to have it written l...

Using a defstruct database with remove-if-not

I'm trying to adapt this defstruct example by adding the select- functions described in the book: Practical Common Lisp. I'm running the code in Emacs using the Common Lisp package. The select-by-first does not return anything. In the Lisp book, the author does not use defstruct so I must need to do something slightly different? (de...

How can I perform a partial symbol match on a defstruct?

In this StackOverFlow question, I created an employee database and provided a select-by-first function. How can I write a select-by-first-pattern where the record is returned if any part of the string/symbol matches? (select-by-first-pattern 'ev); Returns all records containing "ev" (eg. Steve) Here's the code needed to construct th...

Common Lisp Exercises/Problems

I'm working through Practical Common Lisp presently http://www.gigamonkeys.com/book/ It's an excellent book with some practical assignments towards the end, but I'm looking for basic problems that explore the use of functions, variables and macros. Can anybody suggest a suitable resource to work through in order to reinforce the conce...

How to write a recursive macro call on a &REST parameter in Lisp?

Hi, I've been writing some simple test cases for one of my assignments, and have built up a bit of a test suite using macros. I have run-test and run-test-section and so on. I'd like run-test-section to take a number of parameters which are run-test invocations and count up the number of PASSes and FAILs. run-test returns T on PASS, an...

Lisp Community - Quality tutorials/resources

As many other people interested in learning Lisp, I feel the resources available are not the best for beginners and eventually prevent many new people from learning it. Do you feel it could be created some sort of community, with a website, forum or something, that provides good (as in quality) resources/tutorials, for Lisp users, possib...

Why is consing in Lisp slow?

I read in the book 'On Lisp' that one should avoid excessive use of cons in the body of expanded macros. Why is cons considered to be an inefficient operation? Does Lisp not do structure sharing with the cons cells? ...

Generating a quiz in Common Lisp?

I want to teach myself Spanish and Lisp. I've got several word lists like the data show below. How can I generate a quiz from the data that looks like this? amarillo? [ ] blue [ ] yellow [ ] gray [ ] pink azul? [ ] red [ ] blue [ ] green [ ] orange . . . verde? [ ] purple [ ] gold [ ] green [ ] black ...

Lisp or Haskell for web application development

I'm considering to learn a functional programming language. I decided to build a medium-sized web application. I narrowed down the choices to Haskell and Common Lisp. Web application needs to interface to some relational database (MySQL, Firebird or Postgres) and has to run on Linux. Obviously, it has to interface well with web serve...

Lexical closures over macrolet?

Is there a way to do something like lexical closures using macrolet? What I want to do is make the following macro a local recursive helper that calls a function on each combination instead of generating a list as it does now calling the macro in the repl results in: CL-USER> (combinations nil '(1 2 3) '(4 5 6)) ((1 4) (1 5) (1 6) (2 4...

Syntax Error in Common Lisp

This refuses to compile. Commenting out the (setf roll line lets it compile. However, (setf roll... itself evaluates correctly in the REPL. Program: ;; loop n times ; sum up number of hits over value v (defun num-hits (n v) (let ((roll) (table)) (setq table (make-hash-table)) ;;until i == n (loop for i from 1...

sbcl runs forever on second call of function

The function: Given a list lst return all permutations of the list's contents of exactly length k, which defaults to length of list if not provided. (defun permute (lst &optional (k (length lst))) (if (= k 1) (mapcar #'list lst) (loop for item in lst nconcing (mapcar (lambda (x) (cons item x)) (permute (remov...

Unroll / splat arguments in common lisp

Say I have a list of arguments: > (setf format-args `(t "it's ~a" 1)) (T "it's ~a" 1) How can I then "splat" or "unroll" this into a series of arguments rather than a single list argument, for supplying to the format function? i.e I would like the following function call to take place: > (format t "it's ~a" 1) For reference, I wo...

Suggestions for algorithmic analysis of Lisp programs?

Which operations in Common Lisp programs are to be considered sufficiently primitive so as to count for a single "step" in algorithmic analysis? How widely do modern lisps vary in their implementation? Certainly arithmetic with small integers would count as a single step, but what about larger numbers? And what about considering the d...

Scraping an HTML table in Common Lisp?

I'd like to extract some information from a web page that's contained in an HTML <table>. How can I extract all the table information into a nice | separated file? Author|Book|Year|Comments Bill Bryson|Short History of Nearly Everything|2004 Stephen Hawking|A Brief History of Time|1998|Still haven't read. Ideally, I'd like to have a...

How to process input and output streams in Steel Bank Common Lisp?

I'm trying to figure out how to use the output stream of one program I start with RUN-PROGRAM so it can be used as the input of another program started with RUN-PROGRAM (i.e., the moral and perhaps literal equivalent of piping). I've tried using a number of combinations of the :INPUT, :OUTPUT and :WAIT keyword arguments, but nothing I've...

CLisp: "use-package" resolving conflicts non-interactively

I'm trying to use parenscript in GNU common lisp to compile a lisp file into a javascript one. I find that using the PS symbol macro "@" doesn't work if I try to use its prefix ("ps:@"). However, if I use the REPL and run (use-package :ps) before I try compiling the lisp file, everything works as expected (and I don't have to use the pr...