"$d_Qroot""help - [develop, debug, error list, etc]/0_QNial lessons.txt" www.BillHowell.ca 07May2018 initial #**************************** # List of Lessons, generated with : # $ grep "^#]" "$d_Qroot""help - [develop, debug, error list, etc]/0_QNial lessons.txt" | sed 's/^#\]/ /' # Lesson - Handling atoms : [check, fault]s 07Dec2021 sub_posnA1stItmInTop_ary example Lesson - Testing provides actual context for future modifications not just [shallow yapping, arm-waving] of [statement, principle, rule]s [month,year]s later, the tests bring one back into context for a real understanding of behaviour 17Oct2021 path_exists IS OP typer path - returns true if a [directory, path] exists, or can be created Lesson - Nested array (nestAry) transformers - can I get there? Non-nested arrays (noNestAry) should be fine as standard [EACH, TWIG, LEAF, etc] should work. Also, is there a problem with the way that TWIG works? I need my own TWAG transformer. Lesson - writefile p_log doesn't work for some reason? Lesson - [LOCAL, NONLOCAL] don't really work!! example LOCAL as NONLOCAL effect Lesson - linking of single-character strings Lesson - QNial version of standard libraries - translate C libraries!! Lesson - [LOCAL,NONLOCAL] USE THEM to reduce code errors due to "stray" changes to NONLOCAL variables! Lesson - too much of my programming is in isolation, much faster to adapt existing libraries and use them I spend most of my time [build, mainta]ing tools, not doing my projects. Lesson - [QNial,bash] hybrid programming - sed 's###', careful if string has [".']!!! Lesson - tabs in a string entered on command line cause qnial to produce directory listings!!?!! 08********08 #] Lesson - Handling atoms : [check, fault]s +-----+ #] 07Dec2021 sub_posnA1stItmInTop_ary example sub_posnA1stItmInTop_ary IS OP sub ary { LOCAL ary sub faultL indx positionL slicer shapeAry shapeSub fitIndx1stSubItem indxA_1stSubItm_in_aryTop matchIndx1stSubItem maxIndx1stSubItem ; % ; faultL matchIndx1stSubItem := null null ; IF (isAtm ary) THEN faultL := fault '?sp1a1' ; ELSEIF (isAtm sub) THEN subr := [sub] ; ELSEIF (OR ((gage shape sub) > (gage shape ary))) THEN faultL := fault '?sp1a2' ; ELSEIF (isfault (faultL := sub_checkFitIntoTop_ary sub ary)) THEN null ; ENDIF ; % ; IF (= null faultL) THEN 08********08 #] Lesson - Testing provides actual context for future modifications #] not just [shallow yapping, arm-waving] of [statement, principle, rule]s #] [month,year]s later, the tests bring one back into context for a real understanding of behaviour +-----+ #] 17Oct2021 path_exists IS OP typer path - returns true if a [directory, path] exists, or can be created How is this supposed to behave? if a [file, dir] cart [exists, isEmpty]? if a dir new? It currently tests the parent of the directory specified!? seems crazy Today - just go with what I did before to preserve functionality of past programming. But this should be revisited. 08********08 #] Lesson - Nested array (nestAry) transformers - can I get there? #] Non-nested arrays (noNestAry) should be fine as standard [EACH, TWIG, LEAF, etc] should work. #] Also, is there a problem with the way that TWIG works? I need my own TWAG transformer. 03Oct2021 I have long struggled with optrs that must deal with [nested, complex] arrays, for which I will use the label "noNestAry". Questions : Do you really want to do "first [str, ary] cart [L,A]" if some of your work focuses on single [chr, str] replacements? If you force usage of "[,no]nestAry" [optr, tranformer]s, will it help raise your practicing meta-level of abstract [think, programm]ing? This could be the greatest benefit, irrespective of code efficiency? +--+ In practice, these only works for the uppermost level of strL, in which case EACH is all you need. However, it may be possible to implement [TWIG, LEAF, etc]. Also, TWIG does NOT seem to work right, or at least the way I sometimes would like. The standard QNial jargon for noNestAry is "simple array". This term is next-to-useless. +-----+ # ary1_transStr_isSameStructAs_ary2 IS OP ary1 transStr ary2 - # boolean indicating if ary[1,2] have same same structure by applying transformer transStr # 02Oct2021 initial ary1_transStr_isSameStructAs_ary2 IS OP ary1 transStr ary2 { LOCAL a result ; IF (str_toUpperCase transStr) in ('EACH' 'TWIG' 'LEAF') THEN cmd := link '= ' transStr ' (gage shape) ary1 ary2' ; IF (execute cmd) THEN result := l ; ELSE result := o ; ENDIF ; ELSE a := '?ary1_transStr_isSameStructAs_ary2 error: unlisted transformer' ; write a ; result := fault a ; ENDIF ; result } +-----+ # strL_cutBy_chrL IS OP strL chrL - cut each strL by all chrL, omitting chrL, lists only (not arys) # note that a character list is just a string, but I use "chrL" to emphasize that each chr cuts The hope was that this would generalize to all nested arrays, and not just strL (string list). In practice, this only works for the uppermost level of strL (or a non-nested strA?), in which case EACH is all you need. However, it may be possible to implement [TWIG, LEAF, etc] strL_cutBy_chrL IS OP strL chrL { LOCAL cmd noerror result ; IF flag_break THEN BREAK ; ENDIF ; noerror := l ; IF (NOT AND (EACH isString strL)) THEN noerror := o ; cmd := fault '?strL_cutBy_chrL error: strL is NOT all strings' ; write cmd ; result := cmd ; ENDIF ; % ; IF (NOT isString chrL) THEN noerror := o ; cmd := fault '?strL_cutBy_chrL error: chrL is NOT a string' ; write cmd ; result := cmd ; ENDIF ; % ; IF noerror THEN boolA := chrL atomA_restructSameAs_ary strL ; result := boolA EACHBOTH booleanL_cut_list strL ; ENDIF ; % ; result } +--+ # olde code The most recent version is first, which takes code from the # strL_cutBy_chrL IS OP strL chrL - cut each strL by all chrL, omitting chrL, lists only (not arys) # note that a character list is just a string, but I use "chrL" to emphasize that each chr cuts strL_cutBy_chrL IS OP strL chrL { LOCAL argAry boolAry boolLL ; IF flag_break THEN BREAK ; ENDIF ; boolTab := chrL EACHLEFT EACHRIGHT EACHRIGHT = strL ; boolAry := EACH (solitary first) NOT OR EACH EACH cols boolTab ; argAry1 := boolAry EACHBOTH pair (EACH solitary strL) ; argAry := EACH EACH first argAry1 ; EACH booleanL_cut_list argAry } # strL_cutBy_chrL IS OP strL chrL - cut each strL by all chrL, omitting chrL # formal tests - see link d_Qtest 'strings/strings- tests.ndf' # 11Jun2021 inital This generalizes str_cutBy_chr below. Here's a problem : do you really want to do "first [str, ary] cart [L,A]" if some of your work focuses on single [chr, str] replacements? strL_cutBy_chrL IS OP strL chrL { (NOT (chrL EACHLEFT EACHRIGHT EACHRIGHT = strL)) EACHBOTH booleanL_cut_list strL } # str_cutBy_chr IS OP str chr - cut a string at each chr, omitting chr # formal tests - see link d_Qtest 'strings/strings- tests.ndf' # 11Jun2021 inital str_cutBy_chr IS OP str chr { booleanL_cut_list (NOT (chr EACHRIGHT = str)) str } +-----+ # atomA_restructSameAs_ary IS OP atomA ary - only effective for top-most structure of ary # normally will be of use for noNestArys (non-nested) # not recommended : [crude, inefficient] alternative to using [EACH, TWIG, LEAF, etc] transformers As with strL_cutBy_chrL above : The hope was that this would generalize to all nested arrays, and not just non-nested arrays. In practice, this only works for the uppermost level of strL, in which case EACH is all you need. However, it may be possible to implement [TWIG, LEAF, etc] atomA_restructSameAs_ary IS OP atomA ary { LOCAL errorStr result ; IF (isAtomAry atomA) THEN result := (shape ary) reshape [atomA] ; ELSE errorStr := '?atomA_restructSameAs_ary error: atomA is NOT a atomA array' ; write errorStr ; result := fault errorStr ; ENDIF ; result } 08********08 #] Lesson - writefile p_log doesn't work for some reason? 26Mar2020 - I noticed this before, can't find notes 23Apr2020 p_log must be a filenumber, not a name!!! 08********08 #] Lesson - [LOCAL, NONLOCAL] don't really work!! example LOCAL as NONLOCAL effect 15Mar2020 while working on MindCode see link d_QNial_mine 'MindCode/code develop_test/MindCode [arith, trig] tests.ndf' net_struct IS { LOCAL net net_cols ; NONLOCAL structTitles netIDL outTypL optrL offTL waitTL inNetL outNetL net_rows nulColL ; ... net_rows := net_rows - 1 ; Subsequent use of net_rows redefined it! I had to make the change in later operators, such as : net_results IS { LOCAL netIDL net net_cols net_rows net_titles ; NONLOCAL resltTitles fireL StdL ResL OKL ; ... net_rows := net_rows - 1 ; LESSON: don't rely on LOCAL definitions, use operator-specific variable names 08********08 #] Lesson - linking of single-character strings # linking converts strings to characters! 01Jun2018 NUTS! linking converts strings to characters! 08********08 #] Lesson - QNial version of standard libraries - translate C libraries!! # too much (ALL) of my programming is in isolation, much faster to adapt existing libraries and use them 07May2018 C strings etc translate_Matlab_to_QNial.ndf - good template translate c to nial.txt -> convert to .ndf!!! >> when will I find the time to do this? 08********08 #] Lesson - [LOCAL,NONLOCAL] USE THEM to reduce code errors due to "stray" changes to NONLOCAL variables! 07May2018 08********08 #] Lesson - too much of my programming is in isolation, much faster to adapt existing libraries and use them #] I spend most of my time [build, mainta]ing tools, not doing my projects. 07May2018 08********08 #] Lesson - [QNial,bash] hybrid programming - sed 's###', careful if string has [".']!!! 15Jan2020 OK if you are good at [bash, QNial] programming, but it's tricky! ... I need to put fixes here! 07May2018 avoid, and when you do, don't mix in-line, # build a bash script for a lot of work, and run independent # too many problems with string [".']!!! Example : qnial> symTranslate_file_test /media/bill/PROJECTS/Qnial/code tests/symbols translate- tests.ndf Mon May 7 10:59:52 2018 # symTranslate_file_test example 1: compare test results in : /media/bill/PROJECTS/Lucas - Universal Force/Howell - math of Lucas Universal Force.txt /media/bill/ramdisk/trans_file_out.txt /media/bill/ramdisk/trans_file_diff.txt (ideally "/media/bill/ramdisk/trans_file_diff.txt" will be empty except for "good" substitution lines) Mon May 7 11:00:15 2018 >> OK, looks good! >> Great lesson - just use QNial! : >> runs 100 times faster with QNial than my hybrid [QNial,sed] version!!! >> (23 seconds rather than ~40 minutes (2,400 seconds) >> Coding with QNial is >>10 times faster than hybrid [QNial,sed], and FAR simpler >> Development time is critical - and QNial is a great prototyping language >> I'll have to check in detail manually. 08********08 #] Lesson - tabs in a string entered on command line cause qnial to produce directory listings!!?!! # (but not from a file?) 22Apr2018 # to put an apostrophe in a QNial string, just use a double apostrophe '' within the string, eg 'Here is an ''apostophe'' for you' # for sed : # from https://unix.stackexchange.com/questions/32907/what-characters-do-i-need-to-escape-when-using-sed-in-a-sh-script For details, see "/media/bill/PROJECTS/System_maintenance/Linux/sed notes.txt" in the list of characters matched by a bracket expression '$.*/[\]^' -> most of these are NOT legal symbol characters, so they won't be in extracted symbols In the replacement text: '&\/\n' ; # 15Apr2018 Currently I do this manually # enddoc