FAQ Database Discussion Community


Hide `(declare)` forms in lisp mode

emacs,common-lisp,slime
This is actually two questions: Does anybody know an emacs feature that can hide (and maybe indicates that it has done so) selected forms in lisp code ? I've written some performance oriented common lisp and the key functions do contain lots of (declare (type ...)) forms that clutter the...

Difference between (loop for) and (loop :for) in Common Lisp [duplicate]

lisp,common-lisp
This question already has an answer here: Why do some people use keywords for the clauses in the loop macro? 3 answers I just saw the answer of Sylwester to this question, and I thought strange that the loop has colons everywhere. Usually, I would write (loop for n...

How to get a text to be executed in LISP?

lisp,common-lisp
Suppose that the following macro execution: (make-model '((1 2)(3 4)(5 6)(7 8))) , can generate the following list: ((MAKE-INSTANCE 'MODEL :NAME 7 :ID 8) (MAKE-INSTANCE 'MODEL :NAME 5 :ID 6) (MAKE-INSTANCE 'MODEL :NAME 3 :ID 4) (MAKE-INSTANCE 'MODEL :NAME 1 :ID 2)) If I store the result in a parameter...

Understanding “let” expression in LISP

lisp,common-lisp,let
I am extremely new to lisp, had previous experience with functional programming (Haskell, SML). Why is this code returning 14, and not 10 (ie. 1 + 2y + 3 + 1)? (defvar x 1) (defun g (z) (+ x z)) (defun f (y) (+ (g 1) (let ((x (+ y...

Difference between array/vector types in Common Lisp?

arrays,vector,types,common-lisp
What is the difference between the types 'vector, 'simple-vector, 'array and 'simple-array? I know that vectors are a subtype of arrays and cannot be multidimensional. The "simple-" versions seem to be types, and the rest classes. So the types might be more complex, to specify the type. Which type-specifiers should...

How to Call a Go Program from Common Lisp

common-lisp
I have a Go program which cannot be rewritten in Common Lisp for efficiency reasons. How can I run it via Common Lisp? Options so far: 1. CFFI Using the foreign function interface seems to me like the "correct" way to do this. However, the research I did lead directly...

Get Thread ID in SBCL

common-lisp,sbcl
I am working with Lisp sb-thread package. When I use *current-thread* to get the thread id, the result of the last evaluated expression is also returned with the thread id. I only need the thread id for my program.

Custom slot options don't apply any reduction to its argument

common-lisp,clos,mop
Say if I define a metaclass that enhances standard slots with a validator slot, when I pass :validator (clavier:valid-email "The email is invalid") as an option, instead of storing the result of of the expression, which is a funcallable, it stores the expression itself. Am I'm missing a step when...

How to read sbcl deterministic profiler output?

profiling,common-lisp,profiler,sbcl
How is the output of the deterministic profiler of sbcl to be interpreted? seconds | gc | consed | calls | sec/call | name ------------------------------------------------------- seconds (total execution time),calls (amount overall calls),sec/call (average time per call), and name (well the name of the function) are quite straight forward. What does...

How to call a macro with a parameter instead of list in LISP?

lisp,common-lisp
Based on the example provide in the practical common lisp reference, I define a macro to create a class as followed. (defmacro define-class (class-name class-slot) `(defclass ,class-name () ,(mapcar #'slot->defclass-slot class-slot)))) The function slot->declass-slot take a single argument and generate a standard line describing a slot in a class. The...

Creating A Process Queue in Common Lisp

common-lisp
I have a server running Hunchentoot (CentOS and SBCL). When a user submits a specific type of post request, a subprocess is launched (run-program) which can take up to four minutes to complete. If five people perform that specific type of request at the same time, the server runs out...

Why does lisp use gensym and other languages don't?

lisp,common-lisp
Correct me if I'm wrong, but there is nothing like gensym in Java, C, C++, Python, Javascript, or any of the other languages I've used, and I've never seemed to need it. Why is it necessary in Lisp and not in other langauges? For clarification, I'm learning Common Lisp.

sbcl run-program hang when there is large amount of output from program

common-lisp,hang,sbcl
Recently I find a run-program hang issue of sbcl 1.2.7 (32bits, linux). The code as following (progn (with-open-file (s "test.out" :direction :output :if-exists :supersede) (loop repeat 900 do (write-line (make-string 76 :initial-element #\x) s))) (run-program "/bin/bash" (list "-c" "cat test.out") :output :stream)) That is when the "cat test.out" produce many...

Documentation for CL's loop macro

loops,documentation,lisp,common-lisp
I'm looking for official documentation for the common lisp loop macro, but all I can find are tutorials and examples. Where can I find this documentation?

Common Lisp object setter function style

coding-style,common-lisp
I am attempting to write a function that takes a list of user-defined objects called nodes to generate connections between them. Each node object has a slot for its unique number ('num') and a slot for a list of numbers that act as the edges between nodes ('edges'). +max-edges+ is...

Can't get the post in LISP hunchentoot

post,lisp,common-lisp,hunchentoot
I try to implement a simple post example based on Hunchentoot. Here is the code: (define-easy-handler (test :uri "/test") () (with-html-output-to-string (*standard-output* nil :prologue t :indent t) (:html (:body (:h1 "Test") (:form :action "/test2" :method "post" :id "addform" (:input :type "text" :name "name" :class "txt") (:input :type "submit" :class "btn"...

Why does a macro that uses “let” expand differently from one that doesn't?

macros,lisp,common-lisp,let
I am new to Lisp and I am reading through Doug Hoyte's Let Over Lambda and he presents Paul Graham's nif macro in Chapter 3. I was playing around with that and made these two macros: (defmacro niffy (expr pos zero neg) `(cond ((plusp ,expr) ,pos) ((zerop ,expr) ,zero) (t...

Modify list and return it inside a function in lisp

lisp,elisp,common-lisp
(defun testthis (node index newvalue) (set-nth node index newvalue) node ) I would like to modify the nth element of a list in a function and then returns this list to save the modification performed. How can I do a such function in lisp?...

Common Lisp Object System method execution order

lisp,common-lisp,clos
I have the following two classes: (defclass person () ()) (defmethod speak ((s person) string) (format t "-A" string)) (defmethod speak :before ((s person) string) (print "Hello! ")) (defmethod speak :after ((s person) string) (print "Have a nice day!")) (defclass speaker (person) ()) (defmethod speak ((i speaker) string) (print "Bonjour!"))...

Can CONS objects be used as a key to a hash table?

lisp,common-lisp,gnu-common-lisp
I've been playing with LISP lately, and I want to attempted to optimize a terribly inefficient recursive function by caching it's output so it only runs each combination of parameters once. I want to save the results into hash table, using either (LIST a b) or (CONS a b) as...

Appending to the result of a “loop-collect” in Lisp

loops,lisp,common-lisp
Let's say I run the following (loop for i to 4 collect i) Then I get a list (0 1 2 3 4). Now, if I want to append something to the result, I may use rplacd on its last element, but since Lisp lists are linked lists, it's not...

What's the difference between (list nil) and '(nil) in Lisp? [duplicate]

lisp,common-lisp,literals
This question already has an answer here: Why does this function return a different value every time? 4 answers Unexpected persistence of data [duplicate] 1 answer First of all, let me say I'm a beginner in Lisp. To be honest I have been a beginner for some time now,...

SBCL Run Shell Command

python,shell,lisp,common-lisp,sbcl
I've seen Executing a shell command from Common Lisp and its answers, but I'm still not sure whether SBCL provides a way execute shell commands from code. The SBCL Manual does support POSIX, but I was hoping for something a bit more higher level. Specifically, I want to call a...

lisp remove a the content of one list from another list

lisp,common-lisp
I have a list of string like this called F: ("hello word i'am walid" "goodbye madame") => this list contain two elements of string and I have another list call S like this ("word" "madame") => this contain two words now I want to remove the elements of the list...

Need help getting CLisp to read standard input into a list

python,lisp,common-lisp,clisp
I'm working on converting some existing Python code to CLisp just as an exercise ... The program reads a list of numbers and creates mean, min, max and standard deviation from the list. I have the file-based function working: (defun get-file (filename) (with-open-file (stream filename) (loop for line = (read-line...

What does backtick mean in LISP?

lisp,common-lisp,backticks
I have this macro, which rewrites define. If I remove the " ` " backtick it won't work. What is the explanation? (defmacro define ((name &rest r) body) `(defun ,name ,r ,body)) ...

Format both an expression and its result without eval

common-lisp,eval
I am trying to format an arbitrary expression, say (+ 2 3), and at the same time, its result, 5. I have the following: (defun expr-and-result (expr) (format t "~a returns ~a~%" expr (eval expr))) CL-USER> (expr-and-result '(+ 2 3)) (+ 2 3) returns 5 Though it's a simple matter...

cffi function call hangs

common-lisp,sbcl,cffi
I want to use stat(2) from Common Lisp. I've defined the structs used by the stat function: (cffi:defctype mode_t :unsigned-int) (cffi:defctype ino_t :unsigned-int) (cffi:defctype dev_t :int) (cffi:defctype nlink_t :int) (cffi:defctype uid_t :unsigned-int) (cffi:defctype gid_t :unsigned-int) (cffi:defctype off_t :int) (cffi:defctype time_t :long) (cffi:defctype blksize_t :unsigned-int) (cffi:defctype blkcnt_t :int) (cffi:defcstruct stat (st_dev...

Macro that defines functions whose names are based on the macro's arguments

macros,common-lisp,symbols,sbcl
*Note: Despite having frequented StackOverflow for a long time, this is the first question that I have posted myself. Apologies if it's a bit verbose. Constructive criticism appreciated. When I define a struct in Common Lisp using defstruct, a predicate function is automatically generated that tests whether its argument is...

Difference between CDR, CAR and REST, FIRST and possible implementation?

list,lisp,common-lisp,cons,cdr
I'm learning a little bit about functional programming in LISP and here's what I've bumped into: LISP uses CAR, CDR functions as well as FIRST and REST functions. Both related to lists. From what I've learned so far, there's a difference between these two, but I don't quite see what...

What does the non-terminating-p argument of set-macro-character do?

macros,common-lisp
Set-macro-character has an optional argument called non-terminating-p. It seems to be used to indicate whether another character should be read after reading the macro character, but the reader algorithm seems to ignore this argument. Is there a difference whether I set it to true or false?

How to use grid:slice in LISP?

common-lisp,sbcl
When I do : (grid:subgrid #( 1 2 3 4) '(1) '(2)) , i get 3. But when I do: (grid:subgrid #( 1 2 3 4) '(1) '(* 2 1)) ,i get the following error: #<TYPE-ERROR expected-type: LIST datum: 2>. Does anyone have a hint?...

Lispy way of running a function multiple times

common-lisp
I am using a function d to generate random numbers which I collect in a list and then average them: (/ (apply #'+ (list (d 6) (d 6) (d 6) (d 6) (d 6) (d 6))) 6.0) I would like to run the function (d n) i times, add the...

lisp: dynamic scope vs explicit parameter passing

design-patterns,coding-style,common-lisp,anti-patterns,dynamic-scope
I see two different patterns for "output" functions in (common) lisp: (defun implicit () (format t "Life? Don't talk to me about life!")) (defun explicit (stream) (format stream "This will all end in tears.")) (defun test-im-vs-ex-plicit () (values (with-output-to-string (stream) (let ((*standard-output* stream)) (implicit))) (with-output-to-string (stream) (explicit stream)))) Is using...

Read-line from socket-stream in lisp

sockets,tcp,lisp,common-lisp,usocket
I am working on a TCP client in lisp, and am having difficulties reading/printing the socket-stream correctly. When the client sends data to the server it should receive a response, and I need to write this to stdout. This works correctly, except I am having an issue where the response...

Simulate scheme define in common lisp

scheme,lisp,common-lisp
I wonder how to simulate the scheme define in common lisp,and want to write a macro for simulate the define. So what's the different between cl's defun deparameter defvar and scheme's define ,and how i can do this?

pathnames in Common Lisp, filenames with wildcards in them

common-lisp,filenames,wildcard,clisp,pathname
The characters * and ? are used as wildcards in pathnames. How does one refer to a filename that has ? as one of its actual characters? For example: [18]> (wild-pathname-p #p"foo") NIL [19]> (wild-pathname-p #p"foo?") T So referring to the filename "foo?" cannot be done this way. I tried...

Weird non-lisp errors with capturing labels with a lambda and `reduce`

lambda,crash,closures,common-lisp,allegro-cl
I stumbled across a very weird bug (?) while I was developing an application in Allegro Common Lisp, v9.0 for Windows. I do not get the regular lisp errors, instead I get system errors encapsulated in a lisp condition. I managed to create a simple test-case to reproduce the error...

LISP: Why doesn't mapcan accept my list give as parameters?

list,parameters,lisp,common-lisp,clisp
To simplify my question: why this works (mapcan #'(lambda (l) (list '1 '2) ) '(a b)) and this doesn't (mapcan #'(lambda (l) '(1 2) ) '(a b)) ? I have to write a function that substitutes an element through all elements of list D at all levels of a given...

Running compiled lisp program with clisp-2.49 on OS X

common-lisp,clisp
I have just started out programming in Common Lisp using GNU clisp-2.49 (compiled from source) as my implementation on OS X 10.10 Yosemite. I've written a simple "Hello World" program as follows: (EXT:SAVEINITMEM "test" :INIT-FUNCTION 'main :EXECUTABLE t) (defun main () (format t "Hello World!") (EXT:EXIT)) When I run: $...

Convert lisp function to use map

lisp,common-lisp
Hello I am looking forward to convert my existing function: (defun checkMember (L A) (cond ((NULL L) nil) ( (and (atom (car L)) (equal (car L) A)) T ) (T (checkMember (cdr L) A)))) To use map functions, but i honestly cant understand exactly how map functions work, could you...

SBCL: Deploying Hunchentoot application as executable

common-lisp,executable,sbcl,hunchentoot
Dear StackOverflow community, I started playing with SBCL Common Lisp and want to develop a small web application using Hunchentoot. For easy deployment I planned to save everything in a binary using sb-ext:save-lisp-and-die as I can live with the big output size. For the executable you need to supply a...

Dynamic 2d array in lisp

common-lisp,clisp
I want to have a 2D array in Lisp . But each row can have different number of elements(At max 5). So I thought of maintaining another single list to store the current sizes of each row, and update them whenever required. So, my code goes like this : (setq...

No-argument (and) returns t

clojure,scheme,lisp,common-lisp
Both CL and Scheme define (and) to return t (or #t) with no arguments. I'm trying to understand the rationale for this. My naive assumption is that an empty set is false, and passing in zero arguments feels like passing in nothing that can be true. Edit: clojure follows the...

How are `tagbody` and `go` implemented under the hood in Common Lisp?

compiler-construction,common-lisp
How are tagbody and go implemented in Common Lisp? Is it some form of setjmp/longjmp or is there a more elegant way of handling this? I'm writing a lispy language implemented in C and would like to have something like this....

Updating the window in response to CLIM frame commands

common-lisp,clim,mcclim
While trying to figure out CLIM, I ran into this example program. It's a simple maze game. The author claims to have tested it in LispWorks (and even has #+Genera in there, implying that this program would work on a real Lisp Machine), but I'm trying to get it working...

Common Lisp: predicate returns an error when given a function as a parameter

common-lisp
Just started playing around with Common Lisp (with L(λ)THW), and typed in (atom atom) expecting to get nil as a result. But instead I got the error ERROR[!]: Variable `ATOM' is unbound. The same result is when I try to "feed" any function to any predicate, as far as I...

How would I get the min/max of a list using a key

lisp,common-lisp
I currently have a list of objects, each containing a certain attribute. I would like to get the element of the list with the min attribute value. Is there a concise way of doing this? The python equivalent would be something like: min(d, key=d.get) Is there a way of getting...

How to use do in lisp?

function,lisp,common-lisp
What I'm trying to do is to write a function that which will restart a game of tic-tac-toe after it ends. What is supposed to happen is that the player will be asked if they want to play another game. If they do, then they click yes and a function...

Trying to multiply all elements in a list of sublists with elements in another list in lisp

list,common-lisp
I'm trying to multiply a list with n sublists with a list with n scalars. It's supposed to work like this: (kmult-matrix '((3 4 2 4) (2 5 6 9) (1 -2 8 10)) '(2 3 5)) => ((6 8 4 8) (6 15 18 27) (5 -10 40 50))...

Parenscipt not compiling valid expression?

common-lisp,hunchentoot,parenscript
I have this parenscript macro: ;;; Parenscript macro for showModal() and close() methods for pop-up dialogs. ;;;Takes the dialog's id, button for opening the dialog's id, and closing button's id. (defpsmacro open-close-modal-dialog (dialog-id element-id-1 element-id-2 &key open close open-args close-args) (let ((dialog (ps-gensym))) `(progn (setf ,dialog (chain document (get-element-by-id ,dialog-id)))...

Create an array of single-float from double-float in lisp?

lisp,common-lisp,sbcl
When I try to create a single-float array like this, i get: (make-array 2 :element-type 'single-float :initial-contents #(3.0 4.0)) , i get the following error: The value 3.0 is not of type SINGLE-FLOAT Is there a way to create a single-float array from a simple vector of double-float?...

Lisp - append to a list

lisp,common-lisp
I am new to lisp. I didn't properly understand how to implement append function on a list. I tried the following program. (defvar temp) (setq temp '()) (append temp (logxor 1 0)) temp seems to store only NIL value when it should be storing 1 in it. ...

How can I specify the package name when launching a Lisp program from the command line?

shell,batch-file,common-lisp,gnu-common-lisp
I'm calling a Lisp function (and a few other thing) from a shell script. For brevity, below is relevant part of the script : ./gcl -load /tmp/calendrica-3.0.cl -batch -eval '(format T "~a" (CC3::sunset (CC3::fixed-from-gregorian (CC3::gregorian-date 1996 CC3::february 25)) CC3::jerusalem))' 728714.7349874675 The above code works fine but I had to append...

LISP compare two lists using a loop

list,loops,common-lisp
I'm writing a simple function to loop through a pair of lists and return a true or false for each element as to whether either of the symbols is F. This is at the end of a long string of functions and input will look as follows: '(F E E...

LISP: read number from user and commpare with array index

functional-programming,lisp,common-lisp
Hello guys I'm new In functional programming Really it is not Clear for me anyone can help me ? My Question just for getting the philosophy of writing on Functional programming language for example how I can write a program in Lisp language for reading the user inputs and compare...

How do I best save/read data structures?

common-lisp,clos
I want to write some data structures pointed to by FOO and BAR to a file, and to read the data structures back into the symbols FOO and BAR when I start a new session of Common Lisp. It would appear *PRINT-READABLY* allows objects to be printed in a fashion...

Write fast Common Lisp code [closed]

common-lisp
I'm not sure, if some weird things make my Code faster: Is it normally better to use inbuilt operations or write new specialized functions, that do the same thing? (for example a version of #'map only for vectors; my version is often faster without type declarations) Should I define new...

LISP Easy questio about creating new lists

lisp,common-lisp
A function that receives a list with sublist's M*N and returns the sum of all elements of the sublist's example: (solution '( (1 2 3) (4 5 6) ) ) return: (5 7 9) Sry for the bad english thks =)...

Defmacro that expands to defsetf

macros,lisp,common-lisp,backticks
I'm having some trouble with some nested backquotes in CL. I'm trying to create a macro define-access that takes two parameters, F and A. define-access should define a function and setf expansion for symbol F that acts just like the respective function and setf for A. The current code is...

How to return the value and name of a variable in Common Lisp

lisp,common-lisp
I'm trying to write a macro to return a variable's name and value in common lisp. How do I return the name and value of a variable in a LISP macro? So something like (RETURNVAL (x)) would return x has value 5...

If strings are vectors, why are they immutable?

lisp,common-lisp
if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?

Finding deepest node in a tree (Lisp)

tree,lisp,common-lisp,tree-traversal,postorder
I am wanting to go through a tree in lisp and find the deepest (or furthest from the root node) by using a tree in the form of a list. So far my idea has been to keep on cutting the tree into left and right sub trees (assuming that...

How to use a parameter in a macro call?

macros,lisp,common-lisp,sbcl
I have defined the following simple macro: (defmacro define-class (class-name) `(defclass ,class-name ()())) And now I want to use it in the following function: (defun create-data (mode) (define-class mode)) After compiling the last function I get the following message, the variable MODE is defined but never used. And when I...

Subqueries with select function in CLSQL

postgresql,common-lisp,clsql
I'm attempting to create a subquery with the clsql:select function: CL-USER> (select [books.bookid] :from [books] :where (sql-in [books.bookid] (select [bookid] :from [bookauthors] :where (sql-= [bookauthors.authorid] 120)))) ;; 2015-03-07T06:37:08 /books/ => SELECT BOOKID FROM BOOKAUTHORS WHERE (BOOKAUTHORS.AUTHORID = 120) ;; 2015-03-07T06:37:08 /books/ => SELECT BOOKS.BOOKID FROM BOOKS WHERE (BOOKS.BOOKID IN ((157)))...

Basic idea of Lisp Macro

macros,lisp,common-lisp
I try to do a very simple thing in Lisp - to find a way to turn on a global valuable nodebug t and then some of debug format form would be silence. To do that, I found I cannot grasp the difference of the following: (defparameter *nodebug* t) (setf...

Common Lisp: How to quote parenthese in SBCL

lisp,common-lisp,sbcl,quote
In Common Lisp, the special operator quote makes whatever followed by un-evaluated, like (quote a) -> a (quote {}) -> {} But why the form (quote ()) gives me nil? I'm using SBCL 1.2.6 and this is what I got in REPL: CL-USER> (quote ()) NIL More about this problem:...

Common Lisp: What does #+nil?

common-lisp
The other day (perhaps yesterday) I was quite perplexed about this #+nil read-time conditional found in https://github.com/billstclair/defperson/blob/master/defperson.lisp#L289. After some deep thinking I came to the conclusion that this is very lispy way of commenting out code. Can someone confirm this? Perhaps my assumptions are completely wrong. Anyway, thanks in advance....

LISP Function that Returns True If Atom Is In List

list,recursion,lisp,common-lisp
I'm trying to write a function (deep-find) that takes in a list and another argument and returns T if that argument is present in the list. For example, if I called (deep-find '(A B (C D)) 'C) it should return true, but if I called (deep-find '(A B (C D))...

Read input into string in Lisp reader macro

macros,common-lisp,reader-macro
I am trying to make a reader macro that would convert @this into "this". This is what I currently have: (defun string-reader (stream char) (declare (ignore char)) (format nil "\"~a\"" (read-line stream t nil t)) ) (set-macro-character #\@ #'string-reader ) The problem is that this requires that I put a...

How can I modify function bindings in Common Lisp?

variables,binding,scheme,lisp,common-lisp
Here is something you can do in Scheme: > (define (sum lst acc) (if (null? lst) acc (sum (cdr lst) (+ acc (car lst))))) > (define sum-original sum) > (define (sum-debug lst acc) (print lst) (print acc) (sum-original lst acc)) > (sum '(1 2 3) 0) 6 > (set! sum...

Common-LISP debugging (code included)

debugging,lisp,common-lisp
I hope to get a quick fix to my code, which takes in a list of numbers, numberlist, and a threshold and return the number of items in numberlist that are greater than threshold. I just can't figure out what's wrong, and I am not familiar with debugging. I am...

Differences between Sharpsign Colon and Gensym

common-lisp,reader-macro
I've just been reading up on the sharpsign colon reader macro and it sounded like it had a very similar effect to gensym Sharpsign Colon: "introduces an uninterned symbol" Gensym: "Creates and returns a fresh, uninterned symbol" So a simple test CL-USER> #:dave ; Evaluation aborted on #<UNBOUND-VARIABLE DAVE {1002FF77D3}>....

How to get the POST as parameter of a function in Hunchentoot?

post,common-lisp,sbcl,hunchentoot
I want to use a web formular to filter records stored in mongo-db. My query function uses a filter as followed: (defun models (filter) (docs (db.find *model-collection* filter :limit 1))) And when I use it in SBCL, it can retrieve the record {"NAME" :"a1"}, with one of the following command:...

Char Comparison in Common Lisp

sorting,char,comparison,lisp,common-lisp
How can i compare characters with Common Lisp? I have google it and found out that there are some functions to do the comparison, like char=, char/=, char<, char>, char<=, and char>=. But, i can't use all of the functions just like: (char= 'a 'a) (char< 'a 'b) If i...

Backquote String Interpolation

macros,lisp,common-lisp
Is it possible to use lisp's macro to do string interpolation? For instance, can I make a macro like this: (defmacro test (a) `",a") So that (test abc) returns "abc" as a string? I could probably cheat by quoting it and turning that quote into a string, but that doesn't...

Get element from list of list in lisp

lisp,elisp,common-lisp
I am a beginner with lisp. I manipulate list of list: ((name1, second) (name2, second2)) The goal of my function is to get the second element of the list that have name as it first node. For example: my list is: ((name1, second1) (name2, second2)) getelement list name1 should return...

Structuring large Lisp applications

lisp,common-lisp,quicklisp,asdf
I am currently trying to wrap my head around packages, systems & co. I now have read Packages, systems, modules, libraries - WTF? a few times, and I think I'm still having difficulties to get it right. If I simply want to split a Lisp source file into two files,...

Common Lisp - Writing a function that detects circular lists

list,function,recursion,lisp,common-lisp
I have an assignment for my CS functional languages class where we must write a function able to detect whether or not a given list is circular at its beginning. The function has to be recursive. Let's name it circular : * (setf list1 '(a b c d)) * (rplacd...

How to use FFI:def-call-in in clisp

lisp,common-lisp,ffi,clisp
I have figured out how to make use of shared objects created from C code into Clisp using FFI:def-call-out but I am not able to figure out how to use FFI:Def-call-in. I don't know the process and actually I am confused if clisp will also create some .so file that...

In Common Lisp, how to test if variable is special?

common-lisp
I thought I would be able to find this through Google, SO, or the books I'm reading, but it is proving elusive. In the implementation I'm learning with, I can do the following at the top-level: (defvar *foo* 4) (set 'bar 3) If I then call (describe '*foo*) and (describe...

Local dynamic binding in common lisp

closures,common-lisp,dynamic-binding
Honnestly, I'm not sure I fully understand what it means for a binding to be "dynamic" versus "lexical". But I understand that when I use defvar or defparameterto define a binding, 1. it declares a global variable 2. the binding is declared "special", so that it can be shadowed by...

Invalid specialized parameter in method lambda list

lisp,common-lisp
I am trying to write a simple coin flip program in Common Lisp. This is the code I have (defun yn (let ht (random 1) (if (eq ht 1) (princ heads) (princ tails)) ) ) It seems simple enough, but I keep getting the error: "Invalid specialized parameter in method...

Parsing a comma separated string in lisp

lisp,common-lisp
I am trying to parse a comma separated string with Common lisp with the function below. For (separate-on-comma "a,b,c") I would expect the output ("a" "b" "c") but instead I get ("c" "c" "c"). What do I miss here? (defun separate-on-comma (line) (loop with fields = () with field =...

Not numeric atoms LISP

lisp,common-lisp
I want to ask why this function doesn't work... (defun nenum(ls) (cond ((null ls) nil) ((listp car(ls)) (nenum (rest ls))) ((numberp car(ls)) (nenum (rest ls))) (t (cons (car ls) (nenum (rest ls)))))) Example: (nenum '(l 1 i (b) (5) s -2 p)) --> (l i s p) Thank you!...

Long integer to string and vice versa, operation with digits

common-lisp,sbcl
Solving the Euler project problems I get that I need to make operations with the digits of a long number normally as a string. I work in linux, emacs, slime with sbcl. For example, to get the sum of the digits of this power 2¹⁰⁰⁰, I work this way, 1)...

Replacing symbols in a (nested)? List in LISP

common-lisp
I am supplying a list in the following format: (test '((Q H)(A D)(J C)(Q S)(3 S))) The aim is to to search through the list and replace the symbols J Q K and A with the respective numbers 11 12 13 and 14. Currently my function is this (I'm sorry):...

EMACS-Live + Slime error at startup

emacs,common-lisp,slime,kubuntu
Ok, I must be missing something obvious. I'm getting stuck since yesterday to launch Emacs-live + slime. I'm using EMACS 24.3.1, installed Emacs-live and it worked well (if I start emacs-live without Slime it works), downloaded Slime-Pack from git and added this line to .emacs-live.el (live-append-packs '(~/.live-packs/slime-pack/)) I'm on a...

Is there a way to insert raw javascript in parenscript code?

common-lisp,parenscript
The following code inserts third-party generated javascript as a string which will need to be eval'ed. (ps (let ((x (lisp (json:encode-json-alist-to-string '((:a . 1) (:b . 2)))))))) "(function () { var x = '{\"a\":1,\"b\":2}'; return null; })();" Is there a way to tell parenscript to insert a string unquoted?...

LISP macro fail, crashes slime

lambda,macros,lisp,common-lisp,slime
I am using common lisp with slime in emacs and am trying to define a simple macro. However when I run the macro, the emacs slime buffer becomes unresponsive and my computer quickly becomes unusable. Even after exiting emacs I get error messages at the bash prompt about not being...

SBCL: Gather output of run-program process while running

subprocess,common-lisp,sbcl
Dear StackExchange members, I recently began toying around with Common Lisp and want to create a web interface for administrating a modded Minecraft server. I already tried out this solution but in this case the function just hangs and never returns. My code looks like this: (defvar *proc*) (defun create-minecraft-proc...

where is the text printed by C printf

io,common-lisp,cffi
I happened encounter a trouble with calling C printf function from SBCL via cffi. The problem is when I call printf function, I can't find the output text, just the return value of printf function show on the REPL. But when I quit SBCL, the output text appears on the...

How to get class information in Common Lisp?

common-lisp
For example, I want to see a list of available accessors of a slot from the REPL instead of jumping to the source. How do I do that?

Any ways to allocate flattened array of structure as C in Common Lisp?

arrays,common-lisp
Are there any ways to allocate flattened array of structure (AOS) for efficiency in Common Lisp? What I mean is the following C equivalent. typedef struct { int x; float y; double z; } foo_t; #define SIZE 1000000 void bar() { foo_t *f = malloc( sizeof( foo_t ) * SIZE...

What is a common-lisp analogue of python's argparse?

python,common-lisp,argparse
What is a common-lisp analogue of python's argparse library for parsing command-line arguments?

EVAL/APPLY: too many arguments given to F

lisp,common-lisp,clisp
Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list. (defun f (L) (cond ((NULL l) nil) ((listp (car L)) (append (F(car L))) (F(cdr L) (car (F...

Common Lisp - Giving &rest Lists as Arguments

arguments,lisp,common-lisp,sbcl
As a result of musings around an exercism problem, I am trying to write a function that takes an input number and an arbitrary length list of divisors to test, along with the expected divisibility (i.e. remainder 0) as a boolean, returning true if all expectations are met (defaulting to...

How to move a file in Lisp using rename-file

lisp,common-lisp,pathname
What's the best way to move a file in Lisp in an implementation-independent way? For example I have an image file: (setq oldpath #P"SERVER:PICTURES;TEMP;PHOTO.PNG") and I want to move it out of the TEMP directory into the PICTURES directory. This seems to work: (setq newpath (make-pathname :host (pathname-host oldpath) :directory...

What's the simplest Common Lisp idiom for queued execution of function calls?

common-lisp,sbcl
For instance, if I have a database, and the client code queries the database in a rather uniform fashion (through a wrapper macro), how would I go about putting the queries in a queue so that the queries are executed in order, the next running after the last has completed....

Insertion into a list doesn't reflect outside function whereas deletion does?

list,lisp,common-lisp
I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...