Broccoli is an exciting new programming language that is guaranteed to make you pee your pants (in a good way).
this guide can be found online here
Get the executable:
- Post an issue with desired OS target if it's not here
Quick Start:
- Unpack the Broccoli binary
- To run Broccoli's REPL type the following
./broccoli
- To see a list of commands available type
(help)
Broccoli supports the following datatypes:
- integer (mapped to 64-bit long)
- floating point (mapped to double precision float)
- boolean (t, nil)
- atom
- string
- list
Scalar variables (e.g. int, float, boolean, atom, string) in Broccoli take the form $name
Collection variables (e.g. list) take the form @name
Shows the list of available commands and keywords.
Quits the Broccoli REPL
Clears the Broccoli REPL's internal memory of all elements.
Clears the Broccoli REPL's internal memory of all elements, except structure definitions.
Takes a string and evaluates it as if it was typed into the command prompt.
Takes a function name and 0* arguments and calls the former with the latter.
(call + 2 3)
=> 5
Takes a string pointing to an external file and evaluates its contents as if they had been typed into the command prompt.
Takes a string pointing to an external file and evaluates only its constructs (i.e. functions and bindings).
Takes any valid Broccoli expression and times its execution, returning the number of seconds it took to execute.
Prints text to the console by default. The print function takes 1 or more arguments, including the special symbols endl and tab.
See what happens when you type the following into the REPL:
(print "This is the number two" tab 2 endl)
(print "This is also the number two" tab (/ 100 50) endl)
(:= $two 2)
(print "This is the number two" tab $two endl)
Creates a list of the arguments given.
Returns the number of items in a list
Given a list, returns its first element
Given a list, returns a list of all but its first element
Given a list, a start index, and an end index, returns a sub-list slice of the original
Generates a list containing the fill of the range given
Example:
(range -5 2)
=> (-5 -4 -3 -2 -1 0 1 2)
Concatenates two or more lists
Example:
(cat (list a b c) (list 1 2 3))
=> (a b c 1 2 3)
Add, multiply. Each takes 0 or more arguments.
Subtract, Divide. Each takes 1 or more arguments.
Assignment operator of the form (:= $var <expression>)
.
Example:
(:= $pi 3.14)
Converts a number to either an integer or float respectively.
Checks if the first value is equal to every other value.
Checks if the first value is not equal to every other value.
Checks if the numeric values are in strictly descending order.
Checks if the numeric values are in strictly ascending order.
Checks if the numeric values are in descending order.
Checks if the numeric values are in ascending order.
Reverses the truth value of a boolean value.
Logical and of zero or more truth values.
Logical or of zero or more truth values.
Iterates through the contents of a list
Example
(for $e in (list a b c)
(print $e endl)
)
In order to iterate a given number of times, the (for)
loop can be combined with the (range)
function:
Example
(for $e in (range 0 5)
(print $e endl)
)
The basic if-then statement.
Example
(if (t /= nil)
(print Always prints endl)
else
(print Never prints endl)
)
The broccoli.broc file contains extended functions written in the Broccoli language and loaded (when present) at the interpreter's start.
Takes a number n and returns the nth Fibonacci number (1-indexed).
Calculates the factorial of a given number.
Takes a function name and a list and applies it to each element, returning a list of the results.
Example
(map fib (list 1 2 3 4 5))
=> (1 1 2 3 5)
Takes a function name and a list and reduces the list according to the function, returning an aggregate value.
Example
(reduce + (list 1 2 3 4 5))
=> 15
Takes a function name and a list and returns the values that the function returns true for.
Example
(fn gt10 ($num) (if (< 10 $num) t else nil))
(filter gt10 (list 1 2 10 11 23 6 9 1000))
=> (1000 23 11)