octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #45969] Inner scopes of nested anonymous funct


From: Olaf Till
Subject: [Octave-bug-tracker] [bug #45969] Inner scopes of nested anonymous function definitions are not saved.
Date: Tue, 15 Sep 2015 08:51:14 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.8.0

URL:
  <http://savannah.gnu.org/bugs/?45969>

                 Summary: Inner scopes of nested anonymous function
definitions are not saved.
                 Project: GNU Octave
            Submitted by: i7tiol
            Submitted on: Tue 15 Sep 2015 08:51:13 AM GMT
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Olaf Till
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: GNU/Linux

    _______________________________________________________

Details:

Anonymous functions handles contain an own scope with the variables they
inherited from the parent scope. If anonymous function handles are saved
(ascii, binary, or hdf5), the variables of this scope are also saved. But
currently, if anonymous function definitions are nested (e.g.

@() @() a

), the variables in the scopes of the 'inner' anonymous functions (variable
'a' in

... @() a

in the example) are not saved.

Simple example for triggering this bug:


octave:1> a = 1;
octave:2> f = @ () @ () a
f =

@() @() a

octave:3> save ("test-ascii.dat", "f")
octave:4> save ("-binary", "test-binary.dat", "f")
octave:5> save ("-hdf5", "test-hdf5.dat", "f")
octave:6> ascii = load ("test-ascii.dat");
octave:7> binary = load ("test-binary.dat");
octave:8> hdf5 = load ("test-hdf5.dat");
octave:9> f () ()
ans =  1
octave:10> ascii.f () ()
error: 'a' undefined near line 1 column 9
error: called from
     at line -1 column -1
octave:10> binary.f () ()
error: 'a' undefined near line 1 column 9
error: called from
     at line -1 column -1
octave:10> hdf5.f () ()
error: 'a' undefined near line 1 column 9
error: called from
     at line -1 column -1
octave:10>


More realistic example for triggering this bug:


octave:1> a = 2;
octave:2> b = 10;
octave:3> c = 20;
octave:4> f1 = @ (f, x) f (x) + a
f1 =

@(f, x) f (x) + a

octave:5> f2 = @ (y) f1 (@ (z) z^2 + b * y, y) + c
f2 =

@(y) f1 (@(z) z ^ 2 + b * y, y) + c

octave:6> save ("test-ascii.dat", "f2")
octave:7> save ("-binary", "test-binary.dat", "f2")
octave:8> save ("-hdf5", "test-hdf5.dat", "f2")
octave:9> ascii = load ("test-ascii.dat");
octave:10> binary = load ("test-binary.dat");
octave:11> hdf5 = load ("test-hdf5.dat");
octave:12> f2 (5)
ans =  97
octave:13> ascii.f2 (5)
error: 'b' undefined near line 1 column 23
error: called from
     at line -1 column -1
     at line -1 column -1
     at line -1 column -1
octave:13> binary.f2 (5)
error: 'b' undefined near line 1 column 23
error: called from
     at line -1 column -1
     at line -1 column -1
     at line -1 column -1
octave:13> hdf5.f2 (5)
error: 'b' undefined near line 1 column 23
error: called from
     at line -1 column -1
     at line -1 column -1
     at line -1 column -1
octave:13>


The fix (single changeset to be attached as soon as I know the bug number)
firstly provides a new class, derived from class tree_walker, to collect the
variables of all scopes of potentially nested anonymous function handles,
secondly lets the

octave_fcn_handle::save_[ascii/binary/hdf5]()

methods use this class for saving anonymous functions, and thirdly provides a
test (with the second example above).




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?45969>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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