7.4.0.4

8 Lab Comfortable Macros

Jay McCarthy

In all of these exercises, first do not use a syntax parameter, then write it using a syntax parameter. In each case, decide if you think it is a better interface to use syntax parameters, or not.

Exercise 16. Use let/ec to make a version of define that defines a return statement.

Exercise 17. Use let/ec to make a while macro that supports break and continue.

Exercise 18. Write a version of if that provides access to the value of the condition via it.

Exercise 19. Write a version of cond that uses the if from the previous exercise to also provide access the value of the question.

Exercise 20. Write a macro that allows you define bindings related to other bindings. For example, a user could write:

(struct posn (x y))
(define-related (define-posn p)
 [x (posn-x p)]
 [y (posn-y p)])
 
(define (magnitude p)
 (define-posn p)
 (+ x y))
(magnitude (posn 3 4))
; => 7

define-related is a basic kind of compile-time higher-order module (functor).

Exercise 21. Modify the classy macro to add default values to the fields.

Exercise 22. Modify the classy macro to allow any number of fields to be updated with update.

Survey link: https://forms.gle/gc8Aiw9bBBmczcox9