Program Editor

From emergent
Jump to: navigation, search

<= Back to Program

This section provides detailed information on programming using the program editor, specifically the new ProgCode mechanism for entering C++ expressions which are then auto-converted to the appropriate program element ProgEl.

ProgCode is a type of ProgEl which converts text code into standard emergent program elements. This provides an alternative to drag-n-drop selecting the ProgEl from the Tools menu. To use the ProgCode feature, you must first add a ProgCode element to your program, and then enter a valid expression into the code text box for the ProgCode ProgEl.

Adding a ProgCode ProgEl

Within an existing program, a new ProgCode program element can be easily added:

  1. [RECOMMENDED] Panel View - Edit Program : In the edit panel for the program, navigate to the line of code preceeding the line where you want the new ProgCode element to be inserted, and press Enter key.
  2. Panel View - Edit Program : In the edit panel for the program, right-click (ctrl+mouse on a Mac) on prog code (or init code or functions), and select New from the context menu. In the New_gui pop-up window, specify the typ as ProgCode and press "Ok". The new ProgCode element will be inserted at the end of the current code.
  3. Panel View - Edit Program : In the edit panel for the program, left-click on prog code (or init code or functions). This will bring up an program element editor view at the top of the program edit panel. Press the New button. In the New_gui pop-up window, specify the typ as ProgCode and press "Ok". The new ProgCode element will be inserted at the end of the current code.
  4. Tree View: Under programs => your_program_name right-click (ctrl+mouse on a Mac) on prog code (or init code or functions), and select New from the context menu. In the New_gui pop-up window, specify the typ as ProgCode and press "Ok". The new ProgCode element will be inserted at the end of the current code.
  5. Tree View: Under programs => your_program_name left-click on prog code (or init code or functions). This will bring up an editor Panel View with a list of the current ProgEl elements in the program. Press the New button. In the New_gui pop-up window, specify the typ as ProgCode. The new ProgCode element will be inserted at the end of the current code.

See Keyboard shortcuts for important general shortcuts in navigating around the system without using a mouse -- these are key for high efficiency programming. In particular, Tab to move up to the program element editor at top of listing, and Ctrl+Return to Apply and move back down to the program listing. Use Ctrl+ left or right arrow to move back and forth through a history of prior locations in the program listing -- very useful.

As of 7.0.0, you can just type directly into the editor (just start typing, or hit Ctrl+a (goto start), Ctrl+e (goto end), or F2 to engage editing) and add to or modify the program completely textually -- everything will automatically be converted into the appropriate ProgEl program elements. This builds upon the ProgCode system -- new code is entered into a ProgCode, which then parses and converts it into the appropriate program element. There is an expert Preferences setting that allows you to hide the mini-program edit dialog at top of editor area by default, if you prefer to only operate in editor mode.

ProgCode expressions

For all of these expressions, just enter the core expression itself, not any subsequent statements or curly brackets etc -- e.g., for a for loop or an if statement, just enter the "for()" or "if()" expression itself -- you will then get the opportunity to enter the subsequent statements under the program element when it is created.

If you enter a semicolon (;) at the end of the expression, then it will automatically create a CssExpr, bypassing the automatic conversion process entirely.

You can also enter new variable names -- you will be prompted to create unknown variables (or fix expression if it was a mistake) -- this is true in any expression at all.

Ctrl ProgEl List

Toolbox - Ctrl ProgEl Example Notes
for ForLoop for (i=0; i<10; i++) expects to see two ; within the () -- can also just enter "for"
do DoLoop do (i>=0) expression in parenthesis is for the subsequent while expression -- can also just enter "do"
while WhileLoop while (i>=0) can also just enter "while"
if.else IfElse if (a>b).. can also just enter "if"
if.cont IfContinue if (n==5) continue placed within a program loop, can also just enter "continue"
if.break IfBreak if (n==6) break placed within program loop
if.return IfReturn if (n==7) return placed within a program loop
if gui prmt IfGuiPrompt if gui prmt currently need to select from IfElse or IfGuiPrompt ProgEl elements
switch Switch switch (x) can also just enter "switch", and a default ProgVar_ switch variable will be created
block CodeBlock {} simply enter the set of curly-braces {} to form a block of code. Multiple ProgEl calls can be made from within the block.
script UserScript script effectively a library call where existing scripts can be specified

Var/Fun ProgEl List

Toolbox - Var/Fun ProgEl Example Notes
var ProgVar CANNOT currently use a ProgCode statement to imply a ProgVar ProgEl ... but if you use ProgCode to define a ProgEl which contains an unknown variable you can define that variable as a global type when the ProgCode expression is expanded
loc vars ProgVars int x; this will generate an "int x;" variable in a local code ProgVars group
var= AssignExpr y= if variable name unknown, then you are given the option to create a new global or local variable
var+= VarIncr var+=1 current default is to decrement, so the expression will contain a minus: -1
memb= MemberAssign network->avg_sse=mysse the format is: object->member from object=value or variable
meth() MethodCall network->Compute_Act() the format is: result_var=object->method
if the function returns void then the result_var does not need to be specified
memb.mth() MemberMethodCall network->specs->List()

the general format is: result_var=object->member->method
if the function returns void then the result_var does not need to be specified

