Tuesday, December 10, 2019

(map append elements)

I can recall the difficulty I had understanding let expressions in Lisp.  I used to write out the equivalent lambda expression and then manually add the syntactic sugar to make it into a let.  And I don't recall having an easy time with the chapter on linked lists.  So I find it amusing to see what tortuous code students come up with when they are first introduced to linked lists. My favorite so far has been (map append elements), which looks like it might join the sublists in elements, but if you think about it, the arity is all wrong:  map doesn't apply its function, it calls it.   This had me scratching my head for several minutes until I realized you can call apply on a single argument.

So what little gems of code have you discovered that perform the most trivial of tasks in the most convoluted or obscure manner?

1 comment:

steck said...

The Jane Street libraries for OCaml have

List.concat_map : 'a t -> f:('a -> 'b t) -> 'b t

which joins the sublists created by applying f to each element of the input list.

Not convoluted or obscure, I'm afraid.