And even though you think that such a tiny thing can't be a good implementations, it actually is super efficient. The tail recursion is automatically optimized for you (and you can assume that for any functional language - it's a very crucial optimization for this style of code, after all). That's what the core of it will be in an actual implementation, though with added error handling, type checking and so on.
P.S. unlike haskell, in Racket you don't really need to fold the basic operators, they take variable arguments, so you can just:
What would actually be foldl is this:
Now if you expand this (dropping the tail recursion): And even though you think that such a tiny thing can't be a good implementations, it actually is super efficient. The tail recursion is automatically optimized for you (and you can assume that for any functional language - it's a very crucial optimization for this style of code, after all). That's what the core of it will be in an actual implementation, though with added error handling, type checking and so on.P.S. unlike haskell, in Racket you don't really need to fold the basic operators, they take variable arguments, so you can just:
in order to get it to run on a list.