> Is that a good way to go? I couldn't find much documentation about how to
> create full immutable application.
> I understand I'm mixing functional and OO principles, I hope I'm not to
> wrong about it.

I've done more or less this exact thing in C# before. What I've found
to be most useful, is to take make yourself a T4 template (or hand
code the classes) that will generate objects in the following format:

public class Point
{
    int _x;
    int _y;
    public Point(int x, int y)
    {
        _x = x;
        _y = y;
    }
    public int X { get { return _x;}}
    public int Y{ get { return _y;}}

    public Point WithX(int x)
    {
          return new Point(x, _y);
    }
    public Point WithY(int y)
   {
          return new Point(_x, y);
   }
}

I say use T4 templates to help you because there will be a ton of code
to write if you don't. What I like about this approach is that you
have the option to modify one member, or all members, depending on
your needs. So if you want to scale a point, you can simply do:

p1 = new Point(1, 1);
p2 = new Point(p1.X * 2, p1.Y * 2);

Or if you only need to modify a single element:

p3 = p2.WithX(0);

----

All that being said...after going down that route, I don't really
recommend it that much. C# was never really designed to work well with
immutable types, it just ends up looking like super ugly clojure code.
If you can, try using ClojureCLR embedded in your app, or even F#.
Both of those will be much easier than trying to do it in C#.


Timothy

-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

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