common-lisp

Hex to decimal conversion in common lisp

Is there an easy helper function in common lisp to convert from hex to decimal? ...

How to examine list of defined functions from Common Lisp REPL prompt

I'm a newbie to lisp. I'm evaluating/testing a browser based application presumably written in common lisp. Apart from the browser based interface, the software provides a 'Listener' window with a 'CL-User >' REPL prompt. I wish to examine the list of functions, symbols, and packages from the REPL prompt. So that I could co-relate the ...

Common lisp integer to hex conversion

Is there a similar function to (parse-integer "ff" :radix 16) that will take me back the other way? If I have the int 255 how do I convert it to the string ff? ...

Clozure Common Lisp - TCP Socket Programming - Sending a Reply

I have a very small program which opens a socket and accepts a connection. It then grabs the remote IP and port. I'd like to send a text message to the remote computer (telnet) and close the connection. I can't determine which function is for sending a message to the telnet client. The Clozure manual lists a function called "send to" ...

Getting Stack overflow with GNU CLisp (Windows)

I'm getting "Program stack overflow RESET" message while running my program. So I set added a counter to see how many times I'm recursively calling the main function in my program. Turns out that it is around 30,000 times and the data I'm stacking are lists of length around 10 elements, which I think are not so many. My question is wheth...

"unfold" for common lisp?

I learned quite a bit of scheme from SICP but am more interested in common lisp now. I know common lisp's fold is reduce, with special arguments for left or right folding, but what is the equivalent of unfold? Googling has not helped much. In fact I get the impression there is no unfold??? ...

Common Lisp: Beginner's trouble with funcall

I'm trying to pass a function as an argument and call that function within another function. A piece of my code looks like this: (defun getmove(strategy player board printflag) (setq move (funcall strategy player board)) (if printflag (printboard board)) strategy is passed as a symbol represented in a two dimensional list as some...

Multiple constructors in common lisp

Can classes have multiple constructors and/or copy constructors in common-lisp? That is - in order to create a class for a new vector - "vecr" to represent 3-d vectors of real numbers, I'd like to define the new class that can be initialized in multiple ways: (vecr 1.2) ==> #(1.2 1.2 1.2) or (vecr 1.2 1.4 3.2) ==> #(1.2 4.3 2.5) or...

lisp file pointers in classes

I'm running up against a problem in understanding the CLOS way of handling file access within a class. In c++ I would be able to do this: class Foo { Foo (string filename); // opens the file (my_file) requested by the filename ~Foo (); // close the file FILE * my_file; // a persistent file-handle DataStruct my_data; // ...

When is an initform used?

I'm forming a class for some work on molecular dynamics as follows: (defclass %atom (particle) ((name :initarg :name :initform (error "Every atom in the system must have a name!")) (mass :accessor mass :initarg :mass :initform (getmass name)) (charge :accessor charge :initarg :charge :initform (getcharge name)))) Initially I t...

Common Lisp: cons inside loop

I wonder why in the following code, d is not being consed into x. Any hints are much appreciated. (defun it (x) (setq f '(a b c)) (dolist (d f) (cons d x)) (print x)) Thank you! ...

Translating the Q and P function from The Little Schemer into Common Lisp?

In Chapter 9 of the Little Schemer, the Author presents the following two functions (define Q (lambda (str n) (cond ((zero? (remainder (first$ str ) n)) (Q (second$ str ) n)) (t (build (first$ str ) (lambda ( ) (Q (second$ str ) n))))))) (define P (lambda (str) (build (first$ st...

Lisp as a Scripting Language in a C++ app...

Hey, I've been looking at the possibility of adding a scripting language into my framework and I heard about Lisp and thought I would give it a go. Is there a VM for Lisp like Lua and Python or am I in the wrong mindset. I found CLISP here, http://clisp.cons.org/, but am not sure if this is what I am looking for. Can anyone point me in ...

Getting the first n elements of a list in Common Lisp?

The title says it all, really. How would I get the first n elements of a list? CL-USER> (equal (some-function 2 '(1 20 300)) '(1 20)) T I am absolutely certain this is elementary, but help a brother newb out. Kisses and hugs. ...

Is there a common lisp package naming convention?

I have created some of my own user packages and have run into a name clash. In Java, the naming convention is to use your domain name in the package name: e.g. import com.example.somepackage;. Are there any widely used package naming conventions for common lisp packages? Regards, Russell ...

Pointers in Lisp?

I've started learning Lisp recently and wanted to write a program which uses gtk interface. I've installed lambda-gtk bindings (on CMUCL). I want to have putpixel/getpixel ability on a pixbuf. But I found that I'm unable to direct access memory. (or just don't know how) Function (gdk:pixbuf-get-pixels pixbuf) returns me a number - memor...

lambda-gtk negative pointer

I was trying to write my own put-pixel on (Gdk) pixbuf in Lisp. When I finally realized how I can operate on C pointers in CL, new obstacle came along - (gdk:pixbuf-get-pixels pb) returns me negative number. My question is: can I convert it somehow to a valid pointer? My attempts to use cffi:convert-from-foreign and cffi:translate-from-f...

A lisp function refinement

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...

returning a lambda function in clisp, then evaluating it

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. ...

Why not port Linux kernel to Common Lisp?

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...