On Mon, Aug 06, 2012 at 07:32:42PM -0700, Warren Lynn wrote:
> 
> 
> My reluctance (or allergy as you may suggest) about OOP is toward the 
> > popular 
> > implementations that are insanely verbose. 
> >
> >
> Why is it insanely verbose? Just look at my example:
> 
> (defrecord MyRecord [x y z]
>   (make-record [arg1 arg2 arg3 ...] ...))
> (make-record MyRecord arg1 arg2 arg3 ...)
> 
> How is that more verbose than 
> 
> (defrecord MyRecord [x y z])
> (defn make-MyRecord arg1 arg2 arg3...)
> (make-MyRecord arg1 arg2 arg3 ....)
> 
> I just fixed the name and shuffled things around.

Perhaps I'm missing something, but couldn't you take advantage of the
numerous ways of constructing records, here, and do something like the
following:

    (defrecord MyRecord [x y z])
    (defn ->MyRecord [x y z]
      (MyRecord. (* x 2) (* y 3) (* z 4)))
    
    (->MyRecord 1 2 3) ;=> #user.MyRecord{:a 2, :b 6, :c 12}


So long as you stick with the convention that you always use the
->Record form, then this would be one solution. You could even create a
macro to do this all for you:

    (defmacro defrecord-constructor [name args & body]
      `(do
        (defrecord ~name ~args)
        (defn ~(symbol (str "->" name)) ~args
          (~(symbol (str name ".")) ~@body))))
    
    (defrecord-constructor MyCoolRecord [x y z]
      (* x 2) (* y 3) (* z 4))
    
    (->MyCoolRecord 1 2 3) ;=> #user.MyCoolRecord{:x 2, :y 6, :z 12}

Actually, this is pretty dirty...just something I threw together just
now. I imagine that someone more familiar with Clojure scoping and
binding rules could come up with something much more elegant (I'm fairly
new to Clojure myself).

Honestly, I think this discussion/debate/feature request has little to
do with the merits of OOP vs FP as concepts, and more to do with the
general attitudes held by members of each community. The OOP world tends
to espouse more of a "that's handled for me" approach whereas I've found
FP circles to take the "I'll handle it" approach.

That said, what I like about Clojure (so far) is its willingness to try
and find a middle ground. LISPs have notoriously failed to catch on
because of their insular, built-from-scratch reputation, while OOP
languages almost invariably end up wrapped in as much bureaucracy and
configuration as actual code.

Just my opinion, but I think if you tried something relatively
unobtrusive like the above, and it caught on, you might some day find it
incorporated into the main language. (After all, even the famous "let"
started as a pattern that was made into a macro that ended up in almost
every LISP in use today).

Cheers,

Josh



-- 
Joshua Ballanco

ELC Technologies™
1771 NW Pettygrove Street, Suite 140
Portland, OR, 97209
jballa...@elctech.com

P +1 866.863.7365
F +1 877.658.6313
M +1 646.463.2673
T +90 533.085.5773

http://www.elctech.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to