prog1 2001-06-01 experimental 2001-02-16 0 0 arith1 quant1 relation1 A CD for basic programming concepts. We define "all" the machinery necessary for defining programing structures like function, variable declaration, if, while, for, etc. assignment This symbol is used to assign values to variables. It is a binary symbol to be used as assign(omvar, omobject). The assignment a := 125 is encoded as 125 block This symbol is meant to represent an arbitray block of code. It should be used as block(omobj1, ombj2, ...,ombjN); The following block of code { a := 153; a := a+1; } is translated as 153 local_var This symbol is meant to explicitly declare local variables inside a function definition. It should be used as local_var (var1, var2, .., varN). The scope of these variables is the block of code containing them. (Are we going to allow assigments in local variable declaration?). The following code { local a,b,c; b:=1; a := b; } is transalted as 1 global_var This symbol is meant to explicitly declare global variables as know to particular block of code. It shoul be applied as global_var(var1, var2,...,varN). The scope of these variables is the hole file containing them? The follwing example is B:= 5; { local a; global B; a:=B; } translated as 5 return Returns a value from function (and finished the it). Used as: application(return,omobject). See example (below) in the definition of the symbol function_definition. for The symbol for is used to mimic the C,C++ for construction. Use: for(Block1,Block2,Block4,Block4). -Block1 is the inicialization block. -Block2 is the termination condition (the boolean part). -Block3 is the incremental block. -Block4 is the body of the for loop. See example (below) in the definition of the symbol function_definition. while The symbol while is used to mimic the C,C++ while construction. Use: application(while,Block1,Block2). -Block1 is the termination condition (the boolean part). -Block2 is the body of the while loop. (Maybe is it beter to use a symbol "conditional_block" or "conditional_expresion" to replace block1 and in that way distinguish it from the normal block of commands?) The code while(i <= 10) { N := N + i*i; } is written as 10 if The symbol if is used to mimic the if...the...else construction. Should be used as application(if,Block1,Block2,Block3). -Block1 is the the boolean part. (Maybe is it beter to use a symbol "conditional_block" or "conditional_expresion" to replace block1 and in that way distinguish it from the normal block of commands?) -Block2 is the part corresponding to the then ("executed if the boolean block block1 is true). -Block3 is the part corresponding to the else ("executed if the boolean block block1 is false). the (seudo-)code { if (A) then B else C } is translated to (CONDITION A) (STATEMENT B) (STATEMENT C). arguments The aguments passed to a function or procedure. To be used as application(arguments,Obj1,Obj2,...,ObjN). See example following the definition of the symbol function_definition. function_block The block of code defining the body of the function. Should be as application(function_block,local_var,block). See example following the definition of the symbol function_definition. function_definition The symbol function_definition is used to provide a definition for a function. Should be as application(function_definition, Name, arguments, function_block(local_var,block)). with the following meaning 1- Name is an OMV representing the name of the function (it should be allway present). 2- arguments stands for the openmath object application(arguments, obj1, obj2,...). Arguments should be present even if it is an empty argument list. 3- function_block(local_var,block): a- local_var: local variables declaration, b- block: elements defining de body of the function. Body may contain "returns", "ifs", "whiles", "fors", function_calls, etc. It begins with The body should be present even if its empty. Notes: 1-We suppose that all the information a function has from the "global" scope comes via the arguments. No global_variable variable declariation is allowed. The function (in Maple notation). //Computes 1+2^10+....+N^10; > MyFunction:=proc(N) > local i, Result; > Result := 1; > for i from 2 to N do > Result := Result + i^10; > od; > Result; > end: is translated as 1 2 1 10 1 //End of for //begin of return //end of return //End of block function_call Symbol function_call is used to "call" already defined functions. Should be as application(function_call,Name, arguments(arg1, arg2,..., argN)). Here 1-Name is an OMV representing the name of the function. (Maybe we can allow also an OMS in order to refer to "function symbols" defined in some other content dictionary). 2- arguments(arg1, arg2,..., argN). List of OpenMath objects. The function call "MyFunction(100)" is translated as 100 procedure_definition The symbol procedure_definition is used to provide a definition for a function. Should be used as application(procedure_definition, Name, arguments, function_block(local_var,global_var, block)). The main diference with fucntion definition are 1-procedures may have global variables 2-they do not return values using "return" (i.e. return is not even allowed a procedure). procedure_call Symbol procedure_call is used to "call" already defined procedures. Should used be as application(procedure_call, Name, arguments(arg1, arg2,..., argN)), where 1-Name is an OMV representing the name of the procedure. (Here to allow the use of OMS also, for instance we may have a a Cd with all the "black box" procedures an functions known by a particular back engine. 2- arguments(arg1, arg2,..., argN). List of OpenMath objects.