Questions tagged [lisp-macros]

43 questions
0
votes
1 answer

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 covers macros. In one section about compiling it, he…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
0
votes
1 answer

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 covers macros. He presents a tool called PPMX which…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
0
votes
1 answer

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 should basically just FUNCALL the lambda with taking MY-VAR into account. What…
Manfred
  • 423
  • 3
  • 9
0
votes
1 answer

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) `(eval ,someExpression) ) ) (foo (print 1)…
JustAFellowCoder
  • 300
  • 2
  • 11
0
votes
1 answer

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) 'quote) (symbol? (cadr x)) (null? (cddr…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
1 answer

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/) function macro_expand(single) { return async…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
1 answer

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) (get symbol)))) `(begin ,@(map (lambda…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
1 answer

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 do ((eq current-state ,state) …
SmartyLisp
  • 99
  • 7
0
votes
2 answers

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 startsWith prefix) "abc" "a") => true memfn requires that…
John Dorian
  • 1,884
  • 1
  • 19
  • 29
0
votes
1 answer

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 the (var-get (resolve (symbol ... (str…
HappyFace
  • 3,439
  • 2
  • 24
  • 43
0
votes
1 answer

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) (let ((var (gensym))) (assign var…
Capstone
  • 2,254
  • 2
  • 20
  • 39
0
votes
1 answer

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 have a nil that sticks around in the let…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
0
votes
1 answer

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 similar to the following, (cl-defmacro mac…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
1 2
3