A Very Helpful Language

David Stark / Zarkonnen
2013-03-28 11:04
I was talking to David about code formatting earlier, and the question suddenly popped into my head: "Are there any programming languages where evaluation order is determined by spacing?

The fewer spaces between an operator and its arguments, the earlier the execution?" I don't know the answer to this, but it did lead me to come up with the following joke language inspired by ill-conceived supposedly "helpful" language features:

  • To eliminate hard-to-read brackets, code is evaluated depending on spacing. That is, 3-2 - 1 is 0, but 3 - 2-1 is 2.
  • The multiplication operator is x instead of the confusing *. Yes, the spaces are part of the operator and don't count towards the evaluation order.
  • Of course, the evaluation order of ambiguously spaced code is undefined. 3 x 2 + 1 may be 9 or 7 in a valid implementation.
  • Division is done using nice, readable horizontal divisor lines:
  • To eliminate confusing semicolons, periods are instead used to terminate function invocations and blocks: myfun 3,2.
  • To allow flexibility, adding an extra space before a function parameter passes it in by name, which means it's evaluated each time it's used: myfun 1, foobar 3.. will evaluate foobar 3. as many times as it's used, whereas myfun 1,foobar 3.. evaluates it exactly once.
  • Our language also supports coroutines! Simply wrap any code in the "aside operator", also known as "brackets": (myfun 3,2.)
  • As a convenient shorthand, any function call terminated with a ! instead of a . will exit the program with a code of 1 if the function call returns a falsey value.
  • The boolean values are yes and no, though they're actually just alternate names for 0 and 1. (0 is true to maintain compatibility with unix exit codes.)
  • Everything but yes is falsey, for simplicity's sake.
  • Variables are declared using the syntax x is 3. and changed using x becomes 3..
  • To prevent arguments over naming, the following variable names are considered the same: FooBar, fooBar, foo_bar, FOO_BAR. But foobar is a different variable.
  • There is also an alias command to define aliases of variable names at runtime. The effect of this command is global. It's an excellent tool for multilingual teams.
  • Comments, since they're important, are enclosed between triple explanation marks.

Finally, here's an example function in this language. Suggestions for "improvements" are very welcome. :D

function isPrime,x,
  div is 2.
  result is no.
  alias r to result.
  while div  < x,
                     | x |
    remainder is x - |---|. !!!Using easy visual representation of the floor function.!!!
    remainder is 0?
      r becomes yes.