Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First an example of how to emulate an "anonymous macro". Then I'll comment on the usefulness.</p> <p>Consider this anonymous macro transformer, that takes a syntax object representing a number and returns a new syntax object representing the double of the input number.</p> <pre><code>(λ (stx) (datum-&gt;syntax stx (* 2 (syntax-&gt;datum stx)))) </code></pre> <p>We can test it like this:</p> <pre><code>&gt; ((λ (stx) (datum-&gt;syntax stx (* 2 (syntax-&gt;datum stx)))) #'3) </code></pre> <p>The result is a syntax object with a 6.</p> <p>If we want the actual number 6, we can use <code>eval</code>.</p> <pre><code>&gt; (eval ((λ (stx) (datum-&gt;syntax stx (* 2 (syntax-&gt;datum stx)))) #'3)) 6 </code></pre> <p>Now we have used the anonymous syntax transformer to rewrite the 3 into a 6.</p> <p>Is an anonymous macro useful? </p> <p>Anonymous functions are used in places where you a function, but you only need it once. If the same anonymous functions is used twice in a program, it would be better to give it a name, and then just refer to it twice.</p> <p>The same is the case for syntax transformations. If you need the same transformation at least twice, you should give it a name. The only time an anonymous syntax transformation would make sense is, if it were used once only. In most cases it will be simpler just to write the result of the transformation. I can't think of an example, where an anonymous transformation would make things simpler.</p> <p>Note: All examples were tested in Racket.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload