owned this note
owned this note
Published
Linked with GitHub
# Hell, World!
[TOC]
## "It's not a bug, it's a Feature"s and Syntax
* 1-based indexing
* The only comparison operator is `=`
* Mathematica-like Syntax
* Functions are calles by `Name[parameters]` and defined by `Name[int parameter_]:=[Comment["Do stuff"]]`
* No boolean data type
* Lists are flattened like in Perl.
* Static nominative weak typing discipline (`int a="Hello World"` compiles)
* The above example would assign the string's address to the int.
* No comparison operators. Only `Compare[a,b]`
* No loops or gotos, only recursion.
* `/` is integer division when given ints, or float division if given floats. `%` forces float division.
* Modulus is a function `Remainder[a,b]`
* Numbers are rounded with bankers' rounding `Round[a,b]`
* Function parameters can optionally have a type. If it does, passing something not of that type will cast it. If it doesn't, any value will be used as-is.
* Data types:
* `String` holds strings. Casting to a string gives the data type.
* `byte`, `short`, `int`, `long`, `double` for unsigned numbers. Casting a String or eval to a number gives the address. Casting a large type to a smaller type (Does something, I'm not sure what.) For signed numbers, the `signed` modifier is necessary.
* `eval` is a data type that stores commands. Similar to a function, but can't have arguments. Casting anything to `eval` gives `Eval[x]`. `eval`s are defined by `eval x=[foo;bar]` or `eval x=[foo;bar;]`. If the last statement doesn't have a semicolon it will attempt to return the result of the last statement.
* No fatal errors or compiler errors. The program will print to StdErr if it sees something is wrong but will attempt to continue execution anyway.
* `a/0`=MaxInteger, MinInteger, or 0 depending on if `a` is positive, negative, or 0.
* Referencing an undefined variable or assigning a function which returns `void` to a variable assumes 0.
* Variables and functions not obeying proper case are equivalent to `0` and `Return[0]`.
* There are some noted exceptions. Running out of memory or writing to an invalid memory address will both crash the program.
* Functions are all `PascalCase`. Global variables are `camel_Snake_Case`. Function parameters are `modified_Snake_Case_`. This is enforced by the interpreter / compiler, and treats any instance of a variable or function that does not conform as a 0. This may throw warnings.
* Literals can be assigned, like in Forte. The code `4=5; Print[2+2]` prints `5`. Assigning to an illegal symbol assigns to the default value of that type instead.
* Everything is globally scoped.
## Builtins
* `Remainder[int a_, int b_]:=Return[a_-(a_/b_)]`
* `Print[String a_]` Prints a string to StdOut. If given a non-string, see casting rules above.
* `ToString[a_]` Returns a string representation of anything passed to it.
* `If[byte a_, {eval option_}]` evaluates the a'th option, 0-indexed. Evaluates `Return[a]` and displays `Warning: If index out of bounds` if unable.
* `Compare[a_, b_]` returns 0 if a < b, 1 if a == b and 2 if a > b.
* `ParseNumber[String a_]` returns the number `a` is a string representation of, if `a` isn't a String representation of a number return 0. The type returned depends on the number parsed, if it finds a decimal point returns a double, otherwise returns the smallest integer data type capable of holding the parsed number.
* `Round[double a_, int b_]` rounds using bankers' rounding to the nearest 10^-b^. If `b` is zero, then round towards zero.
* `Eval[String x_]` evaluates `x_` as Hell, World! code.
* `Copy[x_]` returns a variable equivalent to `x_`. This can be used to pass values to variables without passing the reference to the original, to avoid modifying it.
* `Return[x_]` returns from the containing function
* `Please[x_]` must be called about every 3 function calls. Otherwise functions as an identity function. If not called enough, errors.