Different Levels of Access?

Anything that doesn't fit elsewhere.
Post Reply
arb
Posts: 19
Joined: Mon Jul 02, 2007 6:18 am
Location: Humboldt-University, Berlin

Different Levels of Access?

Post 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
ted
Site Admin
Posts: 6389
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Different Levels of Access?

Post 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.
Post Reply