From: "Philippe maincon" <bogus@see.below.co.za>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webx
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nested functions and oop
Message-ID: <ef2a03b.3@webx.raydaftYaTP>
Date: Fri, 24 Feb 2006 06:48:30 -0500
References: <ef2a03b.-1@webx.raydaftYaTP> <1140772064.500859.38240@e56g2000cwe.googlegroups.com> <10031109B76C1E484F25916E18794767@in.webx.raydaftYaTP>
Lines: 44
NNTP-Posting-Host: 198.54.202.210
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:332863



David, Michael, Brad,

Thank you for your answers, I definitely learned something
interesting today. I will try to summarise what I learned from your
contributions:

- A strong anti-bug feature of Matlab is that a function can only
modify a variable if the variable appears on the left hand side of
the function call. This is thanks to MATLAB's pass by value
[apparent] behaviour. This makes it difficult to have different part
of a software work on the same database (in C++ and the like, objects
would have received a POINTER to the database, and used it to access
the data).

Wether one makes them object-like or not, nest&handle allows to pass
to a function THE RIGHT TO DO A SPECIFIC OPERATION on a set of data.
This breaks the above anti-bug rule, but in a very elegant manner:
IfUserWants(a.makeItGreen);
The function IfUserWants can modify the data in "a" but only in one
way: "makeItGreen" It can't make it red or erase it...

A significant advantage over pointers is that "the last one out
switches off the light", or at least, I strongly suspect so. Once the
function handles are generated they "point" to the data, and you can
copy these handles (this acts as "shallow copy"). In C++ et al., if
you delete all your pointers, you have a memory leak. Here... you can
distribute "pointers" around, and yet do not need to bother about a
destructor.

- One can "hack" nested functiosn & handles to create hack-object,
but note the unusual (hence risky) features:
a = b is a shallow copy for hack-objects, and a deep copy for
standard objects... For hack-objects, function argument passage is by
reference, for standard objects, it's by value. If you pass a
hack-object to a function, you basicaly pass the rights to do all
permissible operations.

I certainly retract the comment that nest&handle provides nothing
new. As for hack-objects, I reckon a) there is a market for them b)
be very, very cautious!

Regards

Philippe