Re: How to model a rectangle?

2015-03-05 Thread Felix E. Klee
Looks interesting, thanks! On Thu, Mar 5, 2015 at 4:43 PM, Leon Grapenthin grapenthinl...@gmail.com wrote: (defn rect2 [x y width height] (let [lr [(+ width x) (+ width y)]] (reify Rect (upper-left [_] [x y]) (lower-right [_] lr) (area [_] (* width height) Just

How to model a rectangle?

2015-03-05 Thread Felix E. Klee
Disclaimer: I’ve never done *any* Clojure programming, but I’m curious. Here’s how I may model an on-screen rectangle in JavaScript, a classless object oriented language: let createRectangle = function (x, y, width, height) { return { get upperLeft() {

Re: How to model a rectangle?

2015-03-05 Thread Leon Grapenthin
You could use Clojure protocols. (defprotocol Rect (upper-left [this]) (lower-right [this]) (area [this])) (defn rect1 [x y width height] (reify Rect (upper-left [_] [x y]) (lower-right [_] [ (+ width x) (+ width y)]) (area [_] (* width height (defn rect2 [x y width