lotsa notes

This commit is contained in:
Jay McCarthy 2015-12-22 20:02:28 -05:00
parent 2be5cf01ec
commit dde82280a2
3 changed files with 71 additions and 4 deletions

View File

@ -1,3 +1,6 @@
TODO add ; back into braces but don't have , because of conflict with
its ,
TODO add syntax property for def transformer on RHS (for function call TODO add syntax property for def transformer on RHS (for function call
results, alloc, etc) results, alloc, etc)

View File

@ -0,0 +1,62 @@
;; THEORIES + MODELS
;; A theory is a specification of some values
(def [theory Monoid]
op id)
;; XXX specify properties
;; A model is an object that satisfies the theory
(def zero 0)
(def [model Monoid Nat+Monoid]
[op +]
;; XXX lift non-identifiers
[id zero])
;; XXX verify properties
;; INTERFACES + OBJECTS
;; An interface is just a vtable specification (theory)
;; An implementation is a vtable (model)
;; A class is a set of implementations and a representation
;; +---> (+) private : representation is available
;; +---> ( ) open : no rep, new implementations can be added
;; +---> (-) closed : no rep, no new imps
;; An object is a sealed pair of a class and a layout
(def [interface 2d<%>]
translate
area)
(def [class +Circle Circle -Circle]
#:layout circle
#:new (λ (x y r)
;; this is the layout of the object wrapper
;;
;; alternatively, make this something that assumes you want
;; the below and acts like it.
(this.#:alloc
[rep (circle.#:alloc [c (posn.#:alloc [x x] [y y])]
[r r])])))
;; This implementation uses +Circle, so it has access to the
;; representation.
(def [implementation 2d<%> +Circle]
[translate
;; this is +Circle
(λ (this)
{this.#:set
[c (this.c.#:set [x {x + this.c.x}]
[y {y + this.c.y}])]})]
[area
(λ (this)
{3 * this.r * this.r})])
;; Here's a contrived example of using Circle, where you can add
;; things but don't have the representation (i.e. you can implement it
;; based on other things it has)
(def [interface 2dview<%>]
view-area)
(def [implementation 2dview<%> Circle #:is 2d<%>]
[view-area
;; this is 2d<%>
(λ (this) (this.area))])

View File

@ -373,7 +373,8 @@ def x4
(module+ test (module+ test
;; You will get an allocation function named #:alloc ;; You will get an allocation function named #:alloc
(def [posn p1] (posn.#:alloc [x 5] [y 7])) (def [posn p1] (posn.#:alloc [x 5] [y 7]))
;; XXX (def [posn p1] #:alloc [x 5] [y 7]) ;; XXX (def [posn p1] #:alloc [x 5] [y 7]) <--- def transformer for allocation
;; XXX (def [posn p1] (posn [x 5] [y 7])) <--- default use is allocation
;; And accessors ;; And accessors
{p1.x 5} {p1.x 5}
{p1.y 7} {p1.y 7}
@ -381,8 +382,7 @@ def x4
;; that gave us access to these. We can, of course, just call them ;; that gave us access to these. We can, of course, just call them
;; directly through posn. ;; directly through posn.
{(posn.x p1) 5} {(posn.x p1) 5}
;; You will also get a copying function (XXX: Should it be named ;; You will also get a copying function
;; `copy`? `update`? My analogy here is with hash-set)
(def [posn p2] (p1.#:set [y {p1.y + 2}])) (def [posn p2] (p1.#:set [y {p1.y + 2}]))
;; Notice that these built-in functions are keywords, so that they ;; Notice that these built-in functions are keywords, so that they
;; can't conflict with the fields you've defined. ;; can't conflict with the fields you've defined.
@ -418,7 +418,8 @@ def x4
{qpq1.y 2} {qpq1.y 2}
{qpq1.z 3}) {qpq1.z 3})
;; XXX Does it do the "right thing" for copying? ;; XXX Does it do the "right thing" for copying? (i.e. when a parent
;; copies, do the child's fields get copied as is)
;; A layout's fields may be specified as other layouts. When the first ;; A layout's fields may be specified as other layouts. When the first
;; field is a layout, this is not necessarily the same thing as a ;; field is a layout, this is not necessarily the same thing as a
@ -507,3 +508,4 @@ def x4
{even1.o.e.e 0} {even1.o.e.e 0}
{even1.o.e.o.o 1} {even1.o.e.o.o 1}
{even1.o.e.o.e.e 0}) {even1.o.e.o.e.e 0})