G4C TextFile env:.help Note that the line above defines the lines following it as a file. This file will be created 'on the fly' when loading the gui. The file ends at the triple doublecross below. The Gui4Cli language is basic-like but comes with (many) powerfull features, notably 'translation' up (or down ?) to 100 levels deep. This feature allows you to create arrays and matrices. Here we have exploited it to create mathematical functions. The standard mathematical functions that come with Gui4Cli are a limited but very usable set. (Apart from the operators + - / * and ^ you find those functions 'redefined' in the SetN1Func subroutine.) Using the method illustrated you can define new functions that appear like variables and that you can use in the standard Gui4Cli mathematical evaluation method which looks like this: result = $( mathematical expression ) e.g: x = .3 ; radians) cos2x = $( cos($x) ^ 2) - ( sin($x) ^ 2) ) say $cos2x ; print the result Note Gui4Cli is very flexible in the naming of variables. coss<2x> , cos{x+y} are valid variable names yo The functions produces are of the form Newfunc.x Otherfunc.Y.Z They are created 1. by putting their definition in one of the following subroutines - SetFunc : if you are happy with using 'x' as the only possible variable - SetN1Func MyVarNme : For functions from only one variable , but usable with any variablename - SetN2Func MyVarNmex MyVarNamey: For functions of 2 variables , usable with any variable names - ... 2. by calling the proper subroutine()s before using the functions describe therein You could do that in the 'Default subroutine ' or in the command sequence attached to a gadget or in a subroutine. The variables used can be declared 'local' (In this gui they are not) if wished. Then the logical place to have the function(+variablename(s)) 'declared is in this sequence too (as is done in this gui) Remark Remember when using more than one name (say 3) you should call SetN1Func SetN2Func once for each variablename (here 3). Have fun JosDuchIt ### WINBIG 0 -10 300 120 Math_.gc WINTYPE 11110001 xONLOAD Gosub #this Default xONRELOAD Gosub #this Default xONCLOSE GuiQuit #this xROUTINE Default GuiOpen #this xBUTTON 0 17 60 17 "t" ; x = $(pi / 2) EzReq $(cos($x)) ok var EzReq "$(( cos($x) ^ 2) - ( sin($x) ^ 2) )" ok var xBUTTON 0 0 60 17 "only x" ; GadHelp "Functions of 1 variable: only x is an accepted variable name here" Gosub #this SetFunc x = .2 EZReq "x = $x\n$tg.x\n$($tg.x)" ok var ; x = .3 EZReq "x = $x\n$tg.x + 2\n$($tg.x + 2)" ok var xBUTTON 60 0 60 17 " x or.." ; <<>> GadHelp "Functions of 1 variable: any varuable name accepted" Gosub #this SetN1Func y y = .2 EZReq "y = $y\n$tg.y\n$($tg.y)" ok var ; y = .3 EZReq "y = $y\n$tg.y + 2\n$($tg.y + 2)" ok var xBUTTON 120 0 60 17 "N2" ; <<>> GadHelp "Functions of 2 variables: any varuable name accepted" Gosub #this SetN2Func Hk1 Hk2 Hk1 = .1 Hk2 = .2 EzReq "Hk1 = $Hk1\nHk2 = $Hk2\n$cos+.Hk1.Hk2\n$($cos+.Hk1.Hk2)" ok var xROUTINE SetFunc ; all defined functions will have only x as argument tg.x = "(sin(x) / cos(x))" RepVar tg.x (x) (\$x) CS cotg.x = "(cos(x) / sin(x))" RepVar cotg.x (x) (\$x) CS xROUTINE SetN1Func x ; Functions of one variable ; The argument given is the name not the value ; of the variable you want to use sin.$x = sin($x) RepVar sin.$x ($x) (\$$x) CS cos.$x = cos($x) RepVar cos.$x ($x) (\$$x) CS tg.$x = tan($x) RepVar tg.$x ($x) (\$$x) CS cotg.$x = "(cos($x) / sin($x))" RepVar cotg.$x ($x) (\$$x) CS cos2.$x = "(( cos($x) ^ 2) - ( sin($x) ^ 2) )" RepVar cos2.$x ($x) (\$$x) CS abs.$x = abs($x) RepVar abs.$x ($x) (\$$x) CS log.$x = log($x) RepVar log.$x ($x) (\$$x) CS ln.$x = ln($x) RepVar ln.$x ($x) (\$$x) CS exp.$x = exp($x) RepVar exp.$x ($x) (\$$x) CS xROUTINE SetN2Func x y ; name not value cos+.$x\#.$y = "cos($x + $y)" RepVar cos+.$x\#.$y $x \$$x CS RepVar cos+.$x\#.$y $y \$$y CS

