Created
December 11, 2020 21:47
-
-
Save subsetpark/27e30909aa20fce7dddccdf99371c0b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Janet 1.12.2-5df8ac5 linux/x64 - '(doc)' for help | |
repl:1:> (import fugue) | |
nil | |
repl:2:> (fugue/defproto shape ()) | |
@[@{:_prototype_allocations {} :_object-id shape_000006 :_prototype? true :_object-name :shape :_fields () :new <function new-from-shape>} <function shape?>] | |
repl:4:> (fugue/defproto square shape (x {:init? true})) | |
@[<function x> @{:_prototype_allocations {} :_object-id square_00000a :_prototype? true :_object-name :square :_fields (:x) :new <function new-from-square>} <function square?>] | |
repl:5:> (fugue/defproto circle shape (radius {:init? true})) | |
@[<function radius> @{:_prototype_allocations {} :_object-id circle_00000e :_prototype? true :_object-name :circle :_fields (:radius) :new <function new-from-circle>} <function circle?>] | |
repl:8:> (fugue/defproto manifold shape (hypoteneuse? {})) | |
@[<function hypoteneuse?> @{:_prototype_allocations {} :_object-id manifold_00000k :_prototype? true :_object-name :manifold :_fields (:hypoteneuse?) :new <function new-from-manifold>} <function manifold?>] | |
repl:9:> (fugue/defmethod area circle [{:radius radius}] (* math/pi (math/pow radius 2))) | |
@[<function area> @{:_prototype_allocations {} :_object-id circle_00000e :_prototype? true :_object-name :circle :_fields (:radius) :area <function 0x562F3F66DD60> :new <function new-from-circle>}] | |
repl:10:> (fugue/defmethod area square [{:x x}] (math/pow x 2)) | |
@[nil @{:_prototype_allocations {} :_object-id square_00000a :_prototype? true :_object-name :square :_fields (:x) :area <function 0x562F3F66FF90> :new <function new-from-square>}] | |
repl:11:> (fugue/defmethod area shape [self] "This has an area, but I don't know what it is.") | |
@[nil @{:_prototype_allocations {} :_object-id shape_000006 :_prototype? true :_object-name :shape :_fields () :area <function 0x562F3F671040> :new <function new-from-shape>}] | |
repl:12:> (fugue/defgeneric area [x] "Does this even have an area?") | |
<function area> | |
# A demonstration of methods and inheritance | |
repl:13:> (area (:new circle 100)) | |
31415.9 | |
repl:14:> (area (:new square 100)) | |
10000 | |
repl:15:> (area (:new manifold)) | |
"This has an area, but I don't know what it is." | |
repl:16:> (area :blub) | |
"Does this even have an area?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment