[racket] novice question about parentheses and control flow

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Wed Dec 12 11:49:14 EST 2012

On Dec 12, 2012, at 10:29 AM, Matthias Felleisen wrote:

> In Racket, Scheme, and Lisp, parentheses are NOT optional, they are meaningful. Everyone counts.

In specific, one of the things parentheses often mean is that the first thing inside the parentheses is a function to be applied to the remaining things.

In your example, 
... (begin ((print a) (loop (+ 1 a))))
you're basically asking Scheme to use the result of (print a) as a function which it can then apply to the result of (loop (+ 1 a)).  Since (print a) doesn't return any result at all, it certainly doesn't return a function that can be called on something else.

What you're running into is a common problem for students moving from high school algebra to Lisp/Scheme/Racket: in high school algebra, MISSING parentheses can sometimes give you wrong answers due to order-of-operations errors, but EXTRA parentheses can never hurt.  In Lisp/Scheme/Racket, either one can hurt.

Stephen Bloch
sbloch at adelphi.edu



Posted on the users mailing list.