1# Misc Constants/functions for Dr. Genius 2 3#make something a string 4SetHelp("string","basic","Make a string"); 5function string(s) = s + "" 6 7SetHelp("Compose","basic","Compose two functions") 8function Compose(f,g) = (`(x)[f,g]=(local *;f(g(x)))) 9 10SetHelp("ComposePower","basic","Compose a function with itself n times, passing x as argument, and returning x if n == 0") 11function ComposePower(f,n,x) = ( 12 local *; 13 for k=1 to n do 14 x = f call (x); 15 x 16) 17 18SetHelp("PrintTable","basic","Print a table of values for f(n) for numbers from vector v, or if v is a number for integers from 1 to v") 19function PrintTable(f,v) = ( 20 local *; 21 # Note we can't check the 2 arguments, FIXME 22 if not IsFunction(f) then 23 (error("PrintTable: f must be a function of one argument");bailout); 24 25 if IsVector(v) then ( 26 for k in v do 27 print("" + k + "\t" + (f call (k))) 28 ) else if IsPositiveInteger(v) then ( 29 for k=1 to v do 30 print("" + k + "\t" + (f call (k))) 31 ) else ( 32 (error("PrintTable: v must be a vector or a positive integer");bailout) 33 ) 34) 35