The asymmetry between "take" and "drop" #functionalProgramming operations on lists is weird. "drop" is just applying "cdr" N times, which is just a couple of function calls in #LambdaCalculus. While "take" requires full-blown #recursion and conditional testing. Or am I doing it wrong?
=> More informations about this toot | More toots from aartaka@merveilles.town
@aartaka but "apply a function N times" is also implemented with recursion, right? so secretly you're sort of smuggling the difference out.
take(lst, n):
if n <= 0 then return emptylist
else return cons(head, take(tail, n-1))
drop(lst, n):
if n <= 0 then return lst
else return drop(tail, n-1)
it's just that it's easier to "hide" drop's recursion and conditional testing in "apply fn N times"
=> More informations about this toot | More toots from d6@merveilles.town
@d6 in Lambda Calculus, numbers are functions applying the first argument to second argument N times. Composing it N times, in other words. This doesn't require recursion, at least in LC. And drop is just a "^list N cdr list" in this situation, while take requires real recursion instead of composition.
But I realize that LC cheats with Church numerals somewhat.
=> More informations about this toot | More toots from aartaka@merveilles.town
@aartaka The asymmetry comes from the data structure, not the operation. On a Lisp array, for example, both would be similar.
=> More informations about this toot | More toots from khinsen@scholar.social This content has been proxied by September (ba2dc).Proxy Information
text/gemini