Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify our eval() method. #97

Merged
merged 11 commits into from
Nov 20, 2022
Merged

Simplify our eval() method. #97

merged 11 commits into from
Nov 20, 2022

Conversation

skx
Copy link
Owner

@skx skx commented Nov 13, 2022

This commit is the first in a chain that will close #94, by simplifying our eval method.

Here we've recognized that all of our simple types return themselves when they're evaluated - so we've created a simple "IsSimpleType" in our primitive interface.

This makes it easy for simple things to return themselves, and no longer need to have a special case.

This commit is the first in a chain that will close #94, by
simplifying our eval method.

Here we've recognized that all of our simple types return
themselves when they're evaluated - so we've created a simple
"IsSimpleType" in our primitive interface.

This makes it easy for simple things to return themselves,
and no longer need to have a special case.
This has two goals:

* Isolates the special forms in one location.

* Removes the clutter from our eval method.
We still need to rework the struct-stuff, but I'm happier already.
Change the parseing of numbers to use 64-bit too.
* Move the type-checking into a function.
* Update the variadic argument as we go around the loop
Sample code:

```lisp

;; define a structure
(struct animal name species)

;; create some instances of that structure
(set! cat (animal "tibs" "cat"))
(set! dog (animal "spot" "dog"))

;; Create a function using that structure as a typed-parameter
(set! greet (fn* (an:animal)
                 "Greet an animal"
                 (print "Hello %s you're the best %s I've ever seen!"
                        (animal.name an) (animal.species an))))

(greet cat)
(greet dog)

;;
;; Error executing types.lisp:
;;    TypeError - argument an to greet was supposed to be animal, got string
;;
;; (greet "Steve")
;;
;; Error executing types.lisp:
;;    TypeError - argument an to greet was supposed to be animal, got number
;;
;; (greet 3)

```
@skx skx merged commit 54cfa70 into master Nov 20, 2022
@skx skx deleted the 94-eval branch November 20, 2022 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eval is getting out of hand.
1 participant