Total LISTP
Total LISTP, pronounced "to-tal listp", is an esoteric LISP-like programming language that always halts (which makes it usable on a total Turing machine). This description is work-in-progress and open to ideas.
Syntax
Brackets, curly brackets, and parentheses may all be used as parentheses are in normal LISP, as long as they are properly matched. Semicolons and commas are treated as whitespace. Comments start with hashtag/pound/number sign #.
Semantics
Uses term-rewriting. Symbols have LISP-1 semantics. Definition overloading using argument count. No macros as known in other LISPs. There are no "multiple values", lists can be returned instead.
{def <expr1> <expr2>}
# define a variable or function
examples:
{def a 3} # a = 3 (a variable is like a 0-argument function) {def (a x) (+ 1 x)} # the old definition of a is overrided with this new one
- {def+ <expr1> <expr2>} # overload a definition of a variable or function
examples:
{def b 1} {def+ {b x} (+ b x)} # b is overloaded as a variable 1 and also a function that adds b (the variable) to x
- {fun [<sym>...] <expr>} # like lambda
- {dotimes [<sym> <expr>] <expr>}
- {repeat <expr> <expr>}
- {dolist <expr:list> <expr>} # linear lists only
- (display <expr>)
- (read-char)
- (emit-char)
- (read)
- (eval <expr>)
- {do <expr> ...}
- (/ x y) # x divided by y, if y is 0, then returns 0
- (* x y) # x multiplied by y
- (+ x y) # x added to y
- (- x y) # difference of x and y
- (sum <expr> ...) # sum of expressions (addition)
- (product <expr> ...) # product of expressions (multiplication)
Examples
Hello world
[display "hello world"]
99 bottles
(def bottles {fun [n] {do {cond {(= n 0) (display "No more bottles")} {(= n 1) (display "One bottle")} {else (display n) (display " bottles")}} (display " of beer")}}) {dotimes [n 99] {if (> n 0) {do (bottles n) (display " on the wall") (newline) (bottles n) (newline) (display "Take one down, pass it around") (newline) (bottles (1- n)) (display " on the wall") (newline) (newline))}}}
Total cat
Halting cat program. Takes the number of characters to repeat and then repeats that many characters.
[repeat (read) (display {or (read-char) (halt)})]