2

Let's begin with some definitions:

  • An expression is a construct that produces (returns) a value.
  • A literal is a notation for representing a fixed value.

I could assume the literal is a expression that returns exactly one value. E.g. the literal 1 is an expression that returns the value 1.

Is there anything wrong in my approach or does being a literal always imply being an expression?

Thank you for clarification.

halex
  • 16,253
  • 5
  • 58
  • 67
  • 1
    I'm not sure if there's a rigid definition of "literal". OTOH, I think you'd be hard-pressed to find anything commonly considered a literal that isn't a valid expression. –  Nov 21 '11 at 19:44

2 Answers2

2

If you account for language-specific exceptions (Python docstrings, C macros, etc.), you are correct. In general, every literal is an expression.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

That's my understanding. To think of it another way:

4-3 is one way of expressing 1

1 is another way of expressing 1

They are both expressions, because they both express a value (1). But 1 is also a literal - because it's literally 1.

Raphael
  • 1,701
  • 15
  • 26