lambda_f undefined function - when used inside template

Anything that doesn't fit elsewhere.
Post Reply
shailesh
Posts: 104
Joined: Thu Mar 10, 2011 12:11 am

lambda_f undefined function - when used inside template

Post by shailesh »

Hi,

I am facing an issue when using lambda_f for specifying nseg. The error message is: "lambda_f undefined function"
I had read the only other post dealing with such an error on the forum (http://www.neuron.yale.edu/phpbb/viewto ... =15&t=2017) and double-checked to ensure that I had included 'load_file("nrngui.hoc")' at the start of my code. I even tried toying around placing the same statement just before creating an object from the template, but to no use.

A stripped down & simplified version of my hoc code (that reproduces this error) is as follows:

Code: Select all

load_file("nrngui.hoc")

begintemplate test_template
	
	public a, b
	create a, b[1]
	
	objref list_b

	proc init() {
		NUM = $1	
	
		create a, b[NUM]

		list_b = new SectionList()
		forsec "b" list_b.append

		a {
			L =  25  // um
			diam = 25  // um	

			cm = 1  // uF/cm2

			insert hh
			ena = 50  // mV
			ek = -80 // mV
		}

		forsec list_b {
			L = 1500 // um
			diam = 1.0  // um

			cm = 0.005  // uF/cm2
		}

		forall { 
			nseg = int((L/(0.1*lambda_f(100))+.9)/2)*2 + 1  // d_lambda rule
			//nseg = 11  //This works!
			print secname()

			Ra = 100 // ohm.cm

			insert pas
			e_pas = -70  // mv - Resting Membrane Potential
			g_pas = 1/15000  // S/cm2 = 1/Rm = 1 / Membrane Resistance
		}
	}
endtemplate test_template

objref testobj
testobj = new test_template(5)
access testobj.a
As another check, I opened "nrngui" from the start menu (I am working on Windows 7 with Neuron 7.3) to ensure that the hoc library had been loaded, and then loaded the above hoc code. Again the same error.

Reproducing the entire error message:
nrniv: lambda_f undefined function
in /cygdrive/.....
testobj = new test_template(5)
^
test_template[0].lambda_f(100 )
test_template[0].init(5 )
It seems that 'lambda_f' is being considered as function defined in the template rather than belonging to the hoc library. Specifying my nseg via d_lambda seems to be fine if done outside of the template - after creating my object from the template.

Despite this workaround, I was wondering whether I had committed some mistake in using the template method. If not, is there any way I can get it to work within the template?

Thanks in advance,
Shailesh Appukuttan
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: lambda_f undefined function - when used inside template

Post by ted »

A common feature of object oriented programming languages is that, by default, no X that exists outside of an object is visible from inside the object unless the object's class definition allows it. For hoc, this is done by declaring X to be "external." If you want your objects to be able to manage their own discretization, you'll have to include this statement
external lambda_f
in your template right after the begintemplate or public line

This would be a good time to read everything in
http://www.neuron.yale.edu/neuron/stati ... l/oop.html
and
http://www.neuron.yale.edu/neuron/stati ... n/obj.html
shailesh
Posts: 104
Joined: Thu Mar 10, 2011 12:11 am

Re: lambda_f undefined function - when used inside template

Post by shailesh »

Thanks Ted for pointing that out.
It is working fine now with the 'external' command.
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: lambda_f undefined function - when used inside template

Post by ted »

Good. Controlling the "visibility" of things (variables, functions etc.) from the inside or outside of object instances can be quite useful, but visibility is also very easy to forget about, and that's when quite puzzling things can happen.
Post Reply