LiteralNoExpression
DRAFT

Incorrect

A literal is not an expression

Correct

Even an individual literal is an expression

Correction
Here is what's right.

A literal is the most basic form of expression. When looking at an expression as a tree, a literal is a leaf in such a tree.

Like every expression, a literal has a value. The value of 42 is 42.

Like every expression, a literal also has a type. The type of 1234567 is int.

Understanding that a literal is an expression allows students to reason about expressions in a general, compositional way. Any rules they learn about expressions apply to literals, because literals are expressions.

Origin
Where could this misconception come from?

Scratch does not use blocks to represent literal values; instead students directly enter literals into the holes of the surrounding blocks.

The following example shows a green block for an addition, with two holes for two subexpressions:

To compute score + 10, the student will plug a block for the score variable into the left hole, but there is no block for the literal 10. Instead, the student directly types the literal value 10 into the right hole.

This may provide students with the impression that literals are not expressions.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.