[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: thoughts on onCleanup and handle classes
From: |
Jaroslav Hajek |
Subject: |
Re: thoughts on onCleanup and handle classes |
Date: |
Tue, 18 May 2010 21:02:40 +0200 |
On Tue, May 18, 2010 at 5:51 PM, John W. Eaton <address@hidden> wrote:
> On 18-May-2010, Jaroslav Hajek wrote:
>
> | comments, suggestions? OK to push?
>
> It would be nice to have this functionality, as I think it has already
> been reported as missing a few times.
>
> I originally objected to the idea of implementing it apart from handle
> classes because I thought there would be too many differences between
> a one-off C++ implementation and the way it would work if implemented
> using a handle class object. But maybe that doesn't matter anyway, if
> all the normal use cases are handled.
>
I think so. Just to be clear, I agree that having it done via handle
classes would be better, but I think that Octave is far away from
handle classes and the onCleanup functionality is useful per se. In
particular, it can be used to implement (pseudo-) destructors for
value classes, which is something I can use. Another possible usage is
implementing the "local" parameter for user-defined pseudo-variables.
> In Matlab, what happens for the following
>
> %% argument is not a function handle
> c = onCleanup (1)
> clear c
>
I don't know, but the Matlab docs say the argument must be a function
handle (and apparently must be present). The docs also suggest that
the handle must take zero arguments, but because that is not crucial,
I merely made it a warning.
> With your patch, Octave complains that the argument is not a function
> handle. Is Matlab that strict? If not, then is there some reason to
> allow arguments other than function handles?
>
> c = onCleanup (@() disp ('foobar'))
> save foo.mat
> clear all
> load foo.mat
> c
>
> If the value is preserved, then what should we do? I would guess that
> it is not too helpful to save and restore cleanup functions, so it
> seems that it should be OK to just skip them as Octave does now with
> your patch.
Yes, I agree skipping them would be the best thing. Although function
handles can be saved and loaded, that still doesn't mean the cleanup
action is going to be meaningful after load. I suppose that usually
the user actually doesn't want c to be saved at all.
>
> c = onCleanup (@() disp ('foobar'))
> isa (c, 'class')
> isa (c, 'handle')
>
> Will it cause trouble if Matlab returns true for "isa (c, 'handle')"
> and Octave does not? I don't see how faking this in Octave would
> help, as we don't have handle classes.
Agreed. I think we need not care until there actually are handle
classes. Personally, I decided not to work anymore on new-style
classes unless I have an easy access to Matlab version that supports
them (I only have 2007a now). With onCleanup I'm breaking this a
little, but only because I have uses of the functionality for my own
purposes.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
Re: thoughts on onCleanup and handle classes, David Bateman, 2010/05/18