Whitespace

DinoCode does not completely ignore whitespace. It uses it to infer your intention.

Is it a variable or a function?#

Consider the following example:

print++

Is it an implicit call to the print function or is it an increment to the print variable?

Answer:

It is an increment to the print variable because the ++ operator is physically attached to print. If there were a space between them, DinoCode would infer that it’s an implicit call ➡ print(++), which would give an error immediately.

Use case

Applying increments or decrements to variables is a very common use case in programming, so DinoCode handles it this way.

x = 0
x++ # 'x' is not confused with a function
print x  # 1

x-- # 'x' is not confused with a function
print x  # 0

Parentheses and spaces#

Consider the following example:

print (2 + 1) * 2

Is (2 + 1) * 2 a single argument ➡ print((2 + 1) * 2) or is (2 + 1) the argument grouping ➡ print(2 + 1) * 2?

Answer:

DinoCode infers that (2 + 1) * 2 is a single argument of print, thanks to the space that separates them. If we remove that space between print and (, the mathematical priority changes:

  1. First, print(2 + 1) is resolved.
  2. Then, the result is multiplied by 2.
print(2 + 1) * 2  # Error: print returns None and None * 2 is invalid
What happens with function calls inside expressions?

For consistency, exactly the same thing happens:

# Here 'print' receives a single argument: 'input("Number: ") * 2'
print input("Number: ") * 2

# Here 'print' receives two arguments: 'input' and '(2 + 1) * 2'
print input (2 + 1) * 2

Brackets and spaces#

Consider the following example:

print [0]

Is [0] a new array passed as an argument ➡ print([0]) or is it an access to element 0 of an array called printprint[0]?

Answer:

DinoCode infers that [0] is a new array passed as an argument to print, thanks to the space that separates them. If we remove that space between print and [, the interpretation changes:

print[0]  # Error: print is not an array
What happens inside expressions?

For consistency, exactly the same thing happens:

nums = [1 2 3]

# Here 'print' receives a single argument: 'nums[0]'
print nums[0]

# Here 'print' receives two arguments: 'nums' and a new array '[0]'
print nums [0]