##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: August 2016 # Modified: 2016-10-03/23:23-0400 ##+ # # type.icn, demonstrate the type() function # procedure main() # list of expressions to evaluate types := [ "type(1)", "type(type(1))", "type(\"abc\")", "type(L)", "type(T)", "type(S)", "type(R)", "type(C)", "type(&window)", "type(file)" ] # generate some code to evaluate the expressions prog := "generated-type-program.icn" tmp := open(prog, "w") | stop("Can't open " || prog || " for writing") write(tmp, "record rec(a,b)") write(tmp, "procedure main()") write(tmp, " L := []") write(tmp, " T := table()") write(tmp, " S := set()") write(tmp, " R := rec(1,2)") write(tmp, " C := create 1") write(tmp, " &window := open(\"window\", \"g\", \"canvas=hidden\")") write(tmp, " file := open(&file, \"r\")") every t := !types do { write(tmp, " write(right(", image(t), " || \": \"", ",16), ", t, ")") } write(tmp, " close(file)") write(tmp, " close(&window)") write(tmp, "end") close(tmp) # pipe in the results p := open("unicon -quiet -s -v0 " || prog || " -x", "p") while write(read(p)) close(p) # get rid of the generated source and executable remove(prog) remove(prog[1:-4]) end