PLQ #12Done on:   Tuesday, April 8th

Question 1 @ 2025-04-08 19:23

Why are symbols produced by (gensym) guaranteed to be unique?


Question 2 @ 2025-04-08 19:25

Say that we run the following code in #lang racket with the define-macro tool that we’ve seen:

(define-macro (orelse <expr1> <expr2>)
  (list 'if <expr1> <expr1> <expr2>))

(define (inc! x) (set-box! x (add1 (unbox x))) (unbox x))

(define a (box 0))
(define b a)

(orelse (inc! a) (inc! b))

What would the result be, and is it showing that the macro is implemented properly?


Question 3 @ 2025-04-08 19:31

Focusing on the macro from the last question:

(define-macro (orelse <expr1> <expr2>)
  (list 'if <expr1> <expr1> <expr2>))

How could we solve the problem of this macro?

(Important: choose the best answer!)


Question 4 @ 2025-04-08 19:32

What is the biggest advantage of define-macro over define-syntax + syntax-rules?

(Important: choose the best answer!)


Question 5 @ 2025-04-08 19:34

Your friend Random J. Hacker heard about macros and wants to use one to create a useful debugging tool:

(define-syntax-rule (show expr)
  (let ([result expr])
    ???
    result))

The idea is to print the expression and its result in the ??? line.

Could this be achieved, and how?