help-octave
[Top][All Lists]
Advanced

[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
global
<| octave_values, so that I could use eval on those values. JWE was so kind
<to
<| 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
<functions.
<
<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?
<
<jwe

(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
should):

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;
  tmp(0)=octave_value(Str);
  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);
    else
      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;
  tmp(0)=octave_value(Str);
  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...

Stef.
(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
F2C:
F2CFLAGS:
FLIBS:            -lg2c -lm
-L/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66
-L/usr/i386-redhat-linux/lib -lm
CPPFLAGS:
INCFLAGS:         -I. -I. -I./liboctave -I./src -I./libcruft/misc  -I./glob
-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)
CXXFLAGS:         %OCTAVE_CONF_BUG_CXXFLAGS%
CXXPICFLAG:       -fPIC
LDFLAGS:          -g
LIBFLAGS:         -L.
RLD_FLAG:         -Xlinker -rpath -Xlinker /usr/local/lib/octave-2.1.30
TERMLIBS:         -lncurses
LIBS:
LEXLIB:
LIBPLPLOT:
LIBDLFCN:
LIBGLOB:          ./glob/libglob.a
DEFS:

  -DOCTAVE_SOURCE=1 -DSEPCHAR=':' -DSEPCHAR_STR=":" -DUSE_READLINE=1
  -D__NO_MATH_INLINES=1 -DCXX_NEW_FRIEND_TEMPLATE_DECL=1 -DHAVE_LIBM=1
  -DF77_APPEND_UNDERSCORE=1 -DHAVE_LIBATLAS=1 -DHAVE_LIBCBLAS=1
  -DOCTAVE_LITE=1 -DSIZEOF_SHORT=2 -DSIZEOF_INT=4 -DSIZEOF_LONG=4
  -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 -DNPOS=std::string::npos
  -DSTDC_HEADERS=1 -DHAVE_DIRENT_H=1 -DTIME_WITH_SYS_TIME=1
  -DHAVE_SYS_WAIT_H=1 -DHAVE_ASSERT_H=1 -DHAVE_CURSES_H=1 -DHAVE_DLFCN_H=1
  -DHAVE_FCNTL_H=1 -DHAVE_FLOAT_H=1 -DHAVE_FNMATCH_H=1 -DHAVE_GLOB_H=1
  -DHAVE_GRP_H=1 -DHAVE_LIMITS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_NCURSES_H=1
  -DHAVE_POLL_H=1 -DHAVE_PWD_H=1 -DHAVE_SGTTY_H=1 -DHAVE_STDLIB_H=1
  -DHAVE_STRING_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_PARAM_H=1
  -DHAVE_SYS_POLL_H=1 -DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1
  -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TIME_H=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INK=1
  -DHAVE_USLEEP=1 -DHAVE_VFPRINTF=1 -DHAVE_VSPRINTF=1 -DHAVE_VSNPRINTF=1
  -DHAVE_WAITPID=1 -DHAVE_LIBDL=1 -DHAVE_DLOPEN=1 -DHAVE_DLSYM=1
  -DHAVE_DLERROR=1 -DHAVE_DLCLOSE=1 -DWITH_DL=1 -DWITH_DYNAMIC_LINKING=1
  -DHAVE_TIMEVAL=1 -DHAVE_FINITE=1 -DHAVE_ISNAN=1 -DHAVE_ISINF=1
  -DHAVE_ACOSH=1 -DHAVE_ASINH=1 -DHAVE_ATANH=1 -DHAVE_ERF=1 -DHAVE_ERFC=1
  -DHAVE_ST_BLKSIZE=1 -DHAVE_ST_BLOCKS=1 -DHAVE_ST_RDEV=1 -DHAVE_TM_ZONE=1
  -DHAVE_GR_PASSWD=1 -DEXCEPTION_IN_MATH=1 -DRETSIGTYPE=void
  -DSYS_SIGLIST_DECLARED=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_POSIX_SIGNALS=1
  -DHAVE_GETRUSAGE=1 -DHAVE_TIMES=1 -DGNUPLOT_HAS_MULTIPLOT=1
  -DGNUPLOT_HAS_FRAMES=1

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:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

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