Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aasteria/mylispinterpreter
A simple interpreter for Lisp written in F#
https://github.com/aasteria/mylispinterpreter
Last synced: 29 days ago
JSON representation
A simple interpreter for Lisp written in F#
- Host: GitHub
- URL: https://github.com/aasteria/mylispinterpreter
- Owner: AAsteria
- License: mit
- Created: 2024-10-16T00:38:53.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T06:02:02.000Z (3 months ago)
- Last Synced: 2024-12-07T18:08:59.759Z (29 days ago)
- Language: F#
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MyLispInterpreter
A simple interpreter for Lisp written in F### Build & Run the Project
```bash
dotnet build
dotnet run
```## Features
### Arithmetic Operations- Addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`)
- Supports arbitrary-precision integers (`bigint`)### Variables and Functions
- `define` to bind symbols to values or functions
- `lambda` for creating anonymous functions### Control Structures
- Conditional expressions with `if`
- Sequence execution with `begin`### Macros
- Define macros using `defmacro`
- Macro expansion with parameter substitution### Error Handling
- Exception handling with `try`, `catch`, and `throw`
### List Operations
- `list`, `cons`, `car`, `cdr`, `append`
- Functional operations: `map`, `filter`, `reduce`### Strings
- String literals with double quotes
- String functions: `string-length`, `string-append`, `substring`, `string->list`### Boolean Values
- `true` and `false` literals
- Logical operations with `not`, `and`, `or`### Tail Call Optimization
- Supports proper tail recursion for efficient recursion
### Built-in Functions
- Symbol creation with `symbol`
- Output with `print`## Testing Examples
### Arithmetic Operations
```bash
Lisp> (+ 1 2 3 4 5)
Number 15Lisp> (* 2 3 4)
Number 24Lisp> (- 10 3 2)
Number 5Lisp> (/ 100 5 2)
Number 10
```### Variables and Functions
```bash
Lisp> (define x 10)
Symbol "x"Lisp> x
Number 10Lisp> (define square (lambda (n) (* n n)))
Symbol "square"Lisp> (square 5)
Number 25```
### Control Structures```bash
Lisp> (if true "Yes" "No")
String "Yes"Lisp> (define n 5)
Symbol "n"Lisp> (if (= n 5) (print "n is five") (print "n is not five"))
n is five
Bool true
```### Macros
```bash
Lisp> (defmacro when (condition body)
(list (symbol "if") condition body))
Symbol "when"Lisp> (when true (print "Condition is true"))
Condition is true
Bool trueLisp> (defmacro unless (condition body)
(list (symbol "if") (list (symbol "not") condition) body))
Symbol "unless"Lisp> (unless false (print "Condition is false"))
Condition is false
Bool true
```### Error Handling
```bash
Lisp> (try (/ 1 0) (catch e (print (string-append "Error: " e))))
Error: Division by zero
Bool true
```### List Operations
```bash
Lisp> (define lst (list 1 2 3 4 5))
Symbol "lst"Lisp> (car lst)
Number 1Lisp> (cdr lst)
List [Number 2; Number 3; Number 4; Number 5]Lisp> (cons 0 lst)
List [Number 0; Number 1; Number 2; Number 3; Number 4; Number 5]Lisp> (append lst (list 6 7 8))
List [Number 1; Number 2; Number 3; Number 4; Number 5; Number 6; Number 7; Number 8]Lisp> (map (lambda (x) (* x x)) lst)
List [Number 1; Number 4; Number 9; Number 16; Number 25]```
### Strings
```bash
Lisp> (define greeting "Hello, World!")
Symbol "greeting"Lisp> (string-length greeting)
Number 13Lisp> (substring greeting 7 5)
String "World"Lisp> (string-append greeting " How are you?")
String "Hello, World! How are you?"
```### Tail-Recursive Factorial Function
```bash
Lisp> (define fact (lambda (n acc)
(if (= n 0)
acc
(fact (- n 1) (* n acc)))))
Symbol "fact"Lisp> (fact 5 1)
Number 120
```## License
Notice that this project is under MIT License.