proj-oot-ww

--

toread++: https://speakerdeck.com/stilkov/clojure-for-oop-folks-how-to-design-clojure-programs

toread http://www.slideshare.net/yoavrubin/oop-clojure-style-long

--

http://javascript.crockford.com/prototypal.html

--

Scoping

We need:

one idea is to start with Python's "self", make it more implicit, and fit it into Oot.

how about:

i also have this idea that 'me' should be generalized somehow to allow one to refer to labeled scope boundaries, but in a dynamic, 'instancey' way. and maybe it's silly to have 'me' be implicitly added to each fn call.

maybe the object scope is actually a function, and 'me' is an optional keyword argument.

in which case we still need a way to get unbound methods; that is, we need a way to take inner functions out of their parent functions (their closure) and to prepend the variables that they are using from the closure.

e.g. a point object:

def point(me, x, y): int x; int y; def add_to(me, other): return point(new(), me.x+other.x, me.y+other.y)

however we want to be able to do the immutable stuff implicitly as if we are mutating our own state so:

def point(me, x, y): int x; int y; def add_to(other): me.x += other.x me.y += other.y

somehow we have to know that 'me' is the thing to which the implicit demutability is being applied

to construct a new point: point(new(), x, y)? or do we want to have some weird "new" macro and to do new(point(x,y))?

and do we want object declaration syntax? e.g.

obj point(x, y): int x; int y; def add_to(other): me.x += other.x me.y += other.y

if so how to generalize to arbitrary, multiply layered labeled scope boundaries?

obj(me) point(x, y): int x; int y; def add_to(other): me.x += other.x me.y += other.y

--

note: the idea of an object's state just sitting in a variable in the outer scope of the object is just the idea of using closures to hold state.

which is of course what Clojure does.

in Clojure, if you want a mutable value, or you want mutation, you must explicitly ask for one/it:

( defn make-counter [initial-value] (let [current-value (atom initial-value)] (fn [] (swap! current-value inc))))

(example from http://s3-eu-west-1.amazonaws.com/presentations2013/30_presentation.pdf )

--

clojure defmulti multimethods are interesting (i dont entirely understand how dispatching works, it uses isa?), but oot will be able to do them with metadata

pages 57-59 https://speakerd.s3.amazonaws.com/presentations/2471a370b3610130440476a0f7eede16/2013-05-17-ClojureOOP-Geecon.pdf :

( defmulti area :kind ) ( defmethod area :rectangle [{ :keys [a b]}] (

( defmulti draw-shape ( fn [shape canvas] [( :kind shape) ( :type canvas)])) ( defmethod draw-shape :default [shape canvas] ( str "Drawing " ( :kind shape) " on " ( :type canvas))) ( defmethod draw-shape [ :circle :print-canvas ] [shape canvas] "Printing a circle" ) ( defmethod draw-shape [ :rectangle :display-canvas ] [shape canvas] "Showing a rectangle" )

---

the LimitedPrecisionSuccessorNaturalNumber? has a special relationship to the SuccessorNaturalNumber? interface; namely, it's partially defined, but equal wherever it is defined (e.g. sometimes you add one to a LimitedPrecisionSuccessorNaturalNumber? and get an overflow exception, or equivalently, an overflow sentinel value). should represent that in the language.