Ancestors

Toot

Written by Artyom Bologov (t?he(y|m)?) on 2025-01-05 at 16:24

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

Descendants

Written by ∴ a highly-entropic being ∴ on 2025-01-06 at 00:42

@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

Written by Artyom Bologov (t?he(y|m)?) on 2025-01-06 at 12:11

@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

Written by Konrad Hinsen on 2025-01-06 at 09:43

@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

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113776674972864378
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
268.763649 milliseconds
Gemini-to-HTML Time
0.56023 milliseconds

This content has been proxied by September (ba2dc).