Page 1 of 1

Different Levels of Access?

Posted: Tue Dec 01, 2009 7:18 am
by arb
Hi,
I am using the latest NEURON 7.1 on my MacBook Pro..

I was just wondering what the difference between the two pieces of code are:

Code: Select all

create soma

soma {
	objref test
	test = new IClamp(0.5)
}
producing an error:
/Applications/NEURON/nrn/i686/bin/nrniv: syntax error
in test.hoc near line 5
test = new IClamp(0.5)

while the following

Code: Select all

create soma

soma objref test
soma test = new IClamp(0.5)
works fine. Should this be like that or is this a bug?
I do not remember having this problem in earlier versions of NEURON..

Cheers. Armin

Re: Different Levels of Access?

Posted: Tue Dec 01, 2009 10:35 am
by ted
Statements inside paired curly brackets { . . . } are parsed (tokenized) and tested for syntax errors as they are encountered, but execution is deferred until the closing bracket } is encountered. Consequently

Code: Select all

{ // start of code block enclosed in paired curly brackets
  objref foo // hoc won't "know" foo is an objref until after the end of the code block
  foo = new SomeClass() // so this statement will generate a syntax error msg,
    // and force the hoc parser to quit before it reaches the closing curly bracket
}
hoc treats all variable names as floating point scalars by default. The first declaration of a name as a strdef or objref must be made _outside_ of any proc or func or code block delimited by paired curly brackets. hoc has always worked like this, from the time that objects were added to it.