Hal is a scheme interpreter
The Makefile use stack. You should install it before building hal.
make
The REPL is an interactive interpreter.
You can launch it with -i flag:
./hal -i
The hal interpreter can also interpret scheme files.
./hal [filenames]
Hal allow you to launch REPL after or before interpreting files and keep the context between files and REPL's inputs.
./hal [filenames] -i
or
./hal -i [filenames]
You can load hal stdlib by setting HAL_STD environment variable to the path of stdlib folder.
Only files with .scm, .sps, .sls, .sld, .lisp extensions will be interpreted in this folder.
| Type | Description | Example | Note |
|---|---|---|---|
| number | An arbitrary precision integer | 42 | In next versions number will fit floats and rationals |
| char | A Char is a single unicode character | #\a | |
| boolean | A boolean can be equal to #t (true) or #f (false) | #t | |
| string | A type which represent a text | "hello world" | In next versions string will be a list of chars |
| pair | A pair is a type that can hold 2 elements of any types | '(6 . 7) | An explicit pair should be quoted |
| list | A list is a linked list made of pairs | '(6 7 #\b "hello") | An explicit list should be quoted |
| symbol | A symbol is an atomic value that represented like an identifier preceded with `'` | 'hello | |
| procedure | A procedure is a function | (sort '(3 2 1)) | A procedure should be apply with `(..)` to be executed |
| void | Void is an empty type |
| Name | Description |
|---|---|
| cond | A cond statement take lists, if an expression of a list is false cond jump to the next list |
| else | Else can be used in cond statement. Else is the last cond clause executed. |
| => | `=>` can be used in cond statement. The arrow apply procedure on the right side on expression on the left side. |
| if | If work like standard if statement in other languages |
| and | And take many expressions. If one expression is false `and` return false otherwise return the last argument. |
| or | Or take many expressions. Return the first not false expression. |
| Name | Description |
|---|---|
| (apply procedure [exprs]) | Apply a procedure on list of exprs as arguments |
| (eval expr) | Evaluate an expression |
| (+ ...numbers) | Return sum of all arguments |
| (- ...numbers) | Return negative sum of all arguments |
| (* ...numbers) | Return product of all arguments |
| (div n1 n2) | Divide n1 by n2 |
| (mod n1 n2) | Return n1 modulo n2 |
| (< ...numbers) | Return true if arguments are strictly increasing |
| (> ...numbers) | Return true if arguments are strictly decreasing |
| (cons x1 x2) | Take 2 expressions and return a pair made of them |
| (car list) | Return the first element of a list/pair called `car` |
| (cdr list) | Return values from the second element of list/pair called `cdr` |
| (eq? x1 x2) | Return true if x1 and x2 are equals |
| (eqv? x1 x2) | Return true if x1 and x2 are equivalents |
| (= n1 n2) | Return true if n1 and n2 are equals |
| (string=? ...strings) | Return true if all strings are equals |
| (string->symbol str) | Convert string to symbol |
| (symbol->string symbol) | Convert symbol to string |
| (string->list str) | Convert string to list |
| (list->string str) | Convert list to string |
| (string->number str) | Convert string to number |
| (type? expr) | Return type of an expression |
| Name | Description |
|---|---|
| (list ...lists) | Make a list composed with arguments |
| (make-list k expr) | Make a list of size `k` fill with `expr` |
| (sort list) | Sort a list in ascending order |
| (fold-right fn end lst) | Recude list from first to last |
| (fold-left fn acc lst) | Reduce list from last to first |
| (map p lst) | Apply a procedure over list elements |
| (filter p lst) | Filter a list with a procedure |
| (member x lst) | If `x` is in `lst` return list from associated pair of `x` else return false |
| (list-ref lst idx) | Get element in list at index `idx` |
| (append ...lists) | Concatenate lists |
| (reverse lst) | Reverse list elements |
| (length lst) | Return length of a list |
| Name | Description |
|---|---|
| (fact n) | Factorial n |
| (expt x n) | x^n |
| (fib n) | Fibonacci sequence at n |
| (odd? n) | Check if number is odd |
| (even? n) | Check if number is even |
| (positive? n) | Check if number is positive |
| (negative? n) | Check if number is negative |
| (zero? n) | Check if number is nul |
| Name | Description |
|---|---|
| (string-null? str) | Check if string is null |
| (make-string k c) | Make string of size `k` fill with char `c` |
| (string ...chars) | Make string from `chars` |
| (string-length str) | Return size of string |
| (string-ref str i) | Return char at position `i` in string `str` |
| (string-append ...strs) | Concat some string |
| Name | Description |
|---|---|
| (string? x) | Check if `x` is a string |
| (number? x) | Check if `x` is a number |
| (list? x) | Check if `x` is a list |
| (pair? x) | Check if `x` is a pair |
| (boolean? x) | Check if `x` is a boolean |
| (procedure? x) | Check if `x` is a procedure |
| (symbol? x) | Check if `x` is a symbol |
| (char? x) | Check if `x` is a char |
| (atom? x) | Check if `x` is an atom |
| Name | Description |
|---|---|
| (not x) | If `x` equal false return true otherwise return false |
- IO
- Modules with export/import system
- Some chez-scheme procedures implementation