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

My code signals the error “application: not a procedure” or “call to non procedure”

Why is it happening Scheme procedure/function calls look like this: (operator operand …) Both operator and operands can be variables like test, and + that evaluates to different values. For a procedure call to work it has to be a procedure. From the error message it seems likely that test is not a procedure but … Read more

Why exactly is eval evil?

There are several reasons why one should not use EVAL. The main reason for beginners is: you don’t need it. Example (assuming Common Lisp): EVALuate an expression with different operators: (let ((ops ‘(+ *))) (dolist (op ops) (print (eval (list op 1 2 3))))) That’s better written as: (let ((ops ‘(+ *))) (dolist (op ops) … Read more