This Article IsCreated at 2024-01-07Last Modified at 2024-01-07Referenced as ia.www.f15

Eval is not Evil

The ability to compile and run code assembled at run-time is useful.

Here is an example use of eval in Janet.

(defmacro match? [value pattern]
  ~(match ,value ,(eval pattern) true false))

(def p0 '[:a _])
(pp (match? [:a :b] p0)) # true
(def p1 '[:b _])
(pp (match? [:a :b] p1)) # false