46 questions
2
votes
2
answers
112
views
How to pass function to macro in common-lisp
I'm trying to wrap my head around macros in Common Lisp, and I have this piece of code to create synth-definitions with the cl-collider client for the supercollider sound synthesis language:
(defmacro ...
0
votes
3
answers
187
views
Common Lisp - Any ideas on how to write a "with-methods" macro similar to "with-slots"?
So my idea is to reduce the amount of calls to an object instance, when it is clearly the only one in scope.
Here's a code example:
(defun read-plist (plist)
(let ((plist-reader (make-instance '...
1
vote
1
answer
106
views
Common Lisp: How to use a macro within a macro?
I'm writing an application (a simple game) using cl-sdl2. cl-sdl2 includes a macro called WITH-EVENT-LOOP that can be used to start the SDL application with some event handlers.
Currently I use the ...
1
vote
3
answers
86
views
Is there a pattern for LOOP-like macro mini-languages?
I am attempting to answer the following exercise.
Write a macro function OUR-IF that translates the following macro calls.
(our-if a then b) translates to (cond (a b))
(our-if a then b else c) ...
0
votes
2
answers
170
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)...
0
votes
2
answers
142
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 ...
0
votes
1
answer
146
views
Generating cond's (test expression ...) in Scheme
I've been using Guile for about a year, but am fairly inexperienced in using macros in Scheme. Although I have got some more complicated examples to work satisfactorily, I'm getting stuck on what (to ...
3
votes
1
answer
896
views
How can I see expanded macros in racket?
I got this answer https://stackoverflow.com/a/70318991 about writing a simple macro that records the time at macro expansion time, and then always returns that time.
#lang racket
(begin-for-syntax
(...
1
vote
1
answer
282
views
looking for a really simple racket macro example
I did this:
#lang racket
(define-syntax-rule (macro-expansion-seconds)
(current-seconds))
which does this
> (macro-expansion-seconds)
1639244531
> (macro-expansion-seconds)
1639244532
> (...
2
votes
1
answer
161
views
When and how often do macro expansions happen in SBCL Common Lisp implementation?
Some Lisp implementations (i) expand macros once and save the result for
reuse; (ii) others reexpand the macro at each macro call. Some
implementations (iii) even attempt to expand macro calls in ...
0
votes
1
answer
132
views
Why does the compilation of a Common Lisp macro in my environment produce a different result from the book? Is it possible to achieve the same?
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 chapter 14, the last one, the author ...
0
votes
1
answer
336
views
Why this macro to pretty print macro expansions in Common Lisp does not work? What are the alternatives tools for this?
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 chapter 14, the last one, the author ...
1
vote
1
answer
218
views
Common lisp macro not calling function
I am working on a complicated macro and have run into a roadblock.
(defmacro for-each-hashtable-band (body vars on &optional counter name)
`(block o
(with-hash-table-iterator (next-entry ,...
2
votes
1
answer
364
views
Are lambda expressions macros or markers in Common Lisp?
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 chapter 7, the author suggests the ...
0
votes
1
answer
96
views
Extracting and executing a closure/lambda from a plist macro body
I'm trying to create a macro (bar) that should be used like this:
(let ((my-var "foo"))
(bar ("some")
:buzz (lambda () (format t "~a~%" my-var))))
The macro ...
0
votes
1
answer
151
views
Common Lisp Execute expression as parameter in macro
So using common lisp, I want to be able to do something of the sorts of:
(defmacro foo (count &rest someExpression)
`(do
((,count 0 (+ ,count 1)))
((= ,count 5) T)
`(...
1
vote
3
answers
277
views
Using loop inside defmacro
I'm learning (common) Lisp, and as exercise, I want to implement 'xond', a cond macro, that transform this silly example:
(xond (= n 1) (setq x 2) (= n 2) (setq x 1))
into a if-else chain:
(if (= n 1)...
3
votes
2
answers
369
views
Common Lisp locally shadow function with same name
I've had this question more than once before.
Generic Question
Is it possible to transparently locally shadow a function f with a wrapper of it with the same name f?
I.e., how to locally have (f ...
1
vote
1
answer
1k
views
What is the difference between letrec-syntax and let-syntax in Scheme?
There were similar question but not with syntax macros, I though that the difference is that one macro can't see the other like letrec and let with functions.
But this works the same with letrec-...
1
vote
1
answer
124
views
How do I fix the "X is not a number" in my macro in Lisp
I started learning lisps and am currently working on Macros for school. I created a simple macro called "-=" in a txt file called decrement.txt
(defmacro -= (numericValue decrementValue)
(list '...
0
votes
1
answer
220
views
Standard way to handle quoted symbol in lisp macros in Scheme
For some code I was working I've needed to handle 'x inside macro. What is standard way of handling those values?
I have code like this:
(define (quoted-symbol? x)
(and (pair? x) (eq? (car x) '...
2
votes
2
answers
308
views
macros in clojurescript - does not expand properly
I have created a macro in clojure
(ns macro-question.map)
(defmacro lookup [key] (list get (apply hash-map (range 1 5)) key))
in the clojure repl it works as expected
$ clj
Clojure 1.9.0
user=> (...
2
votes
3
answers
1k
views
lisp macro to build a list of an expression and it's evaluation
I'm trying to write a macro in Common Lisp that takes any number of expressions and builds a list containing each expression followed by its evaluation in a single line. For example, if I name my ...
2
votes
2
answers
101
views
Quoting in macro-defining macro
I'm trying to write a macro that defines some helpers for struct-of-arrays data structure (based on this snippet). Inside that macro I define another macro that helps with traversing all of the slot ...
5
votes
1
answer
651
views
How this backquote "syntax" works in lisp?
Here is simplified example from book On Lisp by Paul Graham (scheme like syntax).
(define-macro (bar)
(let ((x 10) (y '(1 2 3)) (z 'foo))
`(list ,x `(,',z ,,@y))))
I know how ,,@y should work ...
1
vote
1
answer
370
views
How to write LISP macro with double quasi quotation in scheme
I need to write the lisp macro in scheme (please on hygienic macros and syntax-rules etc) that will have function call and Alist as argument
I want function and macro that call that function to have ...
0
votes
1
answer
316
views
How to write macro expand in custom defined LISP in JavaScript
I have general question how should I go about and create proper macroexpand function or macro.
This is definition of my macro in LIPS interpreter (you can test it here https://jcubic.github.io/lips/)
...
3
votes
3
answers
290
views
What is standard way of defining global closures in scheme?
So I want to know if there is standard way of having code like this:
(let ((x 10))
(define (add10 a)
(+ x a)))
I know about:
(define add10 (let ((x 10))
(lambda (a) (+ x a))))...
0
votes
1
answer
349
views
LISP macro that process variables and data structure inside at runtime
I have LISP written in JavaScript (https://jcubic.github.io/lips/ with online demo where you can try it) and I have macro like this:
(define-macro (globalize symbol)
(let ((obj (--> (. lips 'env)...
1
vote
0
answers
120
views
How to define function in LISP that recursively return back quoted list
I have problem with macros in my lisp interpreter writtein in JavaScript. the problem is in this code:
(define log (. console "log"))
(define (alist->object alist)
"(alist->object alist)
...
2
votes
1
answer
222
views
My lisp macro stops working in latest guile
I have macro that I've written in 2010, it was for managing structures like in Common Lips using Alists (here is whole file including functions https://jcubic.pl/struct.txt).
(define-macro (defstruct ...
0
votes
1
answer
184
views
Build dynamic COND clauses in Common Lisp
I wonder if it is possible to dynamically build COND clauses from a loop like (pseudo code):
(defvar current-state 1)
(defmacro mymacro ()
(cond
`(loop (state . callback) in possible-states
...
0
votes
2
answers
250
views
Clojure evaluating string variable as a symbol, is this use of read-string okay?
I can use memfn to create a clojure function that invokes a java function.
(macroexpand '(memfn startsWith prefix))
=> (fn* ([target2780 prefix] (. target2780 (startsWith prefix))))
((memfn ...
1
vote
2
answers
252
views
Parsing an infixed string with a macro
I am trying to evaluate an infixed expression in a string.
Some sample data to evaluate my code against:
(def data {:Location "US-NY-Location1"
:Priority 3})
(def qual "(Location = \"US\"...
0
votes
1
answer
82
views
How can I write this Clojure macro more idiomatically?
(defmacro get-color [color-name]
`@(thi.ng.color.core/as-int32 (var-get (resolve (symbol "thi.ng.color.core"
(str '~color-name))))))
I like to avoid using ...
3
votes
2
answers
286
views
Macro with a list of macros as argument in Common Lisp
In Common Lisp, how to define a “meta-macro” which takes as argument a list of macros (and other arguments) and composes these macros to produce the desired code.
The problem is equivalent to writing ...
2
votes
1
answer
121
views
Using a macro to define functions computing the 10 Easter related based dates
I'm currently learning lisp with Graham's book “ANSI Common Lisp” and as an exercise I am writing Julian-day based calendar calculations. As you know, the Easter Sunday changes from year to year and ...
4
votes
2
answers
2k
views
How do setf works under the hood?
Currently learning common lisp, following Peter Seibel's Practical Common Lisp (i'm at chapter 11, about collections), i have difficulties to understand how setf works behind the hood.
Considering ...
0
votes
1
answer
68
views
Why is a macro being evaluated while compiling a function definition (Clozure Common Lisp)?
I have:
(defmacro assign (name value)
(format t "assigning ~A to ~A~%" `,name `,value))
(defun opcode-call (&rest args)
(mapcar (lambda (arg)
(if (stringp arg)
...
1
vote
0
answers
49
views
How can I utilize an Emacs macro which has already been compiled?
I am attempting to modify the python major mode to work slightly differently. Specifically, I would like to change python-indent-region. I believe I have figured out what change I need to make (it ...
1
vote
2
answers
284
views
How can the symbols in a Pandoric Macro be compiled out?
I have read section 6.7 of LOL a few times now, and I still can't wrap my mind around the following.
Bindings that were previously closed to outside code are now wide open for us to tinker with, ...
2
votes
2
answers
912
views
Use a string variable as macro argument
I want this code :
(setq name "foobar")
(defun (intern name) ())
do the same thing as :
(defun foobar ())
I have tried this (from This question):
(defmacro make-my-function (name)
(list 'defun
(...
4
votes
2
answers
725
views
Elisp: Macro expansion at load time with eval of undefined variable
Lisp-rookie here.
My goal is to define a macro that will make the keys of a dotted alist available as variables to access the corresponding values, hence the name »let-dotted-alist«. So what I want ...
0
votes
1
answer
191
views
Conditionally remove let-binding in lisp macro
How can I conditionally remove a let-binding in a defun created in a lisp macro? Here, I want to remove the first let-bound variable from the resulting function, but am running into a problem where I ...
0
votes
1
answer
220
views
Substitute symbol name in macro
How can I substitute a symbol name into a function created in a macro? I think I am missing something obvious here. For example, I am trying to make a macro that defines some variables and functions ...
6
votes
4
answers
2k
views
How do I modify a :arglists to a Clojure fn or macro?
How do I modify the :arglist attribute for a clojure fn or macro?
(defn tripler ^{:arglists ([b])} [a] (* 3 a))
(defn ^{:arglists ([b])} quadrupler [a] (* 4 a))
% (meta #'tripler) =>
{:...