On Oct 16, 2012, at 1:19 PM, Arlen Cuss wrote:
> My initial solution is to freeze all strings in the reader.  This prevents 
> the most obvious issues, as it means any string read in from the Rouge code 
> itself is immutable.

A problem with `freeze` in Ruby is that it both prevents changing the contents 
of an object and also the methods attached to it. I find it useful sometimes to 
take an immutable object and create a new object with a different 
interpretation:

     hash.become(TimesliceShaped)

What that does is produce an object with some new singleton methods. That lets 
me do something like Clojure's `->` or the common Ruby "boxcar notation":

     timeslice.transform.update

It makes the code more readable.

This is also vaguely analogous to multimethods. The point is that we want the 
functions applicable to an object to be mutable but the contents of the object 
to be immutable.


-----
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
Writing /Functional Programming for the Object-Oriented Programmer/: 
https://leanpub.com/fp-oo


-- 
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