|
A functional, dynamically typed, list-based programming language. |
https://tysonlang-cd8a7.web.app
- Compile the interpreter
make- Run your program
make tyson fileName.tyson make tyson replThe standard library is included by default. definitions from additional files can also be included.
make tyson fileName.tyson repl def {x} 10
def {y} (+ 1 1)
def {z} {1 2 3 4 5} fun {timesTen y} {* 10 y}A function definition consists of the fun keyword followed by 2 Q-expressions.
- First Q-expr: function name + parameters
- Second Q-expr: function body
The last expression evaluated in the function body is returned upon invocation.
timesTen 20
; -> 200
timesTen "a string"
; -> Error: Cannot operate on non-number!
+ 1 2 3 4 5 6
; -> 21
* 10 20
== 5 5
; -> 1
== 5 4
; -> 0
def {res} (timesTen 20)arithmetic operators such as +, -, * and == are functions like any other in tysonLang and are therefore called using polish notation.
| infix notation (Normal) | Polish notation (TysonLang) |
|---|---|
| 1 + 2 + 3 | + 1 2 3 |
| 5 * 5 | * 5 5 |
| 1 == 2 | == 1 2 |
Everything in a LISP is a list - both source code and data (except functions and symbols). This allows for writing functional code where we pass functions as arguments into other functions. TysonLang has no for or while loops and relies on recursion for iteration.
A line starting with a semicolon is ignored by the interpreter; it's a comment!
TysonLang uses if-expressions instead of if-statements, similar to the ternary operator in Java or C.
if (== 1 1) { "happens if true" } { "this is the else" }we can then print the string that the if expression returns:
print (if (== 1 1) { "happens if true" } { "this is the else" })
; -> "happens if true"select, which is used below, works like a quirky switch statement.
fun {fib n} {
; if item 0 evaluates to true, item 1 gets returned when using select
select
{(== n 0) 0}
{(== n 1) 1}
{otherwise (+ (fib (- n 1)) (fib (- n 2)))}
}For a deeper understanding, including control flow and conditionals, consider reading std.tyson.
Most LISPs, including TysonLang, have 2 types of lists listed below:
A Symbolic expression, commonly shortened to sexpr, is a list where the first element is most often some sort of function or operator that operates on the rest of the list. In tysonLang S-Expressions are enclosed within parentheses: ()
The file containing the standard tyson library is a list of S-Expressions that are all evaluated upon loading the file into the interpreter.
Quoted expressions are a simple type of list that is largely untouched by the interpreter itself. Useful for storing data that we can then manipulate ourselves with functions such as fst that extracts the first element in said list.
LISP stands for LISt Processor.
Mike Tyson voiced himself in the bizarre cartoon Mike Tyson mysteries.
Python is a lisp.
Tyson famously said: “Everyone has a plan until they get punched in the mouth.”
The phrase “Lisp Curse” is a tongue-in-cheek joke about Lisp developers endlessly writing their own new Lisps.
The core of this project is based on the book Build Your Own Lisp which you should absolutely consider reading if you made it this far!
Uses mpc to model the abstract syntax tree.
