# loaddefs link d_Qnial_root 'setup.ndf' # Lenovo only : loaddefs '/home/bill/PROJECTS/Qnial/setup.ndf' # Define setup, important startup loads # Important - don't put projected-related setups here - put into quips.ndf EACH write '' '>>>>>>>>>>>>>>>' 'loading : setup.ndf' ; lq_setup IS loaddefs '/media/bill/SWAPPER/Qnial/setup.ndf' #************ # List of operators, generated with : # $ cat "$d_Qroot""setup.ndf" | grep "^#]" | sed 's/^#\]/ /' # Note : many operators should be moved to the appropriate libraties - eg [string, matrix]-related # That would collect ideas together, and reduce hunting-around. # ************************************************** Library directory definitions : **************************** loaddefs tracking : loaddefs_start IS OP f_name - helps to track progress of nested (indented) loaddefs loaddefs_ended IS OP f_name - helps to track progress of nested (indented) loaddefs *********************************************************** DEBUGGING tools - initial settings : write_debug IS OP AAA - writes debug information to the screen writefile_debug IS OP AAA - writes debug information to d_QNial_temp '0_QNial debug log.txt' killfile_debug IS - erases the debug file d_QNial_temp '0_QNial debug log.txt' writefile_log IS OP AAA - logs picture of array to d_QNial_temp '0_QNial log.txt' killfile_log IS - erases logfile d_QNial_temp '0_QNial log.txt' ************************ loaddef [strings, file_ops].ndf : ******************************************** workspace status, checks of [file system, workspace], shell command implementation : writestatus IS - returns QNial env size : [free, lgstblk, #freeblks, Wkspc, stack, atom, internal] file_exists IS OP p_type p_name - returns l if file exists, or o if not HDdrive_mountCheck IS OP dir_to_test - checks if hard drive is mounted (dumb coding?) shellApp_cmds - execute muli-line bash commands like a script (sometimes don't work in terminal?) ******************************************** Special Howell versions of basic ops : check_examples IS OP strList_name - to facilitate [setup, calc, display, check] of examples find_Howell_subString IS OP string_snip stringer - find subString in string, returns error if not found (not the length!) find_Howell IS OP item_sought list_to_search - finds FIRST occurrence of an item [atom,subList,string] in a list of [atoms, lists,strings], returns error if not found (not the length!), integer otherwise, but it will NOT find a string within a string findAll_Howell IS OP item_sought list_to_search - finds ALL occurrences of an item [atom,subList,string] in a list of [atoms, lists,strings], returns error if not found (not the length!), list otherwise but it will NOT find a string within a string, sublistwithin a list, etc sortup_cull_listCollection IS OP arrayOfLists - given a set of lists, [sortup,cull] contents of each based on first list ****************************** Handy mathematical stuff : average IS / [sum, tally] square IS prod [pass, pass] floor_mod IS OP a b - convenient return of BOTH floor and mod! Matrix ops - symbolic through semi-symbolic through numeric lq_[matrix, matrixRedn, align_paren, matrix_examples, directed_graphs] ******************************** Select regions of an array - Howell's operators : sequencer IS OP pointpair - obvious functionality choose_region IS OP pointpairs array - obvious functionality ******************************** Encryption-related, should set up d_QNial_mine 'encrypt - code generation.ndf' : full_code IS - randomly generated codes [alpha, numeric, symbol] codes (12 character sequences) numeric_code IS - randomly generated numeric-only codes (12 character sequences) alpha_code IS - randomly generated alpha-only codes (12 character sequences) alphanumeric_code IS - randomly generated codes [alpha, numeric] codes (12 character sequences) save_codes IS - save randomly generated full, alpha, numeric, alpha-numeric] codes (20 codes per class) ******************************************************** Current project environments : IJCNN mass emails : Depending on commnenting out of lines in f, you can do : lq_[window, audios] not yet [videos, ???] : lq_quips - is a text file for rapid testing of code & concepts loaddefs of symbols [extraction,translation,fix] system ************************************************** startup launches of [workspaces, programs, working docs] : #] ************************************************** #] Library directory definitions : %d_meda := '/media/bill/' ; % LMDE ; d_meda := '/home/bill/' ; % Lenovo ; d_SWAPPER := link d_meda 'SWAPPER/' ; d_PROJECTS := link d_meda 'PROJECTS/' ; d_QNial_root := link d_PROJECTS 'Qnial/' ; d_QNial_lib := link d_QNial_root 'niallib/' ; d_QNial_mine := link d_QNial_root 'MY_NDFS/' ; d_QNial_Stats := link d_QNial_root 'Smillie UAlberta - statistics 1987/' ; d_Qnial_tests := link d_QNial_root 'code develop_test/' ; d_QNial_secure := link d_PROJECTS 'QNial - secure/' ; d_MIDAS := '/media/bill/Midas/' ; d_HOWELL_BASE := '/media/bill/HOWELL_BASE/' ; d_Qnial_music := link d_HOWELL_BASE 'My Music/' ; d_Thunderbird := link d_HOWELL_BASE 'Thunderbird/n4caryuo.default/Mail/Local Folders/' ; d_Lexicom := '/media/bill/Midas/a_INNS Lexicom email server/' ; # computer := ["LMDE2, "Lenovo, "RaspPi] ; # For each computer, this was specified in : '/media/bill/SWAPPER/Qnial/start.ndf' OR '/media/bill/SWAPPER/Qnial/maintain.ndf' # 09Apr2018 NYET - environmental variables for bash don't translate directly to QNial!!! host link 'echo >"/home/bill/HOWELL_computer.txt" "$HOWELL_computer" ' ; fin := open '/home/bill/HOWELL_computer.txt' "r ; computer := readfile fin ; close fin ; IF (= 'RaspPi' computer) THEN d_QNial_temp := '/media/bill/RaspPi_ext4_32Gb/temp/' ; ELSEIF (= 'ThinkPad' computer) THEN d_QNial_temp := '/run/media/bill/ramdisk/' ; ELSE d_QNial_temp := '/media/bill/ramdisk/' ; ENDIF ; p_hostCmdRslt := link d_QNial_temp 'QNial host response.txt' ; # predefine ops to avoid sequencing problems with loaddefs : host_result IS OP cmd { null } #] **************************** #] loaddefs tracking : # Adapt this for every QNial program as a reminder ... # loaddefs_start IS OP f_name - To make it easier to see nesting of loaddefs # loaddefs_level := 0 ; #] loaddefs_start IS OP f_name - helps to track progress of nested (indented) loaddefs loaddefs_start IS OP f_name { NONLOCAL loaddefs_level ; loaddefs_level := loaddefs_level + 1 ; write link (3 * loaddefs_level reshape `>) ' loading start : ' f_name ; } #] loaddefs_ended IS OP f_name - helps to track progress of nested (indented) loaddefs loaddefs_ended IS OP f_name { NONLOCAL loaddefs_level ; write link (3 * loaddefs_level reshape `<) ' loading ended : ' f_name ; loaddefs_level := loaddefs_level - 1 ; } # template for .ndf files f_strings := 'strings.ndf' ; loaddefs_start f_strings ; loaddefs_ended f_strings ; #] *********************************************************** #] DEBUGGING tools - initial settings : # debugging code - "/media/bill/SWAPPER/Qnial/1_bug hunt template for ndf files.txt" # general principles - "/media/bill/SWAPPER/Qnial/1_Debugging.txt" write 'loading : Debugging setup and reminders' ; # debug setup flag_break := l ; % stop execution to test local environment ; flag_check := o ; % force checking of all operators with examples, showing results ; flag_debug := l ; % include additional output to help debug results ; flag_fault := o ; # IF flag_break THEN break ; ENDIF ; fonn IS { NONLOCAL flag_break ; flag_break := l } foff IS { NONLOCAL flag_break ; flag_break := o } # doesn't work? program_break IS { IF flag_break THEN Break ; ENDIF ; } # Faults occur normally during searches, and must not stop execution! settrigger o ; #] write_debug IS OP AAA - writes debug information to the screen # writefile_debug writes to the debug FILE! (log file for debug) # Change p_debug for each project!!! # 16Aug2017 - doesn't work!! write_debug IS OP AAA { NONLOCAL flag_debug ; IF flag_debug THEN EACHRIGHT write (rows picture AAA) ; ENDIF ; } #] writefile_debug IS OP AAA - writes debug information to d_QNial_temp '0_QNial debug log.txt' writefile_debug IS OP AAA { LOCAL fot p_debug ; NONLOCAL d_QNial_temp ; IF flag_debug THEN p_debug := link d_QNial_temp '0_QNial debug log.txt' ; fot := open p_debug "a ; fot EACHRIGHT writefile (rows picture AAA) ; close fot ; ENDIF ; } #] killfile_debug IS - erases the debug file d_QNial_temp '0_QNial debug log.txt' killfile_debug IS { LOCAL fot p_debug ; NONLOCAL d_QNial_temp ; IF flag_debug THEN p_debug := link d_QNial_temp '0_QNial debug log.txt' ; host link 'rm "' p_debug '"' ; ENDIF ; } #] writefile_log IS OP AAA - logs picture of array to d_QNial_temp '0_QNial log.txt' # might want a different file for each project? writefile_log IS OP AAA { LOCAL fot p_log ; NONLOCAL d_QNial_temp ; p_log := link d_QNial_temp '0_QNial log.txt' ; fot := open p_log "a ; fot EACHRIGHT writefile (rows picture AAA) ; close fot ; } #] killfile_log IS - erases logfile d_QNial_temp '0_QNial log.txt' # might want a different file for each project? killfile_log IS { LOCAL fot p_log ; NONLOCAL d_QNial_temp ; p_log := link d_QNial_temp '0_QNial log.txt' ; host link 'rm "' p_log '"' ; } # important for text files fault_eof := ??eof ; setprompt 'qnial> ' #] ************************ #] loaddef [strings, file_ops].ndf ... loaddefs link d_QNial_mine 'strings.ndf' ; loaddefs link d_QNial_mine 'file_ops.ndf' ; #] ******************************************** #] host commands, checks of [file system, workspace, drives] : write 'loading : host commands, checks of [file system, workspace, drives]' ; set "nolog ; setformat 0 6 6 -6 0; setwidth 110 ; % normal is 80 characters, can do much more on high-res ; % screensize returns current value, doesn't work in my compilation! ; # The global variable "computer" is set in the file # "/media/bill/SWAPPER/Qnial/start.ndf" # computer := "Lenovo ; # computer := "Toshiba ; # computer := "RaspPi ; #] file_exists IS OP p_type p_name - returns l if file exists, or o if not # DDMMM2018 CROSS-REFERENCE : strings.ndf needs file_ops.ndf and visa-versa, both of which are loaded by "setup.ndf" # 27May2018 file_exists is required in strings, so define the required operation here. # It will be reset by the file_ops.ndf load. Beware of any changes to "file_exists" in either file! # file_exists IS OP p_type p_name - returns true if a [directory, filepath] exists # p_type = '-d' for directory , p_type = '-f' for filepath file_exists IS OP p_type p_name { LOCAL fin flag_exists p_temp ; NONLOCAL d_QNial_temp ; p_temp := link d_QNial_temp 'p_exists temp.txt' ; host link '[ ' p_type ' "' p_name '" ] && echo l >"' p_temp '" || echo o >"' p_temp '" ' ; fin := open p_temp "r ; flag_exists := readfile fin ; close fin ; IF (= 'l' flag_exists) THEN l ELSE o ENDIF } #] host_result IS OP str - returns [str, str_array, null] result of host commands with stdout returns # 17Jan2020 initial for "Anonymous Recipient Email Daemon" (ARED) # dangerous to use if cmd already outputs to a file!!! # readfile cases : # - null : # - [integer, real] - depends if conversion to str is needed? # - string : will want to "extract" from 1st and only item in list # - string_list : depends on application host_result IS OP cmd { host link cmd ' >"' p_hostCmdRslt '" ' ; finn := open p_hostCmdRslt "r ; result := '' ; WHILE (~= ??eof (line := readfile finn)) DO result := append result line ; ENDWHILE ; close finn ; result } # tests # host_result 'ls ' #] shellApp_cmds - execute muli-line bash commands like a script (sometimes don't work in terminal?) # many programs that run in a shell (terminal) don't work properly but by running via bash on a script file they are OK... # examples - some bash commands (echo), xdotool, # this is for multiple lines of script, for a single command invoke with QNial "solitary command_line") shellApp_cmds IS OP command_lines { LOCAL fot pname_script ; NONLOCAL d_QNial_temp ; %write_debug 'shellApp_cmds : ' ; %EACH write_debug command_lines ; pname_script := link d_QNial_temp '0_QNial shellApp_cmds.txt' ; fot := open pname_script "w ; fot EACHRIGHT writefile command_lines ; close fot ; host link 'bash "' pname_script '"' ; } #] writestatus IS - returns QNial env size : [free, lgstblk, #freeblks, Wkspc, stack, atom, internal] # 06Dec05 writestatus IS { write 'Status (words except #freeblocks): ' ; write ( 2 7 reshape (('free' 'lgstblk' '#freeblks' 'Wkspc' 'stack' 'atom' 'internal') link status)) ; } #] HDdrive_mountCheck IS OP dir_to_test - checks if hard drive is mounted (dumb coding?) HDdrive_mountCheck IS OP dir_to_test { NONLOCAL dir QNial ; fpath_log := link d_QNial_root 'z_HDdrive_mountCheck.txt' ; cmd := link 'ls >"' fpath_log '" "' dir_to_test '"' ; write 'HDdrive_mountCheck : ' cmd ; host cmd ; fin := open fpath_log "r ; line1_directory_output := readfile fin ; close fin ; IF isfault line1_directory_output THEN o ELSE l ENDIF } #] ******************************************** #] Special Howell versions of basic ops : write 'loading : Special Howell versions of basic ops' ; #] check_examples IS OP strList_name - to facilitate [setup, calc, display, check] of examples check_examples IS OP strList_name { exampler := execute strList_name ; EACH write ' ' ' ' '**************' (link 'check_examples on : ' (string strList_name)) ' ' ; FOR i WITH exampler DO write ' ' ; [write, write execute] i ; ENDFOR ; } #] find_Howell_subString IS OP string_snip stringer - find subString in string, returns error if not found (not the length!) # see in_string find_Howell_subString IS OP string_snip stringer { temp := find string_snip stringer ; IF (temp < gage shape stringer) THEN temp ELSE fault '?find_Howell_substring - substring not found' ENDIF } #] find_Howell IS OP item_sought list_to_search - finds FIRST occurrence of an item [atom,subList,string] in a list of [atoms, lists,strings], returns error if not found (not the length!), integer otherwise, but it will NOT find a string within a string find_Howell IS OP item_sought list_to_search { listShape := gage shape list_to_search ; IF (= listShape (key := find item_sought list_to_search)) THEN key := fault '?find_Howell : item not found' ELSE key ENDIF } # examples qnial> find_Howell (2 3 4) ((1 2 3) (2 3 4) (5 6 7) (8 9 10)) 1 qnial> find_howell 'fish' 'There are many fish in the ocean' ?find_Howell : item not found qnial> find_howell 'fish' ('There are many fish in the ocean' 'plants' 'food' 'fish') 3 #] findAll_Howell IS OP item_sought list_to_search - finds ALL occurrences of an item [atom,subList,string] in a list of [atoms, lists,strings], returns error if not found (not the length!), list otherwise but it will NOT find a string within a string, sublistwithin a list, etc findAll_Howell IS OP item_sought list_to_search { LOCAL i_ins ; i_ins := item_sought EACHRIGHT = list_to_search ; i_adds := i_ins sublist (tell gage shape list_to_search) ; IF (isfault i_adds) THEN fault '?findAll_Howell : item not found' ELSE i_adds ENDIF } # qnial> findAll_Howell 5 (1 2 3 4 5 8 3 5 9 1) #] sortup_cull_listCollection IS OP arrayOfLists - given a set of lists, [sortup,cull] contents of each based on first list # sort by "up" (lexicographic comparison - alphabetic for strings) ; # - code from symsExtractTranslate, uses "grade" ; sortup_cull_listCollection IS OP arrayOfLists { LOCAL A addressListCulled addressListSorted culledLists sortedLists ; % ; A := first arrayOfLists ; %sort by "up" (lexicographic comparison - alphabetic for strings) based on first List ; addressListSorted := gradeup A ; sortedLists := addressListSorted EACHRIGHT choose arrayOfLists ; % ; %cull the lists [raw,trn] - I need a list of indexes that are the "first occurence of items" in (first arrayOfLists) ; A := first sortedLists ; addressListCulled := cull (A EACHLEFT find A) ; addressListCulled EACHRIGHT choose sortedLists } # Cull Definition cull IS OPERATION A {­ grid A EACHLEFT in (A EACHLEFT find A) sublist A } culledLists := addressListCulled EACHRIGHT choose arrayOfLists ; # STRANGE : grid A = A EACHLEFT find A ???!!!??? addressListCulled := grid sortedLists EACHLEFT in (sortedLists EACHLEFT find sortedLists) sublist sortedLists ; #] ****************************** #] Handy mathematical stuff : write 'loading : Handy mathematical stuff' ; #] average IS / [sum, tally] average IS / [sum, tally] #] square IS prod [pass, pass] square IS prod [pass, pass] #] floor_mod IS OP a b - convenient return of BOTH floor and mod! # NOTE : the offset 1e-6 is used to avoid excessive "down-rounding" # hopefully this will NOT introduce errors to mod!!??!! floor_mod IS OP a b { LOCAL divident div_flr div_mod ; dividend := a / b ; div_flr := floor dividend ; div_mod := floor ((dividend - div_flr) * b + 1e-6) ; div_flr div_mod } #************************************************** #] Matrix ops - symbolic through semi-symbolic through numeric lq_matrix IS loaddefs link d_QNial_mine 'matrix operations - symbolic & real-valued.ndf' lq_matrixRedn IS loaddefs link d_QNial_mine 'matrix - symbolic reduction.ndf' lq_align_paren IS loaddefs link d_QNial_mine 'matrix - write with parenthesis aligned.ndf' lq_matrix_examples IS loaddefs link d_QNial_mine 'matrix_multiply - examples and validation.ndf' lq_directed_graphs IS loaddefs link d_QNial_mine 'directed graphs.ndf' ; # matrix - symbolic & real-valued matrix operations # matrix_multiply_symbolic IS # - produces result of matrix multiplication from # "labelled_arrays" or "array_of_strings" # matrix_multiply IS # - standard matrix multiplication for numeric-only arrays # matrix multiply => INNER [+,*] A B where cols A = rows B # directed graphs.ndf #] ******************************** #] Select regions of an array - Howell's operators : # (this has not been optimized). - JUST USE "SLICE" ADDRESSING, WHICH DOES THIS!!! write 'loading : select regions of an array ...' ; #] sequencer IS OP pointpair - obvious functionality sequencer IS OP pointpair { a b := pointpair; a + tell (b - a + 1) } #] choose_region IS OP pointpairs array - obvious functionality choose_region IS OP pointpairs array { (cart each sequencer pointpairs) choose array } # Example - selecting subarrays of a survey Prob_case := choose_region ((5 16) (1 4)) survey; #] ******************************** #] Encryption-related, should set up d_QNial_mine 'encrypt - code generation.ndf' : write 'loading : Encryption-related' ; #] full_code IS - randomly generated codes [alpha, numeric, symbol] codes (12 character sequences) full_code IS EACH char (33 + EACH floor (93 * random 12)) #] numeric_code IS - randomly generated numeric-only codes (12 character sequences) numeric_code IS EACH char (48 + EACH floor (10 * random 12)) #] alpha_code IS - randomly generated alpha-only codes (12 character sequences) alpha_code IS { alpha_list := '' ; char_all_list := EACH char (33 + EACH floor (93 * random 50)) ; FOR i WITH tell 50 DO IF in char_all_list@i 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' THEN alpha_list := alpha_list link char_all_list@i ; ENDIF ; ENDFOR ; 12 TAKE alpha_list } #] alphanumeric_code IS - randomly generated codes [alpha, numeric] codes (12 character sequences) alphanumeric_code IS { alpha_list := '' ; char_all_list := EACH char (33 + EACH floor (93 * random 50)) ; FOR i WITH tell 50 DO IF in char_all_list@i '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' THEN alpha_list := alpha_list link char_all_list@i ; ENDIF ; ENDFOR ; 12 TAKE alpha_list } #] save_codes IS - save randomly generated full, alpha, numeric, alpha-numeric] codes (20 codes per class) save_codes IS { fot := open link d_Qnial_temp 'z_Old/sequences.txt' "w ; fot EACHRIGHT writefile ' ' '****************' 'full ' ; FOR i with tell 20 DO writefile fot full_code ENDFOR ; fot EACHRIGHT writefile ' ' '****************' 'numeric ' ; FOR i with tell 20 DO writefile fot numeric_code ENDFOR ; fot EACHRIGHT writefile ' ' '****************' 'alpha ' ; FOR i with tell 20 DO writefile fot alpha_code ENDFOR ; fot EACHRIGHT writefile ' ' '****************' 'alphanumeric ' ; FOR i with tell 20 DO writefile fot alphanumeric_code ENDFOR ; close fot ; } #] ******************************************************** #] Current project environments : #] IJCNN mass emails : Depending on commnenting out of lines in f, you can do : f_emailESC := 'email - extract, sort, cull addresses from text.ndf' ; lq_emailESC IS loaddefs link d_QNial_mine f_emailESC #******************************************** #] lq_[window, audios] not yet [videos, ???] : lq_windows IS loaddefs link d_QNial_mine 'windows - position, size, move, desktop opens.ndf' lq_audios IS loaddefs link d_QNial_mine 'audio - music, microphone.ndf' # Not ready yet - part of package for video production # /media/bill/SWAPPER/Qnial/MY_NDFS/video production/ # audio capture/0_VoiceList record and play.ndf # video capture/0_vidExtrn - common data, operators.ndf # video production/0_vidConv - common data, operators.ndf # video production/0_vidProdn - common data, operators.ndf #******************************* #] lq_quips - is a text file for rapid testing of code & concepts lq_quips IS loaddefs (link d_QNial_root 'quips.ndf') writestatus ; #********************************************* #] loaddefs of symbols [extraction,translation,fix] system # Setup - need to use example of project : Lucas Universal force # other examples and tests later # defined by setup.ndf # d_Qnial_tests lq_symBase IS { loaddefs link d_Qnial_mine 'symbols system loaddefs.ndf' ; loaddefs link d_Qnial_mine 'strings.ndf' ; loaddefs link d_Qnial_mine 'symbols extract.ndf' ; loaddefs link d_Qnial_mine 'symbols translate.ndf' ; loaddefs link d_Qnial_mine 'symbols fix.ndf' ; } lq_symTests IS { lq_symBase ; loaddefs link d_Qnial_tests 'strings- tests.ndf' ; loaddefs link d_Qnial_tests 'symbols system loaddefs- tests.ndf' ; loaddefs link d_Qnial_tests 'symbols extract- tests.ndf' ; loaddefs link d_Qnial_tests 'symbols translate- tests.ndf' ; loaddefs link d_Qnial_tests 'symbols fix- tests.ndf' ; } #] ************************************************** #] startup launches of [workspaces, programs, working docs] : # At startup on the host machine "start.ndf" OR "maintain.ndf" assigns ["Toshiba, "Dell64, "Lenovo] to # the variable "computer", so no decision is needed here. f_workSpace := 'USB workspace loads.ndf' ; lq_workSpace IS loaddefs link d_QNial_mine f_workSpace EACH write 'Easy starts from setup.ndf : ' ' lq_align_paren - matrix - write with parenthesis aligned.ndf' ' lq_audios - audio ops' ' lq_directed_graphs - directed graphs.ndf' ' lq_emailESC - Manage mass email lists for [WCCI,IJCNN,INNS-BigData]' ' lq_matrix - matrix operations - symbolic & real-valued.ndf' ' lq_matrixRedn - matrix - symbolic reduction.ndf' ' lq_matrix_examples - matrix_multiply - examples and validation.ndf' ' lq_quips - text file for rapid testing of code & concepts' ' lq_symbBase - basic operators for symbols [extraction,translation] system ' ' lq_symTests - tests of [strings, symbols [extraction,translation]] systems (loads lq_symBase) ' ' lq_windows - window [size, move,etc]' ' lq_workSpace - DesktopSetup of workspaces and windows' (link 'completed loading : setup.ndf') '<<<<<<<<<<<<<<<' ' ' ' ' ; # enddoc