[Top][All Lists]

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

Re: curr_sym_tab?

From: Stef Pillaert (KAHO)
Subject: Re: curr_sym_tab?
Date: Wed, 10 May 2000 16:12:34 +0200

<On 20-Apr-2000, Stef Pillaert <address@hidden> wrote:
<| in my .oct-functions, I had a way (in octave-2.0.?) to set local or
<| octave_values, so that I could use eval on those values. JWE was so kind
<| provide a simple way to do this.
<| My problem is that this doesn't seem to work in octave-2.1.30 anymore.
<| Anyone has experience on this? "curr_sym_tab" doesn't seem to exist
<| anymore...
<It is declared in variables.h.
<2.1.x already includes get_global_value and set_global_value
<I don't understand why you need functions that access the local symbol
<table, or why your local_oct function is needed.  Can't you accomplish
<the same thing using eval?

(Sorry for the late reply, been in computer-crash-land for a while...)
I used to access the local symbol table, for the following:

In octave, I have a function tst,  X stays local in the
function tst, and doesn't have an effect on X outside the function (as it

octave:1> function tst(A,Str)
> X=A/2;
> tst=eval(Str);
> endfunction
octave:2> tst(5,"X*6")
ans = 15
octave:3> X=12;
octave:4> tst(X,"X*6")
ans = 36
octave:5> tst(X+2,"X*6")
ans = 42
octave:6> X
X = 12

This all seems normal.
Now, I try to do the same in an .oct function:

# include <octave/oct.h>

extern octave_value_list Feval  (const octave_value_list&, int);

DEFUN_DLD (test,args,nargout,
" ")

  const Matrix A = args(0).matrix_value();
  const string Str = args(1).string_value();
  const Matrix X = A/2;
  octave_value_list tmp;
  const octave_value_list retval = Feval(tmp,1);
  return retval;

This is what I get:

octave:1> test(5,"X*6")
error:  undefined near line 0 column 1
error: evaluating binary operator *' near line 0, column 2
octave:1> X=12;
octave:2> test(X,"X*6")
ans = 72
ans = 72
octave:3> test(X+2,"X*6")
ans = 72
ans = 72
octave:4> X
X = 12

It seems logical that the first call doesn't work (X isn't known as a local
symbol), but is it logical that X seems to be known, when defined outside
the function (as if it was global?).

I changed the .oct function (adding the set_local_value function):

# include <octave/oct.h>
#include <octave/symtab.h>
#include <octave/variables.h>

extern octave_value_list Feval  (const octave_value_list&, int);

 void  set_local_value (const string& nm, const octave_value& val)
    symbol_record *const sr = curr_sym_tab->lookup (nm, true);

    if (sr)
      sr->define (val);
      panic_impossible ();

DEFUN_DLD (test,args,nargout,
" ")

  Matrix A = args(0).matrix_value();
  string Str = args(1).string_value();
  Matrix X = A/2;
  set_local_value ("X",X);  
  octave_value_list tmp;
  octave_value_list retval = Feval(tmp,1);
  return retval;

 The results I get now:

octave:1> test(5,"X*6")
ans = 15
ans = 15
octave:2> X=12;
octave:3> test(X,"X*6")
ans = 36
ans = 36
octave:4> test(X+2,"X*6")
ans = 24
ans = 24
octave:5> X
X = 4

I always believed that the function set_local_value (I think I found it in
the archives somewhere long ago...) only declared the symbol
to be local, but the above shows that it seems to be globally defined. Is
this me misusing the function set_local_value, or is there something wrong?

Or is there another way to translate my tst function into an .oct-file (I
remember that there is a function "feval" instead of Ffeval that can be used in 
.oct files,
but is there also a "eval" that can be used in an .oct file instead of
Feval? And will the above problems be avoided?  I looked in parse.y, but
didn't find my way in it, sorry...

Thanks for any help or suggestions...

(I append the contents of the bug-report, in case it matters...)

Configuration (please do not edit this section):

uname output:     Linux localhost.localdomain 2.2.14-5.0 #1 Tue Mar 7
20:53:41 EST 2000 i586 unknown
configure opts:   %config_opts%

Fortran compiler: g77
FFLAGS:           -O
FLIBS:            -lg2c -lm
-L/usr/i386-redhat-linux/lib -lm
INCFLAGS:         -I. -I. -I./liboctave -I./src -I./libcruft/misc  -I./glob
C compiler:       gcc, version 2.91.66 19990314/Linux (egcs-1.1.2 release)
CFLAGS:           -g -O2 -Wall
CPICFLAG:         -fPIC
C++ compiler:     c++, version 2.91.66 19990314/Linux (egcs-1.1.2 release)
C++ compiler:     c++, version 2.91.66 19990314/Linux (egcs-1.1.2 release)
LDFLAGS:          -g
LIBFLAGS:         -L.
RLD_FLAG:         -Xlinker -rpath -Xlinker /usr/local/lib/octave-2.1.30
TERMLIBS:         -lncurses
LIBGLOB:          ./glob/libglob.a

  -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 -DNPOS=std::string::npos

in parse.y, but this is a bit

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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