October 2014
Intermediate to advanced
280 pages
7h 20m
English
Write a macro called myunless that implements the standard unless functionality. You’re allowed to use the regular if expression in it.
Write a macro called times_n that takes a single numeric argument. It should define a function called times_n in the caller’s module that itself takes a single argument, and that multiplies that argument by n. So, calling times_n(3) should create a function called times_3, and calling times_3(4) should return 12. Here’s an example of it in use:
| | defmodule Test do |
| | require Times |
| | Times.times_n(3) |
| | Times.times_n(4) |
| | end |
| | |
| | IO.puts Test.times_3(4) #=> 12 |
| | IO.puts Test.times_4(5) #=> 20 |
Read now
Unlock full access