Tagged Questions
1
vote
2answers
60 views
Evaluation of passed parameters inside macro body
I have a doubt on how parameters passed to the macros are getting evaluated, details below.
This macro is defined
(defmacro test-macro (xlist)
`(* ,@xlist))
and there is this global variable ...
1
vote
2answers
122 views
Common Lisp Macro Pattern match
Been working on a macro for homework a long time know but we are completely stuck, my teacher has limited time, and the deadline is far over the limit. This is our last try to solve this one.
The ...
0
votes
2answers
81 views
Iteratively create local variables?
I have created a function that takes an arbitrarily long list of numbers as an argument. From this list, I wish to create matrices locally using let. The matrices will have rows and columns based on ...
0
votes
3answers
91 views
Common Lisp: Controlling macro expansion time
I was working with common lisp, and found myself typing up slot definitions of the following form quite a lot:
(name :initarg :name :accessor name)
And so I thought to concoct a macro to speed up ...
3
votes
2answers
86 views
Quote a reader macro invocation
is there a way to quote an invocation of a reader macro? More specifically, I want to create a macro, that once evaluated, will generate a defclass statement and a respective XML file. Is this ...
0
votes
1answer
51 views
How to quote all items after comma-at them from a list
I want to expand (foo a b c d e ...) to ===> (bar 'a 'b 'c 'd 'e ...)
So far I only get this solution:
(defmacro foo (a1 &rest a2)
`(bar ',a1 '(,@a2)))
But it results in:
(foo a b c d) ===> ...
5
votes
2answers
134 views
Why does this Lisp macro as a whole work, even though each piece doesn't work?
I'm reading/working through Practical Common Lisp. I'm on the chapter about building a test framework in Lisp.
I have the function "test-+" implemented as below, and it works:
(defun test-+ ()
...
1
vote
1answer
98 views
How to modify this macro in common lisp to integrate collect in loop?
I have a macro below that iterates along bits in an integer. I would like to integrate the collect capability of the loop like this:
(loop for x in '(a b c d e)
for y in '(1 2 3 4 5)
...
6
votes
2answers
182 views
In Common Lisp why does the macro OR use a gensym, but not AND?
In Common Lisp (SBCL 1.0.58) why does the macro OR use a gensym, but not AND?
For example,
CL-USER> (macroexpand '(and 1 2 3 4 5))
(IF 1
(AND 2 3 4 5)
NIL)
T
...
2
votes
2answers
146 views
How could I implement the push macro?
Can someone help me understand how push can be implemented as a macro? The naive version below evaluates the place form twice, and does so before evaluating the element form:
(defmacro my-push ...
4
votes
3answers
183 views
Lisp: Macros vs Functions
In my quest to fully understand the so powerful lisp macros a question came to my mind. I know that a golden rule about macros is the one saying "Never use a macro when a function will do the work".
...
4
votes
3answers
184 views
Compiling Lisp code with read macros
I'm having a bit of trouble understanding what becomes of read macros when compiling a file of lisp code into a bytecode or raw assembly (or a fasl file for that matter). Or maybe I do understand it ...
0
votes
2answers
116 views
Common Lisp: Method to minimize code duplication when defining setf expanders
Triggered from this question about setf expanders: defining setf-expanders in Common Lisp
When writing setf expanders for user-defined getters, I commonly find that there is code duplication in the ...
1
vote
1answer
71 views
common lisp: eval a top-level form only once for a lisp session
I'm doing more interactive development with the REPL lately, and I have a section of code that pushes a symbol onto a global dynamic variable (a list data structure). Problem is, I find myself ...
3
votes
1answer
198 views
Eval-when uses?
After reading a lot of documentation regarding lisp eval-when operator I still can't understand its uses, I know with this operator I can control the evaluation-time of my expressions but I can't ...