Questions tagged [lisp-macros]
43 questions
2
votes
2 answers
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
(intern (format "my-%s-function" name)) ()
(list…

Bapt
- 21
- 2
1
vote
3 answers
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) translates to (cond (a b) (t c))
My solution is the…

preferred_anon
- 538
- 4
- 11
1
vote
1 answer
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
> (macro-expansion-seconds)
1639244533
It replaces…

Alex028502
- 3,486
- 2
- 23
- 50
1
vote
1 answer
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 ,on)
(destructuring-bind
,(apply…

Akasha
- 195
- 1
- 8
1
vote
3 answers
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) (setq x 2) (if (= n 2) (setq x 1)))
Currently,…

Candid Moe
- 131
- 1
- 9
1
vote
1 answer
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-syntax and let-syntax
(let-syntax ((foo (lambda (x)…

jcubic
- 61,973
- 54
- 229
- 402
1
vote
1 answer
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 'setf numericValue (- numericValue…

only_chio
- 13
- 2
1
vote
1 answer
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 syntax like this:
(foo '(10 (a (lambda () (display…

jcubic
- 61,973
- 54
- 229
- 402
1
vote
0 answers
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)
Function convert alist pairs to JavaScript object."
…

jcubic
- 61,973
- 54
- 229
- 402
1
vote
2 answers
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\")")
I would like the qual string to be converted…

pvik
- 105
- 5
1
vote
0 answers
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 involves changing line #1070 to be…

Kurt Wheeler
- 419
- 3
- 12
1
vote
2 answers
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, even if those bindings were compiled to something…

Todd
- 475
- 4
- 15
0
votes
2 answers
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))
(append accu (list (list…

Pedro Delfino
- 2,421
- 1
- 15
- 30
0
votes
2 answers
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 presents examples to re-write the built-in incf…

Pedro Delfino
- 2,421
- 1
- 15
- 30
0
votes
1 answer
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 me) feels like a really simple use case akin to…

Phil
- 592
- 6
- 15