[Sorry, forgot to send this to the list]

On 12/3/05, Paolo Veronelli <[EMAIL PROTECTED]> wrote:
Thanks for your help. I wonder why there is no IRC for new comers .....
But, I wrote a piece of code (runnable :P) ,I just don't like it .
All those nested makers are necessary?
If someone can hint me on a better way to program in I will be happier.

I'm not sure... it looks at first glance like you're trying to split a dictionary, using an object to store data in the meantime. Since all the attributes are essentially public--it looks like you're using a C-style algorithm--using Mozarts objects might not be the way to go, since they do entail a peculiar syntax. Are these data structures persistent, or temporaries only for the one-shot splitting? If the latter, I'd use higher-order functions, dictionaries and an ADT style, and hide the attributes with lexical scoping instead.

Then at the end, you got something like this:

proc {Check}     % pos is a dictionary[1], being used like a C-struct
   if {Length {D.keys pos.prole }} > max then
       if pos.father == none then
           pos.father = {NewPos}    % returns a new dictionary/struct with appropriate fields initialized
                {AddChild pos.father pos}
                local Brother = {NewPos}
                        in
                        {AddChild pos.father Brother}
etc.

I think C++ and sometimes Java use classes and objects in a way that doesn't fit well with the original "object-oriented" approach of e.g. Smalltalk. Mozart's objects seem to be especially suited to Smalltalk-style algorithms (i.e. only send messages, don't access "public" data members). I don't think your algorithm fits into this category. Admittedly I may have misread where your dissatisfaction lies.

Max Wilson


[1] If you're concerned about efficiency, and the number of data fields is fixed, you could use an array instead, as long as you have a set of variables for each index. E.g. Father = 1, Children = 2, etc. Then you call pos.Father instead of pos.father, but you get to use array indexing instead of dictionary indexing. I don't actually know how much more efficient this is except that dictionaries are an O(1) operation too.

--
Be pretty if you are,
Be witty if you can,
But be cheerful if it kills you.
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to