Using AND with the apply function in Scheme

and isn’t a normal function because it will only evaluate as few arguments as it needs, to know whether the result is true or false. For example, if the first argument is false, then no matter what the other arguments are, the result has to be false so it won’t evaluate the other arguments. If … Read more

Flatten a list using only the forms in “The Little Schemer”

I have a version that uses only “first-principles” operations and is efficient (does not require more than one pass through any of the lists, unlike append-based solutions). 🙂 It does this by defining two simple building blocks (fold and reverse), and then defining flatten (and its helper, reverse-flatten-into) atop those (and notice how each function … Read more

Count occurrence of element in a list in Scheme?

Your question wasn’t very specific about what’s being counted. I will presume you want to create some sort of frequency table of the elements. There are several ways to go about this. (If you’re using Racket, scroll down to the bottom for my preferred solution.) Portable, pure-functional, but verbose and slow This approach uses an … Read more

Dot notation in scheme

Note: this is cannibalized from an answer to Recursive range in Lisp adds a period?, which is really asking a different question. However, the explanation of how pairs are printed is the same. The rest of the answer is different. Your question exhibits a bit of misunderstanding, but I think we can clear it up. … Read more