TOC of the series
In the next step we will apply
match instead of higher order functions over lists and
cond. This is optional, the code in the previous version is perfectly valid Racket code. But many Racketeers tend to prefer
for for iteration and
match over conditionals.
for along with sequences (
in-range, and the like) is in principle more efficient, more concise and adds great flexibility given the abundance of pre-defined constructs. For many programmers it is also more readable.
match its expressiveness is unparalleled. Once you meet it, you can't live without it.
For more information about
for see Iterations and Comprehensions [The Racket Guide] and Iterations and Comprehensions [The Racket Reference]. For details about
match see Pattern Matching [The Racket Guide] and Pattern Matching [The Racket Reference]
The new version with
match looks as shown below.
Don't forget to take a look at the Racket documentation for all the new constructs introduced:
By the way, with
match the functions provided by
racket/list are no longer used, so the require of that module has been deleted.
Next article in the series: Racket: