Fully fledged lambdas, along with efficiency tweaks across the ast

This commit is contained in:
Ava Apples Affine 2023-03-13 15:02:19 -07:00
parent b0bd369c1d
commit 8efa1dbaad
Signed by: affine
GPG key ID: 3A4645B8CF806069
10 changed files with 264 additions and 70 deletions

View file

@ -152,7 +152,34 @@ CURRENT VALUE AND/OR BODY:
#+END_SRC
*** TODO Quote and Eval
*** TODO Lambda
*** Lambda
Another form of homoiconicity is the *anonymous function*.
This is a nameless function being passed around as data.
It can be bound to a variable, or called directly.
An *anonymous function* is created with the ~lambda~ function.
Here is an example of a lambda function:
#+BEGIN_SRC lisp
(lambda (x y) (add x y))
;; | ^ this is the function body
;; +-> this is the argument list
#+END_SRC
The result of the lambda call is returned as a piece of data.
It can later be called inline or bound to a variable.
Here is an example of an inline lambda call:
#+BEGIN_SRC lisp
((lambda (x y) (add x y)) 1 2)
#+END_SRC
This call returns ~3~.
Here is the lambda bound to a variable inside a let statement:
#+BEGIN_SRC lisp
(let ((adder (lambda (x y) (add x y)))) ;; let form contains one local var
(adder 1 2)) ;; local var (lambda) called here
#+END_SRC
*** TODO Defining variables and functions
**** TODO Anatomy
**** TODO Naming conventions
@ -322,21 +349,6 @@ This contains any executable target of this project. Notably the main shell file
Note: this section will not show the status of each item unless you are viewing it with a proper orgmode viewer.
Note: this section only tracks the state of incomplete TODO items. Having everything on here would be cluttered.
*** TODO Lambda
IMPLEMENTATION:
- [-] implement a new Ctr type to encapsulate function and args
- [ ] need a new case in store for when bound to a var
(honestly store should be rewritten)
- [ ] need a case in eval that mirrors the function call case
DOCUMENTATION:
- [ ] let case for creating and applying a lambda
TEST:
- [ ] lambda to_string input equivalency
- [ ] (eq? ((lambda (x y) (add x y)) 1 2) (add 1 2))
- [ ] let case for creating and applying a lambda
*** TODO list contains via circuit
*** TODO Map function
- DOCUMENTATION + TEST: