# Idioms

### Iterating over all segments

    forall for (x) print secname(), x
    forall for (x) if (x > 0 && x < 1) print secname(), x //leave out 0 area nodes

### Data Structures

    begintemplate Temp
    	public str, obj, x
    	strdef str
    	objref obj
    	x = 0
    endtemplate Temp

    objref temp
    temp = new Temp()
    temp.x = 2
    temp.str = "hello"
    temp.obj = new SectionList()

    print temp, temp.x, temp.str, temp.obj

### Adding a Graph so it works with the Standard Run Library

    begintemplate P
            public flush, plot, begin, view_count
            objref this
            proc flush() { print this, "flush", t }
            proc plot() { print this, "plot", t }
            proc begin() { print this, "begin", t }
    	func view_count() { print this, "view_count"   return 1}
    endtemplate P

    flush_list.append(new P()) // call flush every step
    graphList[0].append(new P()) // call plot and flush every step

### Arrays of strings

    begintemplate String
    	public s
    	strdef s
    	proc init() {
    		if (numarg() == 1) {
    			s = $s1
    		}
    	}
    endtemplate String

    objref sobj[5]
    for i=0, 4 sobj[i] = new String()
    for i=0, 4 sprint(sobj[i].s, "Number %d", i)
    for i=0, 4 print sobj[i].s

### Neat stuff to do after picking a Graph line into the vector clipboard

You can then apply the Vector methods, as in these examples.

`hoc_obj_.c.printf`
  prints a copy of the vector

`hoc_obj_.c.deriv(1,1).printf`
  prints the euler derivative

`hoc_obj_.c.deriv(1,1).indvwhere(">", 1e-5).printf`
  prints the indices

`hoc_obj_.ind(hoc_obj_.c.deriv(1,1).indvwhere(">", 1e-5).add(1)).printf`
  prints the peak values

`hoc_obj_[1].ind(hoc_obj_.c.deriv(1,1).indvwhere(">", 1e-5).add(1)).deriv(1,1).printf`
  prints the time intervals between synaptic discontinuities

The following aren't hoc idioms, but they can be helpful.

## NEURON's interpreter window

### EMACS

These EMACS commands work for command line editing from the console (MSWin: NEURON's interpreter window).
^P previous line (up arrow may also work; this crude history function can be applied repeatedly to scroll through prior commands)
^A front of line
^E end of line
^B backward character
^F forward character
Long command lines can be constructed by revision + accretion (recall a prior line, make changes and add new stuff to it).

NEURON hands-on course
Copyright © 1998-2001 by N.T. Carnevale and M.L. Hines, all rights reserved.