ela
Contents

ManualLanguage

Arithmetic

In the terminalela --spec arithmetic

  • Ordinary infix maths in expressions, no $(( )): count = $count + 1.
  • Operators: + - * / %, comparisons == != < <= > >=, logic and, or, not.
  • and and or stop early: and works out its right side only when its left is true, and or only when its left is false. A test that guards what follows it is one line: if has($m, "k") and $m["k"] > 0 never reads the missing key, and if $err != null and $err.stderr != "" never reads a field of null.
  • Bash's and C's ||, && and ! in an expression are errors that name the word to write: if $a || $b stops with write or for ||. In a condition, ! cmd stops with the word to write, if not cmd.
  • One visible number type. Internally it is a 64-bit integer while whole, and becomes a float only when needed (as in Lua 5.3), so large integers such as nanosecond timestamps keep full precision.
  • Integer overflow is an error (fail fast), never a silent wrap-around.
  • / always gives the exact result: 7 / 2 is 3.5. // is whole-number division: 7 // 2 is 3. % is the remainder.
  • Conversions are explicit: int(x) truncates towards zero, float(x) reads a number that may have a fraction or an exponent, float("2.5"). Both refuse text with spaces or underscores. What float gives is a number as any other, whole when it is whole: float("1") indexes a list.
  • A value becomes text inside a string, "$x" or "${int($x)}". A call to str(…) or string(…) stops before line 1 and says so, and number(…) names int(x) and float(x).