confused about execute()

Anything that doesn't fit elsewhere.
Post Reply
bhalterm
Posts: 52
Joined: Wed Mar 08, 2006 10:43 am
Location: University of Pennsylvania

confused about execute()

Post by bhalterm »

When running the code (at the bottom), I get the following error:

Code: Select all

the_number_ten not a public member of Ten
/Users/benlhalt/NEURON/nrn/i686/bin/nrniv: Ten the_number_ten
 in Ten.hoc near line 17
 {print this.the_number_ten}
                            ^
        Ten[0].execute("print this.the_number_ten", Ten[0])
      Ten[0].print_ten()
/Users/benlhalt/NEURON/nrn/i686/bin/nrniv: execute error: print this.the_number_ten
 in Ten.hoc near line 17
 ^
I was hoping that using "this" as the second argument to execute() would make it unnecessary to declare the variable as public. Am I missing something?

Code: Select all

begintemplate Ten
public print_ten
objref this

proc init() {
  the_number_ten = 10
}

proc print_ten() {
  execute("print this.the_number_ten", this)
}

endtemplate Ten

objref my_ten
my_ten = new Ten()
my_ten.print_ten()
bhalterm
Posts: 52
Joined: Wed Mar 08, 2006 10:43 am
Location: University of Pennsylvania

Post by bhalterm »

Also, execute() always returns 0. When I begin the command with a tilda, it outputs the value of the statement before it outputs 0. Is it returning two values? Is there any way to get it to just return the value of the statement? It would be really cute if the 2nd and 3rd expressions with execute() behaved similarly:

Code: Select all

oc>one = 1
first instance of one
oc>two = 2
first instance of two
oc>execute("~one")
        1 
        0 
oc>two = execute("~one + one")
        2 
oc>two
        0 
oc>execute("~two = one + one")
        0 
oc>two
        2 
oc>
bhalterm
Posts: 52
Joined: Wed Mar 08, 2006 10:43 am
Location: University of Pennsylvania

Post by bhalterm »

Ah hah! It looks like even within the object, the javaish idiom this.var is a no no because the dot notation tricks the interpreter into thinking var is being accessed from outside the object. No more extraneous syntax for me.
Post Reply