fun def Function fun def currently creates a un-named empty function in the prog_code or init_code -- must move this user-defined function into functions section of program
fun() FunctionCall myfunctname() the function name must exist
return() ReturnExpr return x; return from a function with a given expression, use return; to return from a void function)
prog() ProgramCall LeabraTrain() the program name must exist
prog var() ProgramCallVar CANNOT currently use a ProgCode statement to imply a ProgramCallVar ProgEl
Call Fm prog_group prog_name_var ()
oth prg var OtherProgramVar CANNOT currently use a ProgCode statement to imply a OtherProgramVar ProgEl
Fm:To or To:Fm

Print/Args ProgEl List

Toolbox - Print/Args ProgEl Example Notes
print PrintExpr CANNOT currently use a ProgCode statement to imply a PrintExpr ProgEl.
The print statement will imply a PrintVar which does contain an expression field.
print var PrintVar print x; use print "message"; to imply a PrintVar ProgEl containing a message only (no variables printed)
comment Comment /* my comment */
// one-liner comment
any comment
stop/step StopStepPoint stop/step
var=arg ProgVarFmArg var=arg complete fields after program element created
memb=arg MemberFmArg memb=arg complete fields after program element created
data=args DataColsFmArgs data=args complete fields after program element created
sele=args SelectEditsFmArgs sele=args complete fields after program element created
reg args RegisterArgs reg args

Misc Fun ProgEl List

Toolbox - Misc Fun ProgEl Example Notes
static() StaticMethodCall x=taBase::funct() the taBase:: object type field is critical to select a Static Method function, can select specific funct() after program element created
math() MathCall x=taMath::funct() the taMath:: or taMath_double:: or taMath_float:: object type field is critical to select a Math Function, can select specific funct() after program element created
random() RandomCall x=Random::funct() the Random:: object type field is critical to select a Random number generation function, can select specific funct() after program element created
misc() MiscCall x=taMisc::funct() the taMisc:: object type field is critical to select a taMisc function, can select specific funct() after program element created
data proc() [DataProcCall]] x=taDataProc::funct() the taDataProc:: object type field is critical to select a taDataProc (data processing/database) function, can select specific funct() after program element created
data anal() DataAnalCall x=taDataAnal::funct() the taDataAnal:: object type field is critical to select a taDataAnal (data analysis) function, can select specific funct() after program element created
data gen() DataGenCall x=taDataGen::funct() the taDataGen:: object type field is critical to select a taDataGen (data generation) function, can select specific funct() after program element created
img proc() ImageProcCall x=taImageProc::funct() the taImageProc:: object type field is critical to select a taImageProc function, can select specific funct() after program element created

Data ProgEl List

Toolbox - Data ProgEl Example Notes
data loop DataLoop data loop implies either a DataLoop ProgEl (DataTable Loop) or NetDataLoop ProgEl (Network Data Loop), must specify loop type -- gui pop-ups left-most "data loop" is the DataLoop type --, and also specify index variable after program element created
reset rows ResetDataRows reset rows specify target datatable after program element created
new row AddNewDataRow new row specify target datatable after program element created
row done DoneWritingDataRow row done specify target datatable after program element created
data=vars DataVarProg data=vars specify target datatable, Fm:To or To:Fm, row, and column after program element created
data mtx=vars DataVarProgMatrix data mtx=vars specify target datatable, Fm:To or To:Fm, row, and column after program element created

DataProc ProgEl List

Toolbox - DataProc ProgEl Example Notes
sort DataSortProg sort specify source and destination datatables, and sort specification after program element created
group DataGroupProg group specify source and destination datatables, and sort specification after program element created
sel rows DataSelectRowsProg sel rows specify source and destination datatables, selection specification, combination rule, and specify columns after program element created
sel cols DataSelectColsProg sel cols specify source and destination datatables, and specify columns after program element created
join DataJoinProg join specify source datatables, destination datatable, join specification, and column name after program element created
calc loop DataCalcLoop calc loop specify source and destination datatables, columns, and loop code after program element created
+dest row DataCalcAddDestRow +dest row specify destination datatable after program element created
=dest row DataCalcSetDestRow =dest row specify destination datatable after program element created
=src row DataCalcSetSrcRow =src row specify source datatable after program element created
cpy cols DataCalcCopyCommonCols cpy cols specify source and destination datatables, and "only named columns" flag after program element created

Network ProgEl List

Toolbox - Network ProgEl Example Notes
init nm units InitNamedUnits init nm units specify input_data datatable and other variables after program element created
set units lit SetUnitsLit set units lit specify input_data datatable and other variables after program element created
set units var SetUnitsVar set units var specify input_data datatable and other variables after program element created
net ctr init NetCounterInit net ctr init specify network, local counter variable, and network counter names after program element created
net ctr inc NetCounterIncr net ctr inc specify network, local counter variable, and network counter names after program element created
net updt view NetUpdateView net updt view specify network and NetUpdateView control variable after program element created
wt init prmt WtInitPrompt wt init prmt requires that the program contain a variable named: network
data loop NetDataLoop data loop implies either a DataLoop ProgEl (DataTable Loop) or NetDataLoop ProgEl (Network Data Loop), must specify -- gui pop-ups right-most "data loop" is the NetDataLoop type --, also requires that the program contain variables named: network and trial (counter)
gp data lp NetGroupedDataLoop gp data lp This is obsolete: use NetDataLoop with group flag instead

NOTE: See Program Text Color Coding for tips on the program element color coding.