These problems get you warmed up writing your own macros in Racket.
Look up the truthy-falsy behavior of Python 3, and implement a python-if macro that has the same syntax as Racket’s but implements Python’s truthy-falsy behavior. There are lots of corner cases; be careful and test extensively!
Since the number of types of values is very large, we’re going to scope the problem by limiting it to the set of types you can meaningfully use in smol/hof.
Note as a language design issue that the more types there are in the language, the more a non-trivial truthy/falsy system has to consider. Think of this as a virtue of the systems in languages that are either Boolean-only (à la OCaml) or extremely simple (à la Racket: false is false, everything else is true).
(for-right id L B) (for-wrong id L B)
#lang racket (require smol/hof/compat) (define L1 (for-right x (list 1 2 4) (* x x))) (define L2 (for-wrong x (list 1 2 4) (* x x))) (test L1 '(1 4 16)) (test L2 '(1 4 16))
You are welcome to use any of Racket’s constructs, such as for.
If you have the basic idea sketched out but need help with Racket constructs or with macro use syntax, by all means ask!
Finally, we strongly urge you to read this paper for another example of macros.
There is no work to turn in associated with this, but we trust you to
read it anyway—