Questions tagged [hygiene]

Questions should be tagged with the hygiene tag when they involve both macro expansions and name collisions, which means that only specific programming languages using macros are concerned (like C, Lisp, Scheme, etc.).

See Hygienic Macros on Wikipedia.

42 questions
60
votes
8 answers

Collection of Great Applications and Programs using Macros

I am very very interested in Macros and just beginning to understand its true power. Please help me collect some great usage of macro systems. So far I have these constructs: Pattern Matching: Andrew Wright and Bruce Duba. Pattern matching for…
unj2
  • 52,135
  • 87
  • 247
  • 375
30
votes
6 answers

Can someone explain the concept of 'hygiene' to me (I'm a scheme programmer)?

So... I'm new to scheme r6rs, and am learning macros. Can somebody explain to me what is meant by 'hygiene'? Thanks in advance.
Cam
  • 14,930
  • 16
  • 77
  • 128
9
votes
2 answers

How can I create hygienic identifiers in code generated by procedural macros?

When writing a declarative (macro_rules!) macro, we automatically get macro hygiene. In this example, I declare a variable named f in the macro and pass in an identifier f which becomes a local variable: macro_rules! decl_example { …
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
8
votes
1 answer

What is difference between datum->syntax and syntax #' in define-syntax body?

Testing code: (define-syntax (test-d stx) #'(begin (define (callme a) (writeln a)))) (define-syntax (test-e stx) (datum->syntax stx '(begin (define (callme2 a) (writeln…
Ondrej
  • 503
  • 3
  • 21
8
votes
1 answer

What is it about a single namespace that leads to unhygienic macros? (in LISP)

Some claim that a single namespace in LISP leads to unhygienic macros. http://community.schemewiki.org/?hygiene-versus-gensym http://www.nhplace.com/kent/Papers/Technical-Issues.html What precisely is it about having single, dual or multiple…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
7
votes
1 answer

Macro call vs macro definition environment in Julia

I am trying to make sense out of a statement in the Julia's Metaprogramming documentation on macro hygiene. The documentation claims that Julia’s macro expander solves these problems in the following way. First, variables within a macro result are…
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
7
votes
3 answers

Macro-defining macro in Racket?

In Common Lisp it is relatively easy to create a macro-defining macro. For example, the following macro (defmacro abbrev (short long) `(defmacro ,short (&rest args) `(,',long ,@args))) is a macro-defining macro, because it expands to another…
Racket Noob
  • 1,056
  • 1
  • 8
  • 16
7
votes
1 answer

What exactly is the purpose of syntax objects in scheme?

I am trying to write a small scheme-like language in python, in order to try to better understand scheme. The problem is that I am stuck on syntax objects. I cannot implement them because I do not really understand what they are for and how they…
Matt
  • 21,026
  • 18
  • 63
  • 115
6
votes
0 answers

How to debug Julia macros?

Note: This question refers to Julia v1.6. Of course, at any time the answers should ideally also answer the question for the most recent version. There seem to be a lot of questions and confusion about macro hygiene in Julia. While I read the manual…
Adomas Baliuka
  • 1,384
  • 2
  • 14
  • 29
5
votes
1 answer

Why does macro hygiene not prevent collisions between multiple const definitions?

I thought "hygiene" would prevent collisions between Xs defined within my macro m! but that turned out not to be the case. What am I misunderstanding? macro_rules! m { ($e:expr) => { const X: i32 = $e; }; } m!(0); m!(1); fn main()…
nodakai
  • 7,773
  • 3
  • 30
  • 60
5
votes
2 answers

How do I write a hygienic Ruby mixin?

Say I'm writing a mixin module that adds functionality to a third-party class. Obviously some of the methods and instance variables I want to make accessible to the third-party class and its clients. These constitute the public interface of the…
John
  • 29,546
  • 11
  • 78
  • 79
4
votes
1 answer

Scheme syntax-rules - Difference in variable bindings between (let) and (define)

The R5RS spec states that as part of the requirements for a macro defined using syntax-rules: If a macro transformer inserts a free reference to an identifier, the reference refers to the binding that was visible where the transformer was…
Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
4
votes
1 answer

Does macro hygiene only protect you in different modules?

As for Julia 0.4.2 macro g(y) :((x, $y, $(esc(y)))) end x = 1 function t() x = 2 println(macroexpand(:(@g(x)))) println(@g(x)) end t() println(x) >>> (x,x,x) (2,2,2) 1 I had expected the result to be (1, 1, 2). However, if I…
colinfang
  • 20,909
  • 19
  • 90
  • 173
4
votes
1 answer

Why does this Julia macro _not_ require `esc`?

I found an example of an unless macro in Julia here written as follows: macro unless(test, branch) quote if !$test $branch end end end However, when I try to use it, it fails (apparently there is a hygiene problem, but I can't…
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
3
votes
1 answer

Prevent merge if the custom labels are not present in Github

I am setting up a hygiene development process for my team. As part of that, I want every code built to be unit tested and QA verified. I have created custom labels like QA Ready, Prod Ready for code repositories. How do I ensure that a PR is not…
1
2 3