octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cellfun calling style


From: John W. Eaton
Subject: Re: cellfun calling style
Date: Wed, 21 Sep 2011 18:32:18 -0400

On 21-Sep-2011, John W. Eaton wrote:

| On 20-Sep-2011, John W. Eaton wrote:
| 
| | On 20-Sep-2011, Jordi Gutiérrez Hermoso wrote:
| | 
| | | On 20 September 2011 14:54, John W. Eaton <address@hidden> wrote:
| | | > On 20-Sep-2011, Rik wrote:
| | | 
| | | > | octave_value f = symbol_table::find_function (func.function_value ()
| | | > |                                                          -> name ());
| | | >
| | | > We probably don't want to do that because I think it will screw up
| | | > cases where people actually do want to use the function handle for
| | | > purposes of finding the right overloaded function to call.
| | | 
| | | Isn't that what I did here?
| | | 
| | |     
http://hg.savannah.gnu.org/hgweb/octave/annotate/9b8e786bbf3c/src/DLD-FUNCTIONS/cellfun.cc#l357
| | 
| | I think that's OK if the is_overloaded function is always giving
| | you the correct result.
| | 
| | I'll be able to say more when I am able to come up with a simple
| | example that demonstrates the bug I've found.
| 
| OK, here is what I can say now.  The code is small, so I'm inserting
| it all here, but it is also attached in the tar file for easy
| extraction and experimentation if anyone is interested.
| 
| First, I have two classes, one derived from the other.  These are the
| constructors.  The parent class overloads the numel function.
| 
|   ------------------
|   @derived/derived.m
|   ------------------
| 
|   function r = derived (n)
|     s.a = n;
|     p = parent (n);
|     r = class (s, 'derived', p);
|   end
| 
|   ----------------
|   @parent/parent.m
|   ----------------
| 
|   function r = parent (n)
|     s.a = rand (n, 1);
|     r = class (s, 'parent');
|   end
| 
|   ---------------
|   @parent/numel.m
|   ---------------
| 
|   function r = numel (x, varargin)
|     disp ('in @parent/numel.m');
|     r = numel (x.a, varargin{:});
|   end

The problem can be simplified much more.  Using just the above three
functions:

  octave:1> d = derived (13);
  octave:2> numel (d)
  in @parent/numel.m
  ans =  13
  octave:3> f = @numel;
  octave:4> f (d)
  ans =  1

Oops.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]