Hacker News new | ask | show | jobs
by billsix 3696 days ago
I'm currently writing a library/book dedicated to the subject, including compile time state, compile time I/0, and a compile time test framework in 9 lines of code!

Tests are specified as part of the definition, run at compile time, and if they fail no executable is produced.

  {define
    "list#"
    permutations
    [|l|
     (if (null? l)
       ['()]
       [{let permutations ((l l))
          (if (null? l)
              [(list '())]
              [(flatmap [|x| (map [|y| (cons x y)]
                                  (permutations (remove x l)))]
                        l)])}])]
  ;;; tests
  (satisfies?
   permutations
   '(
     (() ())
     ((1) ((1)))
     ((1 2) ((1 2)
             (2 1)))
     ((1 2 3) ((1 2 3)
               (1 3 2)
               (2 1 3)
               (2 3 1)
               (3 1 2)
               (3 2 1)))
     ))}
https://github.com/billsix/bug