# "$d_Qroot""help - [develop, debug, error list, etc]/3_Debug - routines and habits to help debug QNial projects.txt" # www.BillHowell.ca <<16Feb2007 initial? # Library directories for reference QNial_lib := 'C:\Languages\Q'Nial\niallib\' ; Howell_lib := 'C:\Documents and Settings\William Neil Howell\My Documents\Qnial\MY_NDFS' ; Howell's definitions are NOT in separate file - only this one!! #******************************* Contents clean_symbol_list produce a list of global symbols & files which files define & use them make type_check check data types # *************************** Operation: is_blankstring Howell 16Feb07 Based on QNial library: File: stripblk.ndf QNial library # This operation removes all leading and trailing blanks from a string. char_Tab := 8 ; char_newline := 10 ; char_carriagereturn := 13 ; char_space := 32 ; is_blankstring IS OP Str { charrep_list := each charrep Str ; test_char_tab := char_tab EACHRIGHT match charrep_list ; test_char_newline := char_newline EACHRIGHT match charrep_list ; test_char_carriagereturn := char_carriagereturn EACHRIGHT match charrep_list ; test_char_space := char_space EACHRIGHT match charrep_list ; AND OR test_char_tab test_char_newline test_char_carriagereturn test_char_space } # *************************** make - this EXAMPLE must be extensively modified for each situation!! Laskar_directory := 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Laskar - Milankovic insolation program\2004 Howell\' ; # you'll need the string_wide operation: loaddefs (link % Names of project files ; f1 := 'Main.ndf' ; f2 := 'Interpolation.ndf' ; f3 := 'Insolation.ndf' ; f10 := 'Milankovic - civilization.ndf' ; f99 := 'Civilization problem setup.ndf' ; % Select files and arrangements when loading ; make_all := f3 f2 f10 f99 f1 ; % this is the normal list order to load all files ; make_list := solitary f3 ; % specify which files to loaddef - use solitary for single file ; loaddef_mode := l ; % display line by line as file loads? ; autolog_mode := l ; symbol_mode := l ; # make_list := make_all ; IF autolog_mode THEN old_logmode := set "log ELSE old_logmode := set "nolog ENDIF ; FOR i WITH make_list DO loaddefs (link Laskar_directory i) loaddef_mode ; ENDFOR ; set "old_logmode ; # to display "hand-specified" symbols v_list := 0.0 ; f_list := 0.0 ; z_list := 0.0 ; IF symbol_mode THEN fout := open (link Laskar_directory 'Symbol_list.txt') "w ; xx:= EACH string EACH first (symbols 0) ; e_list := (OR ( ('_O$' EACHRIGHT regexp_match xx) ('_V$' EACHRIGHT regexp_match xx) ('_E$' EACHRIGHT regexp_match xx) ('_X$' EACHRIGHT regexp_match xx) ) ) sublist xx ; v_list := EACH string e_list ; v_list_len := 3 + max EACH shape v_list ; vv_list := v_list EACHLEFT string_wide (first v_list_len) ; f_list := EACH string EACH value e_list ; f_list_len := 1 + max EACH shape f_list ; ff_list := f_list EACHLEFT string_wide (first f_list_len) ; z_list := EACH link pack vv_list ff_list ; fout EACHRIGHT writefile z_list ; ENDIF ; # To run the program Civic # *************************** Operation: towords1 Str Howell: 16Feb07 based on QNial library 'towords' # This operation returns the list of STRINGS (not phrases!! like the QNial library) of the words in the string. Words in the string are character sequences separated by one or more blanks. For example, the string 'See Spot run.' has 3 words: "See", "Spot" and "run.". towords1 IS OPERATION Str { Strings := EACH pass ( ` match Str cut Str ) } # Examples: w := 'See sam cok the dinner ' ; Result +---+---+---+---+------+ |See|sam|cok|the|dinner| +---+---+---+---+------+ # *************************** clean_symbol_list - produce a list of global symbols & files which files define & use them clean_symbol_list IS OP directory filename_in filename_out { fin := open (link directory Filename_in ) "r ; fout := open (link directory Filename_out) "a ; WHILE ((w := readfile fin) ~= ??eof) DO % first clear out "decorative" items & whitespace ; w := regexp_substitute '\|' ' ' w "g ; w := regexp_substitute '-' ' ' w "g ; w := regexp_substitute '\+' ' ' w "g ; % don't need to nuke the whitespace ; % final work on each line ; IF NOT is_blankstring w THEN writefile fout (link (link ((' "' EACHRIGHT link (towords1 w))) (link (solitary ' zzz') Filename_in (solitary 'zzz')) )) ; ENDIF ; ENDWHILE ; writefile fout ' ' ; close fin ; close fout ; } # Example - for entire Laskar project di := 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Laskar - Milankovic insolation program\2004 Howell\' ; fo := 'Laskar symbols raw.txt' ; #fi := 'simple test file.txt' ; % small test file ; clean_symbol_list di fi fo ; fi := 'Civilization problem setup.sym' ; clean_symbol_list di fi fo ; fi := 'Milankovic - civilization.sym' ; clean_symbol_list di fi fo ; fi := 'Main.sym' ; clean_symbol_list di fi fo ; fi := 'Interpolation.sym' ; clean_symbol_list di fi fo ; fi := 'Insolation.sym' ; clean_symbol_list di fi fo ; #*************************************** # type_check.ndf Routines for implementing checking of data types # default type_checking is FALSE global_typecheck := o ; # Standard types global_object_types := [ "boolean "isboolean, "char "ischar, "fault "isfault, "int "isinteger, "list "islist, "phrase "isphrase, "real "isreal, "solitary "issolitary, "string "isstring ] # what is a list? Here its assume that a list is a 1 dimensional array of atomic data - which is NOT the full definition of a list in Nial! islist IS OP data { IF tally TWIG shape data = 1 THEN l ELSE o ENDIF } type_check IS OP object_type data { type_tests := object_types|[FIND object_type first object_types, 1] ; IF AND (AND = EACH shape type_tests data) (AND (type_tests TWIG apply data)) THEN l ELSE o ENDIF } #Examples IF global_typecheck THEN type_check_result := EACH type_check ["int net_model, "int out_model, "int out_linear, "int n_inputs, "int n_hidden1, "int n_hidden2, "int n_outputs, "int executable, "int zero] ; IF NOT AND type_check_result THEN return 'LayerNet type error' typecheck_result ; ENDIF; ENDIF; # enddoc