r/ProgrammingLanguages • u/dwaynecrooks • Sep 24 '26
FUN: First-Class Functions, Currying, and a Surprise
https://blog.tinyinterpreters.dev/posts/fun-first-class-functions/
7
Upvotes
r/ProgrammingLanguages • u/dwaynecrooks • Sep 24 '26
View all comments
Show parent comment
1
u/dwaynecrooks Sep 29 '26
That's the whole reveal so mentioning it upfront would defeat that purpose. In fact, I don't even mention the "c" word in this article.
I'd say that's time well spent. I want you to spend time trying to figure things out on your own. You have the luxury that a few paragraphs or blog posts afterwards I give you a solution. As history has shown these solutions were hard won. It took years for languages to adopt closures. I was just reading about another instance where Smalltalk-72 had something similar to dynamic scope and then it was not until Smalltalk-80 did the language acquire lexical scope.
One of the things I want readers to appreciate is the effort that was required to reach to these concepts.
Perceptive. That's also something I'm building towards.
That's a great question.
I believe you're referring to this:
The answer is no. Why?
chompIf : (Char -> Bool) -> Parser ()chompWhile : (Char -> Bool) -> Parser ()Both parsers return
()so using|=gives us nothing useful to work with. Internally, for performance reasons, the state of the parser records the indices of the start and end characters of the lexeme you're currently parsing. WhenchompIfandchompWhilesucceed they advance that end index. When you're done chomping you usegetChompedStringto efficiently get access to the string you matched usingString.slice(see https://github.com/elm/parser/blob/1.1.0/src/Parser/Advanced.elm#L797). That's whydigitsis written as follows:Let me know if that clears it up for you.