Carp/examples/derive.carp
Veit Heller 02936cc74c
feat: Derive (#1120)
* core: add derive

* fix: fix errors with set!

Notably, don't type check dynamic bindings (which can be set to
whatever) and eliminate a hang that resulted from not handling an error
at the end of the `set!` call. Also refactors some of the code in
efforts to make it a bit cleaner.

Also adds an error when `set!` can't find the variable one calls set!
on.

* feat: better derive

* test: add error test for derive

* document derive

* add derive to core documentation to generate

* core: add derive

* fix: fix errors with set!

Notably, don't type check dynamic bindings (which can be set to
whatever) and eliminate a hang that resulted from not handling an error
at the end of the `set!` call. Also refactors some of the code in
efforts to make it a bit cleaner.

Also adds an error when `set!` can't find the variable one calls set!
on.

* feat: better derive

* document derive

* feat: first completely working version of derive

* feat: make name of derivable customizable (thanks @scolsen)

* refactor: implement doc edits provided by @scolsen

* feat: change argument order for derive

* fix: change deriver error test

* test: add derive tests

* fix: change order of derive back

* docs: fix typo in derive document

Co-authored-by: scottolsen <scg.olsen@gmail.com>
2021-01-15 10:48:34 +01:00

19 lines
429 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

; lets make inc and dec derivable
(make-update-deriver 'inc)
(make-update-deriver 'dec)
(deftype T [x Int y Int z Int])
(derive T inc)
(derive T dec)
(derive T zero)
(derive T str)
(derive T = eq)
(defn main []
(do
(println* &(T.inc (T.init 1 2 3)))
(println* &(T.dec (T.init 1 2 3)))
(println* &(T.zero))
(println* (= &(T.init 1 2 3) &(T.init 1 2 3)))
(println* (= &(T.init 1 2 3) &(T.init 1 3 2)))))