Questions tagged [lisp-macros]

43 questions
5
votes
1 answer

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 but not sure exactly how ,',z should work what…
jcubic
  • 61,973
  • 54
  • 229
  • 402
5
votes
4 answers

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) => {:arglists ([a]), :ns #, :name…
Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86
3
votes
2 answers

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 wrapped-args...) expand to (f args...)? Flet seems to…
Alberto
  • 565
  • 5
  • 14
3
votes
3 answers

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)))) but this will not work if I want to define…
jcubic
  • 61,973
  • 54
  • 229
  • 402
3
votes
2 answers

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 a “higher-order macro” which defines a macro out…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
3
votes
2 answers

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 this expression : (setf a 10) I completely…
aluriak
  • 5,559
  • 2
  • 26
  • 39
3
votes
2 answers

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 is: (setq foo '((a . "aa") (b .…
Phylax
  • 189
  • 10
2
votes
1 answer

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 (define the-time…
Alex028502
  • 3,486
  • 2
  • 23
  • 50
2
votes
1 answer

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 function bodies at the time the function is…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
2
votes
1 answer

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 following about lambda expressions: This confuses me…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
2
votes
2 answers

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=> (require 'macro-question.map) nil user=>…
Alex028502
  • 3,486
  • 2
  • 23
  • 50
2
votes
3 answers

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 macro as (defmacro list-builder (&rest exp) …
2abysses
  • 101
  • 1
  • 7
2
votes
2 answers

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 values in struct. The thing is I can't make double…
Andrew Kravchuk
  • 356
  • 1
  • 5
  • 17
2
votes
1 answer

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 name . fields) "Macro implementing structures…
jcubic
  • 61,973
  • 54
  • 229
  • 402
2
votes
1 answer

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 there is about 10 other special days whose actual…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
1
2 3