********************* loaddefs link d_Qndfs 'arrays atomic.ndf' - operators for TOP level only (not nested!) WARNING! use _chkAppOp for developments call ary optrs directly to save [vast, redundant] operator versions +-----+ Setup Predefine local ops to avoid sequencing problems with initial qnial loaddefs +-----+ [itm, sub]_in_[ary, table, matrix] operators - see link d_Qndfs 'types.ndf' +-----+ Array restructure [to,from] cart [atm, str, lst, ary] : many work on nry (nested) aryA_catVertical IS OP aryA - joins 2D arrays by "stacking-merging" each above next aryA_catHorizontal IS OP aryA - joins 2D arrays by "side-merging" each alongside next ary_repeatNtimesTo_aryL IS OP ary n - repeats ary n times ary_atm_putAllAtm_aryOut IS OP ary atm - replace all atoms of ary with atm handy for test standards, ready for post-replacements, works for atm=null even if is not an atom aryP_transStr_isSameStruct IS OP aryP transStr - boolean indicating if aryPL (= [y1, ary2] have same same structure according to transformer transStr ary_to_atmL_recurse IS OP ary - recursion to get working ary_to_atmL_recurse ary_to_atmL IS OP ary - returns an atmL containing all contents of ary handy for nestAry [test, standard]s, - eg all [bool, chr, int, real, phrase, complex] ary ary_allAtmsUnique IS OP ary - tests if topLevel itms of ary are unique ary_allItmsUnique IS OP ary - tests if topLevel itms of ary are unique [atm, single, solitary]s are unique by defn +-----+ [idx, itm, slc, sub] optrs - (slc = slice hyper-planes) typically returns a LIST : the use of commas, followed by execute string is necessary. I can't get "nulls" to work otherwise use of "ary" instead of "ary" can be confusing, but hightlights minimal information needed 'arrays- testOptrs.ndf' mostly uses "ary" optrs, not "ary, for easy data setup, tracking 10Nov2022 problem with indexes - should always be a minimum of solitary (valence >= 1)? 10Nov2022 ary valnce >= 1, so solitaries are legitimate arys? adrLL_to_idxLL IS OP adrLL - returns a list of "targeted" indexes for each axis, based on adrLL ary_get_idxAll IS OP ary - returns [i j] for ary top level (idx, not str!) ary_symStr_make_idxSymAll IS OP ary symStr - make ary of shape ary, elements 'symStr@[i,j]' for easily following processes! eg see 'matrix operations - symbolic & real-valued.ndf' symStr must end with '@[', usually preceded by the name of the ary being looked at ary_idx_get_itm IS OP ary idx - returns itm of aryTop ary_idxSeq_to_slc IS OP ary idxSeq - convert idxSeq to slc isIntLL(idxSeq) where idxSeq[axi] MUST be OR[full slice, [int]]! example idxSeq := (1 0 0) (1 0 1) (1 0 2) (1 0 3), result [1, 0, 0 1 2 3] 16Dec2022 at this stage cannot check that idxSeq "fits" -> need ary 05Mar024 doesn't check for isTypVerBar at this time ary_itm_get_idxL IS OP ary itm - returns all positions of itm in ary, or o (false) 05Mar024 doesn't check for isTypVerBar at this time itm MUST be an "element" of ary, eg (0 1) in ((0 1) 2 3 4 5), not in (0 1 2 3 4 5) note the very strict standard formatting of slices!! ary_itm_get_slcL IS OP ary itm - get all slices (hyperplanes) through itm in ary slcLL = list of all slcL, one slcL for every occurrence of itm in ary, 2^aryVal slc in each slcL allows subsequent find of sub at point itm, along "free" axis of ary Note that itm can be ANYTHING! (including [null, atm, solitary, single, etc]) idx refers to one point only at topLevel of ary, MUST have same valence as ary! ary_slc_to_idxA IS OP ary slc - convert slcA to idxA for itmSlc, a single is converted to a solitary (list) ary_slc_get_sub IS OP ary slc - res ipsa loquitor, not much use except for executables ary_slcA_to_idxAA IS OP ary slcA - convert idxA to slcA ary_slc_invert IS OP ary slc - returns the "inverse Axs-sliceidxL", useful for [cut etc] 17Nov2021 initial draft only, doesn't work yet,list version only so far 17Apr2022 does this even make sense? - do later when I get to it ary_slcA_invert IS OP ary slcA - returns the "inverse Axs-sliceidxA", useful for [cut etc] 11Feb2022 initial ghost only, simply calls ary_slc_invert, difficult to define in ary case? 17Apr2022 does this even make sense? - do later when I get to it ary_sub_get_idx1stL IS OP ary sub - idxL of 1st item of sub in TOP level of ary only when full sub fits ary_sub_get_idxL IS OP ary sub - posnAL of sub within in ary, or faultL sub must be valence >= 1 (not an atom), and must match ary valence ary_sub_get_slcL IS OP ary sub - get slcL (hyperplanes) for sub in ary sub_idxUL_to_idxA IS OP sub idxUL - generate slice that specifies idxL for each itm of sub the slice is for a larger ary, so slice idxs can be greater than allowed by sub tbl_keyAxiTit_selAxiTitL_to_slc IS OP tbl keyAxiTit selAxiTitL - generate slice that specifies idxA for each itm of sub the slice is for a larger ary, so slice idxs can be greater than allowed by sub +-----+ split[Separate,[At[Front,End]], ] : 14Nov2021 - these optrs have NOT yet been upgraded from list basis to array these optrs return subs of ary, and don't have to apply slice-like! they do not leave non-existant "interior portions" of an ary, because splits do not remove content ary_itm_splits - aren't useful by the definition of an item - arys are already split by itms! ary_slc_get_frontEndSlcP IS OP ary slc - returns [i,j] for ary top level (ghost optr) for retrieval, slc is part of ary for [insert, delete] slc is location in ary before action ary_subL_getLenMatchesTo_subPL IS OP ary subL - return (ary = link subPairs) ary_slc_splitSeparate_subL IS OP ary slc - ary is split at slc, gives [front, slc part, end] or faultL slc must be FULLY specified (not a search) ary_sub_splitSeparate_subL IS OP ary sub - sub [splits ary, separate] 10May2022 WON'T WORK - part way through transition!!!! iteratively does each split, one Axs at a time using result on previous Axs split implicitly uses global g_AxsSplitL (default = 0) to be changed from default before calls? ary_subL_splitSeparate_subLL IS OP ary subL - recursively separate ary where sub occurs, sub separate ary_subP_splitSeparateTo_mididxs_subL IS OP ary subP - split ary, return [idxs, aryAst] ary_sub_splitAtFront_subL IS OP ary sub - splits ary at each point that sub occurs sub in aryAOut combined with next item ary_subL_splitAtFront_subL IS OP ary subL - iteratively split ary at each point that a sub of subL occurs ary_sub_splitAtEnd_subL IS OP ary sub - split ary where sub occurs, sub @end of each split ary_subL_splitAtEnd_subLL IS OP ary subL - iteratively split ary at each point that a sub of subL occurs ary_subP_splitReplace_subL IS OP ary subP - splits ary at each subOld, then replace subOld with subNew ary_subP_splitLftRgtTo_mididxs_subL IS OP ary subP - split ary, return [idxs, aryL] +-----+ cut [itm, slc, sub] - aryOut of different shape : ary_itm_cut_subL IS OP ary itm - cut ary at each itm, omitting itm, returns a array! ary_itm_cut_subWithNullsL IS OP ary itm - cut ary at each itm, omitting itm, nulls for multiple itms ary_itmL_cut_subLL IS OP ary itmL - cut a ary at each itm, omitting itm, returns a array! aryA_itmL_cut_subLLL IS OP aryA itmL - cut each aryA by all itmL, omitting itmL note that a character list is just a ary, but I use "itmL" to emphasize that each itm cuts ary_itmA_cut_subL IS OP ary itmA - cut each itmA, remainder of ary as LIST by order of occurence ary_width_cut_subL IS OP ary width - cut ary into subs of equal length broken on word boundaries ary_sub_cut_subL IS OP ary sub - splits ary at each point that sub occurs, omit sub note that bool values must be tru (l) for itms to be cut! (see bolL_opt_cull_lst) IF flag_break THEN BREAK ; ENDIF ; +-----+ get [itm, slc, sub] - aryOut of different shape : ary_itmP_get_sub ary itmP - generate indices to select a region of an array ary_itmPL_get_sub IS OP ary itmPL - select a region of an array ary_getBefore_sub IS OP ary sub - extract ary itms before sub, null if sub not in ary sub does not have to be a slice of ary ary_getAfter_sub IS OP ary sub - extract ary itms after sub, null if sub not in ary sub does not have to be a slice of ary ary_getBetween_slcP IS OP ary slcP - recursive? list from between slcPA, WRONG! - needs work items are ~= like a chr in a str, 14Nov2021 WRONG - need to fix ary_getBetween_subP IS OP ary subP - extracts subs between [lstStrt,lstEndr] screws up! - needs fixing... DUPLICATE OF ary_getBetween_subP? ary_getExSlc_itmL IS OP ary itmL - cut a ary at each itm, omitting itm, returns a array! aryA_getExcSlc_itmL IS OP aryA itmL - cut each aryA by including itmL, omitting non-itmL, ??lists only (not arys, maybe generalize to arrays (several years hence))?? note that a character list is just a ary, but I use "itmL" to emphasize that each itm cuts ary_getL_slc IS OP ary slc - get list of slc in order of occurence, drop other content for an itmL -> relative position information may be important in the result!! aryA_get_idxOdd IS OP aryA - useful for inclusion in a list of aryA for [terminal, file] output ary_slc_get_idxOdd IS OP ary slc - useful for [terminal, file] output ary_width_padItm_get_aryL IS OP ary width padItm - get fixed length (width) from start of str, pad end with padChr to make length if needed (padChr = [null] for no pad) +-----+ insert [itm, slc, sub] - aryOut of different shape : ary_sub_slc_insert_aryOut IS OP ary sub slc - insert sub into ary at index slc sub must be "[all-full-but-[one or none]]" of ary, matching slc index must add sub items if (shape sub < shape slc) aryA_slc_axs_insertBetweenThenLink_aryOut IS OP aryA slc axs - insert slc into aryA @ Axsidx slc must be a "full slice" of ary!!, subs are NOT adequate! aryA_sub_insertBetweenThenLink_aryOut IS OP aryA sub - link (insert sub between aryA items) +-----+ pad with slc - aryOut of different shape : if ary_length >= len, returns ary often used for zero-prepadding numbers to get constant ary length slc must be a "full slice" of ary!!, subs are NOT adequate! ary_slc_length_prepad_aryOut IS OP ary slc length - augment ary to length by prepadding with slc ary_slcL_length_prepad_aryOut IS OP ary slcL length - prepads ary with slcs to get length ary_itm_length_prepad_aryOut IS OP ary itm length - prepads ary with itms to get length ary_slc_length_postpad_aryOut IS OP ary slc length - postpads ary with slcs to get length ary_itm_length_postpad_aryOut IS OP ary itm length - postpads ary with itms to get length ary_sub_makeVlcSame IS OP sub ary - reshape sub to to satisfy isLayArySub reshape sub for further use defaults to axis ((gage shape sub) + 1,2,3...) in sequence as needed!!! +-----+ put [itm, slc, sub] - aryOut of SAME shape, replaces current (unknown) with [itm, slc, sub] (nothing yet) : +-----+ replace [itm, slc, sub] - aryOut of SAME shape : ary_itmP_put_aryOut IS OP ary itmP - put all itmOld by itmNew in ary ary_subP_put_aryOut IS OP ary subP - substitutes subNew for subOld in ary insert must be a full slice, not a lesser sub returns OR(aryNew, faultL) ary_subPL_putAll_aryOut IS OP ary subPL - lstOld is putd by lstNew in ary, for all ??21Nov2021 I'm lost!!) +-----+ [sort, cull] aryL - 02Dec2021 not converted from str to ary optr yet! aryA_sortupOn1st IS OP aryA - EACH sortup set of aryL based on first array aryA_sortupOn_col IS OP colNum aryA - EACH sortup set of aryL based on colNum aryA_sortupCullOn1st IS OP aryA - EACH [sortup,cull] set of aryL based on first array Cull QNial Definition - cull IS OPERATION A {­ grid A EACHLEFT in (A EACHLEFT find A) subarray A } strPL_sortCullUnique IS OP strPairL - sort, then cull to get a unique array of strPairs ordering matters : (str1 str2) ~= (str2 str1) aryPL_sortCullUnique IS OP strPairL - sort, then cull to get a unique array of strPairs ordering matters : (str1 str2) ~= (str2 str1) +-----+ cull [itm, option] ["hold, "cut, "get] : ary_itm_option_cull_aryOut IS OP ary itm option - cull ary with itm, according to option option "hold returns a linked ary, ["cut, "get] return a aryA ary_itmL_opt_cull_aryOut IS OP ary itmL option - cull ary with itmL, according to option option "hold returns a linked ary, ["cut, "get] return a aryA aryA_itmL_option_cull_aryOutL IS OP aryA itmL option - cut each aryA by all itmL, omitting itmL note that a character array is just a ary, but I use "itmL" to emphasize that each itm cuts +-----+ Tables, titles - tables are 2D arys with [row, col] titles can't use characters as titles! use one-char phrases instead especially useful for symbol tablesd - reduce # of global variables and "cross-over" problems assumes [row, col]TitL itms are unique all 'get_subTbl' optrs retain titles (eg for 2D : col 0, row 0) 27Aug2022 PROBLEM at present : only handles 2D tables, should be generalised!! should actually use ary optrs for much of this (conceptually open the vista & vision) 03Mar2024 pTblHtm_transform_pTblHtmOut - transform (axis) of html table, see file_ops.ndf nCols_labldDat_make_tbl IS OP nCols labldDat - res ipsa loqitor don't remember what labldDat was (from loaddef of something?) tbl_get_titLL IS 0 pick - trivial expression that "hides" structure, allows flexibility tbl_get_tblDat IS 1 pick - trivial expression that "hides" structure, allows flexibility tbl_get_tblDat_titLL IS pass - trivial expression that "hides" structure, allows flexibility normally, just use tblDat titLL := tbl tbl_keyAxiTit_selAxiTitL_get_itmLL IS OP tbl keyAxiTit selAxiTitL - keyTit=null selects ALL itms in selAxiTitL as yet unknown implications of non-[key, sel] axis (included, but), will have to think about it... tbl_keyAxiTit_selAxiTitL_put_itmLL IS OP tbl keyAxiTit selAxiTitL - returns updated tbl keyTit=null selects ALL itms in selAxiTitL tbl_axiIdxL_keyL_get_subTbl IS OP tbl axiIdxL keyL - returns a subTbl of key-selected cols as [row, col]TitL will be more common, this simply calls tbl_[row, col]TitL_key_get_subTbl tbl_titLL_get_sub IS OP tbl titLL keyL - returns subTbl from titLL, then with key in axiIdxHyperPlane assumes that tbl_titLL_check has been run, so data is consistent titL=null (part of titLL) retains all axiIdxs for that axis remember : [row, col]TitL are LISTS, if only one returned it is in form of a solitary tbl_keyTitLL_keyItmL_get_adrL IS OP tbl keyTitLL keyItmL - returns an idxLL of keyItmL hits assumes that args are consistent - use _chk to ensure this!! (keyTitL = null) returns ALL idxs of key in tbl, keyTit (for any axis) ignores that axis make sure that single-arg [keyTitLL, keyItmL] are solitaries (protect [str, ary, list, etc] titles) tbl_keyTitLL_keyItmL_get_sub IS OP tbl keyTitLL keyItmL - returns a subTbl showing only hyperPlanes for keyItmL hits assumes that args are consistent - use _chk to ensure this!! make sure that single-arg [keyTitLL, keyItmL] are solitaries (protect [str, ary, list, etc] titles) tbl_make_tblWhole IS OP tbl - human-readable table output, 2D tblWholes ONLY! tbl_writeParts IS OP tbl - res ipsa loqitor tbl_writeSolPassCells IS OP tbl - output table with cells of [solitary, pass] value tblDat_titLL_make_tbl IS OP tblDat titLL - trivial error checks : see tblDat_titLL_compatible in "$d_Qndfs"'types.ndf' tblWhole_make_tbl IS OP tbl - trivial split whole (unified for output) tbl into 2 parts +-----+ tabHtm - html formatted tables tblQNial_put_tblHtmOut IS OP tblInn tblHtmOut - convert QNial table to html format tblHtmInn_transform_tblHtmOut IS OP tblHtmInn tblHtmOut - transform (axis) of html table tblHtmInn must be in standard format, contain only ONE htmTbl +-----+ Database queries (sort of), see also tables - previous section QNial roster database model : "$d_Qroot"'Qnial_bag/aitools/roster/' ary_posnACommon1stItmIdxL IS OP ary - finds indexs of common items in an ary (by defn TOP level) aryL_keyLIdx_cullSort IS OP aryL keyLIdx - returns arrayList, sorted by common-keys, as per keyLIdx aryL_extractMulplicate_subArys IS OP selectOp aryList - find mulplicates in aryN by selectOp actually, should work with any array type (in form of list), including aryNs 29May2021 - no good for general use, use aryL_keyLIdx_cullSort +-----+ transformers - QNial TRANSFORMERs, as well as "generalised transformer" (OPERATORs) aryInn_putWith_aryOut IS OP aryInn aryOut - useful for "general transformers" (optrs with optrPhrs) I was thinking of replacing [atom, str]s in nested arys at the time ... normally just use aryOut := aryInn, which won't help in transformers opPhr_ary_LEAFputWith_aryStatic IS OP optrPhr ary aryStatic - LEAF_aryInn_aryStatic IS TRANSFORMER f OPERATION aryInnStaticPair - 24************************24 +-----+ ToDos 21Apr2022 should ary_sub_get_idx1stL faults be returned as a list to be constent with other optrs? (NO! - cannot rely on solitary lists, use ary_hasFaults) 01Sep2022 for valence > 2, the [row, col] title concept implies separate lists optrs should be redesigned for this - more efficient too +-----+ Warnings and notes xxx_chkFor_ary_apply_optrPhr forces proper [idx, sub] valence (not for itm) provides error-tracking faults then it checks [idx,itm,sub] compatibility with ary default axis augmentation (if necessary) is to higher dimensions where n_axisAdd := - EACH valence ary sub : gage shape resFltL := link (gage shape ary) ((gage shape sub) link (n_AxisAdd reshape 1)) faultL if [not found, other reasons], 10Apr2022 actually returns null if not found (should be fault?) As QNial is an array-oriented language, it has extremely powerful built-in capabilities. This obviates most of the need for [chr, str, lst, tbl, etc]-specific optrs. It is best to learn to work in as [high a dimension, deep a nesting] as practical (or won't learn) My work below comprises very simple arrangements for simple tasks, with some built-in checks. www.BillHowell.ca 14Apr2020 initial some Howell optrs date from late 1980's? 2014-15 'matrix operations - symbolic & real-valued.ndf' Apr2022 [posn, slice, etc] optrs below, although I did earlier stuff too, nomenclature ripped up! 11Feb2022 many operatornew and not well defined, or just ghosts, ds much more [work, test]s view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap see "$d_Qndfs"'arrays atomic.ndf' "$d_Qndfs"'array notes.txt' "$d_Qtest"'array- tests.ndf' "$d_Qtest"'array- test results log.txt" "$d_Qndfs"'types.ndf' slc - "[all-full-but-[one or none]]" INDEX of an array sub - is a sequence of items at the top level of an array, note that a sub can span [one, more, all] Axs not much use for a separate subSlc of an array - just use sub optrs [cut, put] - require slc of an array, often built from search for a subAry, put something in non-sub parts of slc split - requires a hyper-plane index as a specific place to split ary