4 ms·
Can you explain that last line (sort @1 : [chain car len])?
by abecedarius 3y ago
Can you explain that last line (sort @1 : [chain car len])?
- kazinator 3y agoYes. @1 indicates where the first argument of the implicit function is inserted. (It's like _ in some partial application syntaxes, but more general because there can be multiple implicit arguments.) The previous steps produced a list of word lists, so we indicate that this giant list, which is the implicit first argument of this function of the pipeline, is going into the first argument position of sort. The : symbol causes argument 2 of sort to be defaulted, as if it were omitted. That's the comparison function, which defaults to less. In TXR Lisp, you can explicitly default optional arguments with : which enables you to give arguments to later optional arguments to the right of those. We then specify argument 3, the function for selecting the key to sort by for each element. Each element is a list of words (anagrams fo equal length). We pick the first one with car, and take its length: chain will compose those functions for us. We use square brackets because the function names are in the function namespace: square brackets provide a function application language in which variables and functions are in one namespace.
- abecedarius 3y agoThanks! It's interesting to see some ideas from other Lisp dialects. Maybe I'll learn a bit more TXR.