Skip to content

NivenT/RLisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RLisp

Simple Lisp dialect written in Rust currently under development.

This project is a redo of my Math-Lisp repository. The code in that repositiory became messy and hacked together over time, so I decided it would be best to just start from scratch. This interpreter will, ideally, have more structured and readable code.

How to Build/Run

Install Rust and then navigate to the src directory in command prompt (or terminal). Then run "cargo build" and the project should be built for you. To then run it either type "cargo run" into command prompt or navigate to the created application file.

How to Use

Because this is a Lisp Interpreter, it makes use of a REPL. Enter your command and hit enter to see the result. Afterwards, repeat. Press Ctrl+c to quit.

Check the src/std.rlisp for examples of valid code

Native Functions/Special Forms (Incomplete list)

Function Description Example input Corresponding output
+,-,*,/ Basic math functions (* (+ 19 (- 5 4)) (/ 2 4)) 10

,>=,<,<=,= | comparisons | (> 10 4) | T list | Creates a list containing the passed arguments | (list 1 2 3 4 5 6) | (1 2 3 4 5 6) car | Returns first element of list | (car (list 1 2 3 4)) | 1 cdr | Returns all but the first element of a list | (cdr (list 1 2 3 4)) | (2 3 4) cons | cons's the two arguments together | (cons 0 (list 1 2)) | (0 1 2) nth | returns the nth element of a list | (nth 2 (list 0 1 2 3 4)) | 2 nthcdr | returns all but the first n elements of a list | (nthcdr 3 (list 1 2 3 4 5)) | (4 5) define | sets value of a symbol | (define x 10) / (+ x 5) | 10 / 15 if | executes statement if condition is not nil | (if (= 5 5) 2 3) | 2 lambda | creates an anonymous function | ((lambda (x y) (+ x y)) 4 3) | 7 defun | shorthand for a combination of define and lambda | (defun add (x y) (+ x y)) / (add 10 22) | 32 ' or quote | returns the input unevaluated | '(1 2 3) | (1 2 3) ` or backquote | returns the input, only evaluating expressions after commas | `(1 2 ,(+ 1 2)) | (1 2 3) let | creates temporary variables and evaluates an expression | (let ((a 2) (b 4)) (+ a b)) | 6 let* | sames as let but variables can be defined in terms of previous variables | (let* ((a 2) (b (+ a 2))) (+ a b)) | 6 progn | evaluates multiple forms, returning the last one | (progn (define x 1) (define x (* 2 x)) x) | 2 load | opens a file, wraps contents in progn, and evaluates | sample.txt: (defun abs (n) ((if (> n 0) + -) n)) (abs -4)) REPL: (load "sample.txt") | 4

  • / is used to separate different inputs

TODO (in no particular order)

  • Add more native functions
  • Add special forms
  • Add macros
  • Allow user to modify environment
  • Add quote and backquote
  • Make error messages more helpful
  • Add functions written in RLisp
  • Improve speed
  • Fix string parsing
  • Store last result (stored in variable %%%)
  • Perfect lambda expressions
  • Add optional parameters
  • Add rest parameter
  • Add cond and case
  • Add BigInt class

About

Simple Lisp dialect written in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages