tisp-v0_1.md (7610B)
1 --- 2 title: "Tisp v0.1 Release" 3 tags: tech programming language project 4 categories: tech 5 date: 2024-11-21 6 --- 7 8 After over 7 years of off-and-on development (but mostly off), 9 I am finally releasing the first version of Tisp, the tiny lisp programming language. 10 Tisp is far from complete or being ready to use in the real world, 11 but I am now satisfied at the current state of features. 12 13 Before the idea of tisp ever formed, I worked on a shell interpreter called [s][]. 14 It is a traditional shell which aimed to replace the complexity of bash. 15 When creating tisp, I brought this experience with me and wanted to make tisp a practical language 16 for everyday interactive use, shell scripting, and quick but powerful one-liners. 17 18 The desire to have a small, simple language, easy to embed or extend with external libraries, 19 originally inspired the creation Tisp. 20 Initially, Lua seemed to fit these requirements, 21 but it lacks expressive power, which leads to verbose and repetitive code. 22 You cannot tailor Lua to the specific domain where you embed it. 23 Lua's imperative nature leads to programs which focus on the step by step operations to solve a problem, not the big picture. 24 This mandatory ceremony adds noise which clutters the core business logic at the heart of the problem solution. 25 Global by default encourages writing messy spaghetti code which manipulates global state, making programs impossible to reason about locally. 26 By more carefully selecting a higher level of abstraction, abandoning the imperative semantics of Lua can lead to an even simpler core language. 27 28 Together this eventually motivated the creation of a new language which combines the simplicity of Lua with the functional and expressive power of lisp and pragmatism of shell. 29 30 [s]: https://github.com/rain-1/s 31 32 # Current Features 33 34 - Interactive read-eval-print-loop (REPL) interface, with readline keybindings [^rlwrap]. 35 - S-expression based homoiconic syntax. 36 - Enables simple yet powerful macros to extend syntax by manipulating code like data. 37 - Prefix syntax for `Func`, `quote`, `quasiqutote`, `unquote`, and `unquote-splice`. 38 - Runtime evaluation 39 - Full language is always available: `read`, `parse`, `eval`, and `print` eevo code during runtime. 40 - Symmetric printing: values are printed in a format that can be read by the parser 41 (with the exception of procedures). 42 - Basic error messages and debugging through backtrace `bt`. 43 - Strings and symbols are interned to reduce memory and enable fast comparisons. 44 - Sizeable core library written in tisp for control flow, lists, stacks, math, and IO. 45 - Builtin documentation for every procedure, accessed through `doc` function at runtime. 46 47 [^rlwrap]: Through the use of [rlwrap](https://github.com/hanslub42/rlwrap). 48 49 # Library 50 51 Tisp is designed as a library first, which can be easily included in any C project (or language with C bindings), 52 or inversely call any library with C bindings. 53 Tisp is essentially just a collection of functions which provide a high-level runtime for C. 54 The language's syntax is defined by the `parse` function, which transforms a string of tisp code into a tisp value. 55 The language's semantics are defined by the `eval` function, which transforms a value into its evaluated form (performing any side-effects along the way). 56 Then the language defines how to display the results with the `display` function.[^MVC] 57 58 [^MVC]: Web and game devs might see this as similar to the model-view-controller design pattern. 59 60 Currently the only application which uses tisp as a library is the default CLI interpreter. 61 Other possible applications include 62 a notebook interface (like [juptyer][] notebook for python), 63 game platform (similar to [love2d][] or [pico-8][]), 64 a text editor (like lua for [neovim][], or elisp for [emacs][]), 65 or a spreadsheet (replacing visual basic). 66 67 [jupyter]: https://jupyter.org/ 68 [love2d]: https://love2d.org/ 69 [pico-8]: https://www.lexaloffle.com/pico-8.php 70 [neovim]: https://neovim.io/ 71 [emacs]: https://www.gnu.org/software/emacs/ 72 73 # Interpreter 74 75 While tisp is a library first, a default interpreter is provided as a standalone executable, 76 enabling execution of tisp programs from the command line. 77 It also serves as an example on how to use tisp as a library. 78 79 - `-r` launch REPL prompt (Default if no other options given). 80 - `-c` run command as tisp code. 81 - `-` read from standard input. 82 - if no hyphen prefix, run program in file. 83 84 # Types 85 86 - Integers, decimals, (with scientific notation for both) and rationals. 87 - Strings 88 - Supporting backslash escape codes for newline, carriage return, tab, and double quote. 89 - Symbols 90 - Variable identifiers as first class objects. 91 - Functions (and primitives from host language) 92 - Including captured environment for closures. 93 - Macros (and special forms from host language) 94 - Functions which operate on syntax, treating code as data. 95 - Pairs 96 - Building block used to construct lists, trees, graphs, stacks, queues, etc. 97 - Nil 98 - Void 99 - Error 100 101 # Variables 102 103 - `True` 104 - All values except `Nil` are truthy, use `True` as explicit true value. 105 - `False` 106 - Equivalent to `Nil` 107 - `bt` 108 - Backtrace of procedure call history which caused error 109 - `version` 110 - String of current version: `"0.1"` 111 112 # Builtins 113 114 Procedures defined by the host runtime (currently only C). 115 Each procedure is either a primitive which behaves like a normal function, 116 or a special form which might not evaluate some of its arguments (eg `quote`, `cond`). 117 See the documentation of each primitive for more information. 118 119 - `car`, `cdr` 120 - `cons` 121 - `quote` 122 - `eval` 123 - `=` 124 - `cond` 125 - `typeof` 126 - `get` 127 - `Func` 128 - `Macro` 129 - `def` 130 - `undefine` 131 - `defined?` 132 - `load` 133 - `error` 134 135 ## IO 136 137 - `read` 138 - `write` 139 - `parse` 140 141 ## OS 142 143 - `cd!` 144 - `pwd` 145 - `now` 146 - `time` 147 148 ## String 149 150 - `Sym` 151 - `Str` 152 153 ## Math 154 155 - `+`, `-`, `*`, `/`, `mod`, `^` 156 - `<`, `>`, `<=`, `>=` 157 - `Int`, `Dec` 158 - `floor`, `ceil`, `round` 159 - `sin`, `cos`, `tan` 160 - `sinh`, `cosh`, `tanh` 161 - `arcsin`, `arccos`, `arctan`, `arcsinh`, `arccosh`, `arctanh` 162 - `exp`, `log` 163 164 # Core Library 165 166 Functions defined in eevo, included by default but not required. 167 168 - `list`, `list*` 169 - `if`, `when`, `unless` 170 - `not`, `and`, `or`, `nand`, `nor` 171 - `let`, `recur`, `switch` 172 - `apply`, `map` 173 - `do`, `do0` 174 - `compose` 175 - `caar`, `cadr`, `cdar`, `cddr`, etc. 176 - Type tests `nil?`, `int?`, `string?`, etc. 177 - `defmacro` 178 - `quasiqutote` 179 180 - `length` 181 - `last`, `nth`, `head`, `tail` 182 - `convert`, `filter`, `keep`, `remove`, `memp`, `member` 183 - `reverse` 184 - `count`, `every?`, `everyp?` 185 - `assoc` 186 - `append`, `zip` 187 - `push`, `pop`, `peek`, `swap` 188 189 - `doc` 190 - `repl` 191 192 ### IO 193 194 - `print`, `display`, `println`, `displayln`, `newline` 195 - `run` 196 197 ### Math 198 199 - `pi`, `tau`, `e` 200 - `/=`, 201 - `inc`, `dec`, `truncate` 202 - `sqr`, `cube`, `root`, `sqrt`, `cbrt` 203 - `logb`, `log10` 204 - `csc`, `sec`, `cot`, `arccsc`, `arcsec`, `arccot` 205 - `csch`, `sech`, `coth`, `arccsch`, `arcsech`, `arccoth` 206 - `abs`, `sgn`, `max`, `min`, 207 - `positive?`, `negative?`, `zero?`, `even?`, `odd?`, 208 - `dot`, `!` 209 210 # Next Steps 211 212 This is likely the first and last release of Tisp. 213 Tisp has always been a temporary name. 214 As the language moves away from the signature lisp style and starts taking more inspiration from 215 other languages, a rebrand is in order. 216 One of the primary motivators for this release is so I can fundamentally change much of core language, 217 such as the syntax, data structures, and type system. 218 219 I have already started implementing a new syntax system built on top of s-expressions, 220 to remove top level parentheses and forced prefix notation. 221 222 While this is the far from the end of the language, a significant revamp is coming.