15 Jul 2013, 03:42
The Elixir test framework, ExUnit, uses some clever code quoting tricks.
For example, if you assert
assert 5 < 4
You’ll get the error “expected 5 to be less than 4.”
The Elixir source code is on Github (at
of this is in the file
/lib/ex_unit/lib/assertions.ex. Spend some
time reading this file, and work out how it implements this trick.
(Hard) Once you’re done that, see if you can use the same technique to
implement a function that takes an arbitrary arithmetic expression
and returns a natural language version.
explain do: 2 + 3*4
#=> multiply 3 and 4, then add 2
You must be logged in to comment