‘3D syntax’ explanation

Hi

‘3D syntax’ came up in the discord recently and Jade Sailor kindly provided an explanation and example:

3d syntax is when a syntax object is programmatically constructed to contain something which doesn't have a source representation

!rkt eval

(parameterize ([current-namespace (make-base-namespace)])
  (print
   (expand
    #'(let-syntax ([f (lambda (stx) #`(quote #,(lambda () 4)))])
        (f)))))

r16 APP

#<syntax:trick:4:6 (let-values () (let-values () (quote #<procedure>)))>

The fully expanded version of the program contains a live procedure, not just numbers and lists and identifiers and such. There are occasionally places where something like this is useful, although there are a number of subtle things to be aware of.

(Most notably that the code can't be compiled and stored in a .zo file and that you can create macros which have weird side effects and generally behave in unexpected ways.)

Also seen at

Perhaps one for the Racket Glossary @sschwarzer ?

Kind Regards,
Stephen :beetle:

Credit to @jagen31 for the image :clap: for adding a bit of fun