Questions tagged [common-lisp]
Common Lisp is a standardized version of the Lisp programming language intended for production-strength power.
5,892
questions
0
votes
1
answer
34
views
I get an error saying (*** - Lisp stack overflow. RESET) when I try Sorting a list using Binary Search Tree Traversal In order in Common Lisp
I get the error mentioned in the title when I try to run my code with an example (included in the code provided below). I can not figure out where the issue is. Help is highly appreciated
Code:
(defun ...
2
votes
1
answer
37
views
ASDF throws system-out-of-date condition
I'm using ASDF load cl-ppcre in a script file. The issue is (progn (require :asdf) (require :cl-ppcre)) is perfectly fine in a top level, but if the same codes wrapped in a handler-case, a system-out-...
0
votes
1
answer
33
views
Is there any pratical difference for atom and null in Common Lisp if they receive a list as an argument?
I am using SBCL, Emacs, and Slime. According to the book Symbolic Computation: A gentle introduction to Common Lisp, the definition of atom is:
The ATOM predicate returns T if its input is anything ...
0
votes
1
answer
39
views
Is there a way to tweak Common Lisp dotimes macro so that it does not start from zero but from a different number, such as 1?
I am using Emacs, Slime, and SBCL.
The default use of dotimes is:
CL-USER> (defun my-dotimes (n)
(dotimes (i n)
(format t "~s ~%" i)))
Which generates:
CL-USER>...
0
votes
2
answers
37
views
How does a Lisp macro extend the syntax and semantics of the Lisp programming language?
A book [1] that I am reading says this:
One of the most interesting developments in programming languages has
been the creation of extensible languages—languages whose syntax and
semantics can be ...
-1
votes
1
answer
66
views
A Common Lisp reference for finding and learning about built-in functions
I am learning Common Lisp, and I cannot for the life of me find a reference (other than textbooks) for quickly looking up what functions do, or whether a function exists. For example, if I want to ...
1
vote
1
answer
53
views
How do I evaluate form inside lambda that is within a macro?
I'm having problems with the following macro:
(defmacro gather-params (&rest body)
"Return plist of params"
`(concatenate 'list
(map 'list
#'(lambda (plist)
...
3
votes
0
answers
46
views
How to list all files in a directory as ASDF defsystem static-files
From How to specify additional files as prerequisites that would cause ASDF to recompile the program, I learned that the ASDF static-file directive can be used to list non-Lisp files that a Common ...
0
votes
2
answers
60
views
In Common Lisp (SBCL) how do you parse a file?
I have a file: test.lisp with this content:
(+ 3 3)
(let ((n 3)) (+ n 1))
(let ((n 4))
(+ n 1))
(defun d (f)
(let ((n 3)
(f 4)
(g 3))
(if (= n 0)
(+ n f g)
(* n f g))))
I ...
-1
votes
2
answers
97
views
Adding List items together while using provisional result
I have the following list:
((a b) (c d) (e f))
and want to loop through it and combine the list elements together. I also have the loop for that, which works exactly like I want to:
(loop for (x . ...
1
vote
1
answer
50
views
Adding List Items together
I have a list and I want to add/concatenate the elements.
((a b) (c d) (e f)) -> ((a b c d) (a b e f) (c d e f))
This is what it should look like. The List ist never of fixed size, so it could ...
0
votes
1
answer
63
views
Why is common lisp's `set-difference` not working? [duplicate]
So, I am trying to use set-difference in Common Lisp (sbcl) and it doesn't really work on lists of structures.
For example,
* varr ;; =>
(#S(VAR :V S) #:$K520)
* pm ;; =>
(#S(VAR :V +) #S(VAR :...
1
vote
3
answers
64
views
What is the difference and the relation between the Lisp interpreter and the Lisp image? Can they be used as synonoms?
I noticed some people using the terms as if they were synonoms.
For instance, in the same scenario, I heard "add this function to the lisp image evaluating it" and "eval this function ...
2
votes
1
answer
42
views
How to specify additional files as prerequisites that would cause ASDF to recompile the program
I have written a program that uses read-time evaluation to read strings contained in text files. In this example, the text files are 1.txt and 2.txt, both of which contain text that will be read ...
0
votes
0
answers
29
views
Hunchentoot, send parameters with redirect or (:a href...)
I am new to building web pages in Lisp, and the question may be stupid, but I am building a web page with Hunchentoot without a framework, and I have a html page in which I will display a list of ...
-1
votes
1
answer
42
views
How to make a new list with 2 positions of a list changed?
I am a complete newbie in LISP (Common lisp to be exact) and I need to make a function where i can pass the list and 2 arguments, pos1 pos2, that are the elements position in a list, the function ...
1
vote
1
answer
40
views
Writing a JSON string from a common lisp data structure
I am trying to create a Common Lisp data structure to output some nested JSON like so:
{
"array_of_objects": {
"item1": {
"foo": {
"value": &...
3
votes
0
answers
73
views
Drawing a rectangle using CLX
I am trying to draw a rectangle inside a window using Common Lisp X Interface:
(asdf:load-system "clx")
(in-package :xlib)
(defun main ()
(let* ((display (open-default-display))
...
2
votes
1
answer
43
views
Is it valid to have NIL as an argument in the string comparison functions?
I am wondering whether or not (string= "abc" nil) is valid in Common Lisp. I noticed that SBCL does not complain even though nil is not a string. (string= '() nil) returns T although both ...
2
votes
1
answer
67
views
How to redirect to HTTPS when Hunchentoot is behind a reverse proxy
I have a Hunchentoot application running on http://localhost:4242. This application uses a non-SSL acceptor (i.e. hunchentoot:easy-acceptor instead of hunchentoot:easy-ssl-acceptor). I set up Nginx as ...
1
vote
0
answers
41
views
Cannot run Common Lisp code on Jupyter Labs
I just installed the Common Lisp kernel on Jupyter but I cannot run even the simplest function.
For example, when I run:
(+ 2 3)
I get the following error output:
SIMPLE-PROGRAM-ERROR: invalid number ...
1
vote
0
answers
46
views
Why can't I access my lisp server when launched from the emacs repl
I have a lisp xml-rpc server. When I launch it from a repl in a terminal, the server responds to the client's requests but when this server is launched from the sly repl in Emacs, the client is stuck ...
1
vote
2
answers
102
views
Order Lists by CAR
I need to be able to compare two cars of a list to sort them im LISP.
Lists '(e d) (a b)
I want to compare the cars (e and a). This works using eql. If they don't match, I want to order the lists ...
0
votes
4
answers
94
views
How to convert this function into a Common Lisp macro that has a variable number of cond clauses?
I am using Emacs, Slime, and SBCL. Simplifying a problem that I am facing, suppose I have this function working:
(defun get-answer (x y z)
(format t "Which animal would you like to be: ~s ~s ~s ...
0
votes
2
answers
29
views
While refactoring this Common Lisp code snippet, how to succesfully remove the cond clause wrapping a handler-case (error handling) situation?
I am using SBCL, Emacs, Slime, and Dexador (a library for HTTP requests). I have this function that works:
(defun old-handle-response-and-status (final-url method &optional user-content)
(let ((...
0
votes
3
answers
44
views
In Common Lisp, how to use lexical scope and funcall to make another function be passed as an argument?
I am using SBCL, Emacs, and Slime. Hence, I can do:
CL-USER> (defvar example #'(lambda (x) (* x 20)))
EXAMPLE
CL-USER> (funcall example 10)
200
Ok. It works as expected. Using the library ...
0
votes
1
answer
51
views
Why does set-difference in sbcl common-lisp appear to be destructive?
The following code snippet compiles under SBCL 2.2.3 (using Emacs/SLIME, C-c C-k), and the .fasl is loaded without errors.
On a subsequent call to test-sets in the REPL, the value of *evens* is set to ...
1
vote
0
answers
50
views
How to do pattern matching with trivia (Common Lisp/sbcl)?
I want to use the trivia library and I am using SBCL.
I want to be able to match a Scheme expression:
(match '(let ((n 2)) (* n 2))
((letp a b) (list a)))
(defun letp (exp)
(and (lisp exp) (equal ...
0
votes
2
answers
49
views
Can the way in which a function is called depend on its arguments?
In Common Lisp, is there a way for an argument to a function to determine how the function is called, in the following sense? Let's say we have a function which has alredy been defined, say (defun foo ...
1
vote
1
answer
39
views
Portacle Common Lisp connection to Swank Hangs
I have a Portacle installation on Windows 10. Sometimes it works properly, sometimes it doesn't. The problem occurs when Portacle is started and it attempts to connect to Swank. Emacs freezes, and I ...
1
vote
2
answers
61
views
How to properly use Common Lisp's multiple-value-bind and handler-case on this HTTP-request interface?
I am using SBCL, Emacs, and Slime. In addition, I am using the library Dexador.
Dexador documentation provides an example on how to handle failed HTTP requests.
From the official documentation, it ...
1
vote
2
answers
58
views
Why did EVAL-WHEN with :LOAD-TOPLEVEL not run the body when I LOAD the file?
I have written this Lisp program:
(eval-when (:load-toplevel)
(princ "Hello!"))
However, when I load the program, the body of the eval-when is not run.
$ sbcl
* (load "hello.lisp&...
-1
votes
1
answer
86
views
What is the problem here? I was trying to increment value but it's giving output as 0
Been at this for hours, I'm new to LISP and could not figure out what is wrong with this. I'm trying to solve a matrix problem using backtracking. Can someone help?
(defvar m 3)
(defvar n 4)
(defvar M-...
3
votes
1
answer
55
views
How to produce double quotes instead of single quotes for XML attributes in CL-WHO
By default, CL-WHO uses single quotes for quoting XML attributes values (e.g. <h1 id='title'>Hello!</h1>). I am trying to set cl-who:*attribute-quote-char* to #\" so that attribute ...
2
votes
3
answers
71
views
How to identify the output of dex:get as being JSON or HTML in Common Lisp?
I am using SBCL, Emacs, and Slime. Moreover, I am using the library Dexador.
Thus, I can do HTTP requests. Some of them will return JSON:
CL-USER> (dex:get "http://ip.jsontest.com/")
&...
0
votes
2
answers
61
views
Return the longest sequence of consecutive numbers from list in lisp
I am a lisp newbie.
I'm trying to create a function in lisp that receives an unsorted list and the function has to sort de list and return a list with the longest sequence of numbers.
Example: (2 1 8 ...
0
votes
2
answers
105
views
trying to convert C to Lisp
I am trying to convert this code to lisp code.
But don't know how to do it
is it right?
for (j=i-1; j>=0 && list[j]>key; j--) {
list[j+1] = list[j];
}
(loop (set j (- i 1))
(setq (...
0
votes
1
answer
59
views
EVAL: undefined function X
I keep getting some random errors while trying to call my function that has to return
the level of a node from a binary tree.
This is my method
(defun nodeLevel(x index l)
(cond
((null l) ...
1
vote
3
answers
73
views
Why the use of `,@` does not work as I expected in this common lisp macro? Why is Slime returning this error message?
I am reading the book Lisp written by Winston. In addition, I am using SBCL, Emacs, and Slime.
In chapter 8 (about macros), the book has the following exercise:
Problem 8-7: A stack is a learnly ...
0
votes
3
answers
47
views
Why inserting `format` function inside a `dolist` expression does not work in Common Lisp?
I am using SBCL, Eamcs, and Slime. Using the print function, I can do:
CL-USER> (dolist (item '(1 2 3))
(print item))
1
2
3
NIL
In addition, format function works for single elements:...
0
votes
2
answers
107
views
How to convert this Common Lisp function into a macro?
I am using SBCL, Slime, and Emacs to develop in Common Lisp.
I have this function:
(defun build-cond-action-pairs (&rest var)
(labels ((aux (xs-left accu)
(cond ((null (cddr xs-left)...
2
votes
2
answers
67
views
Pop first element in a list using a macro
I have the following code
(defmacro popm(l)
`(prog1 (car ,l)
(setf ,l (cdr ,l))))
which is supposed to pop the first element out of the list. However, I don't know how to call the macro. I tried ...
1
vote
1
answer
70
views
Why is Common Lisp famous library Dexador not working for this HTTP POST request case? Is it a bug or did I miss something?
I am using SBCL, Emacs, Slime, and Dexador. I am also watching this course on Udemy about Postman.
At some point, the instructor presents a POST request that uses basic authentication. It is ...
-1
votes
2
answers
59
views
Emacs SLIME Common Lisp Undefined variable
I'm following Practical Common Lisp Chapter 3 codes.
I've save the following codes to an external files:
(defvar *db* nil)
(defun make-cd (title artist rating ripped)
(list :title title :artist ...
0
votes
3
answers
59
views
What is fundamentally wrong in the choice of data structure in this matrix addition code?
Section 2.2.4 here contains the following:
2.2.4 Totally Inappropriate Data Structures
Some might find this example hard to believe. This really occurred in some code I’ve seen:
(defun make-matrix (...
0
votes
2
answers
67
views
How to re-write this Common Lisp macro avoiding the back-quote notation?
I am trying to learn Common Lisp with the book Common Lisp: A gentle introduction to Symbolic Computation. In addition, I am using SBCL, Emacs, and Slime.
In the last chapter, on Macros, the author ...
1
vote
5
answers
121
views
How to use libraries in Common Lisp?
I'm a beginner in Common Lisp and I want to use a library.
I can't find a single one simple example of loading / requiring / using a module.
I've installed cl-ppcre like this :
$ sbcl --non-...
1
vote
2
answers
59
views
Portacle Lisp : Slime-repl-sbcl prompt keep auto-scrolling back
as the title said, I am learning common lisp right now and using portacle, following Practical Common Lisp by Peter Seibel.
I found it quite annoying that the Slime-repl-sbcl buffer keep the writing ...
-1
votes
1
answer
31
views
Augdentity Lisp Implementation
Given positive ints r and c indicating number of rows and columns, create a 2D list that represents the "augmented identity matrix" with that dimension: It's the r x c matrix of all zeroes, ...
1
vote
1
answer
57
views
How to convert a stringfied JSON from a no-indentation and escape backslashes to a beautifully indented and free of escape characters JSON?
I am using Common Lisp, SBCL, and a famous library called Dexador. The following s-exp:
CL-USER> (dex:post "https://html2json.com/api/v1"
:content (dex:get "https://...