difficulty transporting some code from hoc to python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
vellamike

difficulty transporting some code from hoc to python

Post by vellamike »

Hi,

I've been trying to solve this problem for a while now, I should point out that I don't have very much experience with hoc.

I've found some hoc code that contains the statement:

Code: Select all


n_axon_seg = 5

create soma,iseg,hill,myelin[2],node[2]

proc create_axon() {

  create iseg,hill,myelin[n_axon_seg],node[n_axon_seg]

 etc...
to me this seems to suggest that myelin and node are created as global arrays with two elements and then when the procedure create_axon is called the globals are changed or destroyed, however I can't seem to get the behaviour I'd expect from these conditions (e.g if I delete the myelin[2] statement it causes an error in the create_axon procedure) and I've not been able to find any hoc literature to help with this, can anyone explain why this makes sense so I can continue to transport this code to Python?
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: difficulty transporting some code from hoc to python

Post by ted »

I know I've seen the answer to your question somewhere, but can't find it at the moment. So here's more than you wanted to know about hoc's rules for user-created variable names.

0. A name is a string that starts with an alpha character and contains < 100 alphanumeric characters or the underscore _

1. User-created names must not conflict with keywords or built-in functions.

2. Each user-created variable name is one of the following types:
double precision scalar, array of scalars (also called a "double"), strdef, objref, section

3. If a user-created variable name is to have a nonscalar type, its first appearance in the program must be in a declaration statement that occurs outside of any func or proc. Examples:
double xyz[3]
strdef bar
objref foo
create baz

4. Once a name has been assigned a type, it can only be redeclared as the same type.

Regarding your particular question: execute the following example and note the results:

Code: Select all

NUM = 3

create foo
print "First result:"
forall print secname()
print " "

proc test() { i
  create foo[NUM]
}

test()
print "Second result:"
forall print secname()
vellamike

Re: difficulty transporting some code from hoc to python

Post by vellamike »

That's starting to make more sense, but I can get the code to run by creating variables inside a func or proc:

Code: Select all

NUM = 3

proc test() { 
  create foo[NUM]
}

test()
print "Result:"
forall print secname()
returns:
Result:
foo[0]
foo[1]
foo[2]
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: difficulty transporting some code from hoc to python

Post by ted »

Interesting. I don't recall that working the last time I tried (years back).
Post Reply