4 ms·
Ok, but Lisp doesn't force you to curate a library of words or require dealing with abstractions. Maybe this example is relevant. Racket defines procedures `fi
by evdubs 3y ago
Ok, but Lisp doesn't force you to curate a library of words or require dealing with abstractions.
Maybe this example is relevant. Racket defines procedures `filter` and `map` for `list`. Also provided is `filter-map`, which I assume may satisfy your not-being-direct-expression concern about Lisp. But, `filter-map` exists for a particular reason:
> Like (map proc lst ...), except that, if proc returns #false, that element is omitted from the resulting list. In other words, filter-map is equivalent to (filter (lambda (x) x) (map proc lst ...)), but more efficient, because filter-map avoids building the intermediate list.
So it exists for performance concerns. It also exists in the "Additional List Functions and Synonyms" so it's not like it's being confused for a core, important function like `filter` or `map`. I still write Racket code where I just explicitly have something like:
(~>
(filter (lambda (x) (equal? 'some-value x)) some-list)
(map (lambda (x) (symbol->string x)) _))
without always jumping for a more concise abstraction.
And, coming from other languages, DRY (don't repeat yourself) seems quite popular, so I am not sold on this being a Lisp-specific issue.
- kazinator 3y agoThe thing is, a compiler could easily recognize the pattern (filter identity (map proc lst ...)) and rewrite it for efficiency (perhaps by using filter-map). Writing it that way in the first place reduces the verbosity of the code, making it look better.