This is more of a learning experience than anything else, the language is
very slow. I hereby take absolutely no responsibility whatsoever for anything ever that ever has to do with this language. With those warnings out of the way:
Selenium
Selenium is a functional programming language created by me, and you can view the source here, or download the interpreter here. Its syntax is loosely based on other functional languages such as Haskell and Lisp. It also has arbitrary precision arithmetic which is one of the major causes of the language being so slow, although I think it is a very useful feature. I recently made several improvements to the code for it, so the preformances mentioned in the overview videos are a little off.
There are almost no types at all in the language, as everything is considered to be a list (therefore the number 1 would be a list of length 1). The only sort of type-like function is that parameters can be specified to be lists, which will be explained more below.
Downloads:
Source:
https://drive.google.com/folderview?id=0BzgXJ3LjGyQzdHY1RlNrUlNwTTg&usp=sharingInterpreter:
http://www.mediafire.com/download/aff5vau8kka5tb3/Selenium.exeOverview Videos:
Part 1:
https://www.youtube.com/watch?v=Vf-WF9bqBjkPart 2:
https://www.youtube.com/watch?v=nss7KSlncPcTutorials:
https://www.youtube.com/playlist?list=PLrN7GapvulRaSYKUYT9QEh0ste-HSf9ZRQuick Tutorials:
Basics:
All expressions that will actually do anything must begin with a function. To create a function, just start it with quotes, then parameters, and finally the actual code of the function, like
this:
"parameters.code"
There can be any number of parameters used, they just must be separated by spaces.
"param1 param2 param3.code"
The code is a collection of keywords that is run in order and removed when done.
To apply values to the parameters, simply type them after the first function, like this:
"x y.x + y" 10 15
which will replace x with 10, then y with 15, and finally add them together, returning 25.
Slightly less Basics:
You can specify that a parameter is a list by appending the characters [] to the end of the name. To use it though you still use the name without the []. The parameter will then take the rest of the arguments until there aren't any more.
For example:
"x[].intersperse + x" 2 3 4 5
x[] will take all the arguments "2 3 4 5", which then will replace x. The statement is now:
"intersperse + 2 3 4 5", which evaluates to "2 + 3 + 4 + 5" or 14.
Recursion:
Because everything is an anonymous function in Selenium, there are no actual names with which you can specify that a function should call itself. Instead, this problem is solved by the "this" keyword. When used, it insert a copy of the calling function into the spot where it is an then runs that. For example, this code:
"n.if (n == 1) then 1 else n * (this (n - 1))"
which you may recognize as being the factorial function. If you are used to programming in other languages, using "this" is pretty much identical to using the name of the containing function.
So this code would evaluate like so:
"n.if (n == 1) then 1 else n * (this (n - 1))" 5
if (5 == 1) then 1 else 5 * (this (5 − 1))
5 * (this 4)
5 * (if (4 == 1) then 1 else 4 * (this (4 − 1)))
5 * (4 * (this 3))
5 * (4 * (if (3 == 1) then 1 else 3 * (this (3 − 1))))
5 * (4 * (3 * (this 2)))
5 * (4 * (3 * (if (2 == 1) then 1 else 2 * (this (2 − 1)))))
5 * (4 * (3 * (2 * (this 1))))
5 * (4 * (3 * (2 * (if (1 == 1) then 1 else 1 * (this (1 − 1))))))
5 * (4 * (3 * (2 * (1))))
120
Constants:
You can specify certain numbers to always evaluate to constants in a function to simplify the function. To do this, add another period between the parameters and the code. In between the two periods, you can write a value, then a '=' and finally another value. For example:
"x.1 = 1.x"
This is simply syntactic sugar for:
"x.if (x == 1) then 1 else x"
and the interpreter actually constructs the above code from the input.
To use this for the factorial function to simplify it:
"n.1 = 1.n * (this (n - 1))"
and it becomes far shorter and easier to read.
Operators:
[start increment stop] - This is used to generate lists. The list will begin at start, the be incremented by increment while it is less than stop. [1 1 10] generates 1 2 3 4 5 6 7 8 9.
+ - * / % ^ ! - These are all standard mathematical signs. They mean addition, subtraction, multiplication, division, modulus division, exponentiation, and factorial, respectively. This symbols do not have to be separated by spaces.
== ~= - These check for equality and inequality, respectively. If a value is true, then it equals 1. For example, 1 == 1 evaluates to 1.
> < >= <= - These check for greater than, less than, greater than or equal to, or less than or equal to, respectively.
Keywords:
apply x y - Pretty much the map keyword from other functional languages. It applies a function x to every element of the list y.
combine list - Combines all the elements of the list together into one. Ex. combine 1 2 42 5 156 := 12425156
drop count list - Removes count elements from the list.
factor n - Returns a full list of factors of the number n.
filter x y - Filters the list y with the function x. For all values input into x that returns 1, the element is kept, but it is removed when x returns 0.
first list - Keeps the first element of the list, but removes the rest.
gcf a b - Returns the greatest common factor of a and b.
if a then b else c - Checks if a equals 1. If so, then it runs b otherwise it runs c.
input - Gets a line of input from the user.
intersperse a list - Adds the character a after every element in the list.
isprime n - Returns 1 if the n is prime, 0 if it is not.
lcm a b - Returns the least common multiple of a and b.
max list - Returns the numerically highest element in the list.
min list - Returns the numerically lowest element in the list.
unique list - Returns the list, without any duplicate elements.
previous n - Returns the result of the previous computation, n computations in the past. previous 0 is the most recent, previous 1 the one before that, and so forth.
primefactor n - Returns a list of the prime factors of n.
print data - Prints the data to the screen and goes to the next line.
separate data - Takes the data and separates each of its characters into a separate element in a list. Ex. separate 151783518912 := 1 5 1 7 8 3 5 1 8 9 1 2
tail list - Returns all but the first element of the list. Equivalent to drop 1 list.
take count list - Discards all but the first count elements of the list.
this - Used for recursion (see above).