Skip to content

Instantly share code, notes, and snippets.

@rdococ

rdococ/lang.txt Secret

Last active August 11, 2017 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdococ/4be701fc41ffbcc5b81b4fdeb179bbca to your computer and use it in GitHub Desktop.
Save rdococ/4be701fc41ffbcc5b81b4fdeb179bbca to your computer and use it in GitHub Desktop.
Some kind of language thing.
# idk what to call it yet
1. Syntax
Syntax should be highly compactible and simple.
add=x,y→x+y; # = is assignment, and → is function definition
three=→3; # function with no parameters required
2. If expression
This is the ternary if expression, ?:. It's self explanatory.
or=a,b→a?a:b; # also technically the Elvis operator
and=a,b→a?b:a; # the /reverse/ Elvis operator
3. self
You can use "self" in the definition for a function or a map (described below), which enables easy and portable
recursion.
fac=x→x==0?1:x*self(x-1); # this function calls itself
4. parent
Additionally, you are able to access the object's "parent" in its definition with the "parent" keyword. This enables
multiple recursion levels:
yay=x→x==0?1:x*(y→y==0?1:y/parent(y-1))(x-1)
The yay function described above takes x. If x is 0, then it returns 1. Otherwise, it multiplies x by the result of
passing x-1 to /another/, anonymous function which takes a variable y. If y is 0, the latter function will return 1 -
otherwise it will return y divided by the result of calling the /former/ function with y-1.
To aid with this, you can also pass an optional numerical argument in angled brackets - e.g. "parent<2>", to get
an object's grandparent, great-grandparent, etc.
5. Maps
Maps, to put it simply, are associative arrays. They map keys of any type to values of any type.
r={
"a" → "yay";
"b" → "meep";
};
Due to the "self" and "parent" keywords mentioned above, maps hold extreme power - and can hold many more data
structures than their equivalents in other languages can.
Here, I've created a literal finite state machine.
game={
"locked" → {
"unlock" → parent.unlocked; # "parent" here refers to the map currently being constructed (which is the
# nested one, hence the need for the parent syntax)
};
"unlocked" → {
"lock" → parent.locked;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment