| Furniture : fns to flesh out the living area .
| Require CoSy APL object vocabulary . 
| Do NOT require R dictionary obs 
| Author: Bob Armstrong / www.CoSy.com
| Reva's license terms also apply to this file.

cr ." | Furniture begin | "

| \/ | MISC UTILS |\/|

: str>pad_ ( str -- a n ) { pad place } onvan pad count ;
| Move string < 1024 bytes to pad and free if ref count 0 . 


: dae ( v -- v ) >aux+> dup ['] rho 'm ,/ i0 <>i & at\ aux- ; 
| Delete All Empties . Deletes all empty , items of a list . 
| translated from K | { x @ & 0 < #:' x } |

: VM toksplt ; | was bad idea deleted 20201223.0025  | 20200826 | added ' dae  because bunch of words don't like empties .
 
|  name from APL " Vector to Matrix "  | updated to call ' VM rather than ' toksplt
: blVM "bl VM ; 
 
: nlVM ( str -- list_of_strings_split_on_crlf ) "nl VM ;
|   Vector to Matrix on "newlines" . 
 
: lfVM ( str -- list_of_strings_split_on_cr ) "lf VM ;

: htVM ( str -- list_of_strings_split_on_tab ) "ht VM ; 

| Matrix to Vector . Ravels , eg : lists of strings LA inserting token RA
| , eg : "bl or "lf , as a delimiter | in K | { ( # x ) _ ,/ x ,/: y }
: MV over Type@ 0if  2p R@ L@ ['] cL 'R  ,/ R@ rho cut 2P>  ;then drop ;
| Just returns simples so no bomb | 20190510 |
 
: lfMV "lf MV ;   : nlMV "nl MV ;   : blMV "bl MV ; 	| for symmetry w VM fns

: #' : rho' ['] rho 'm ;  | rho on each item of list . for convenience | #' 20200704

: `_ p: ` "bl cL ;  | append blank to make true blank delimited word .
: `__ p: ` "bl cL "bl swap cL ;  | append leading and trailing blanks | 20200621

: match0th 1p> dup dsc ' match 'L ,/ 1P> ; 
| bool of items of a list matching the first . 	| 20211026
 
: all= match0th ' mini ./ ;
| are all items in a list identical 		| 20211026


: idxs 1p> dsc R@ 1 _at iota +i 1P> ; | ( i ( first count )i -- v ) | 20200628 |
 
: thru ( LA RA -- IV )		| vector of integers from LA thru RA .
   2p> swap -i 1+i iota L@ +i 2P> ;
  | was til 20141221.2349 | 2dup swap -i _iota nip swap _i ['] + each ; 
 
: apvi ( start increment n -- a ) iota *i +i ;
	| IBM's Arithmetic Progression Vector . Affine transform of  iota n .
 
: _apv _i : apv ( start increment  n -- a ) iotaf *f +f ; | floating 


| |/\| MISC UTILS |/\|

| |\/| FILE & OS FNS |\/| with CoSy args
| since  ' s"  was changed to not escape ` \ , some of these conversions are
| not needed as much .
| Note that while MS doesn't care about case , F> in particular does .

| convert all / to \ |	| 20190415
: />\  s" /" s" \" ,L ssr ; 	| probably what you want vs dosslash^ 
| 20180815 | corrected for change in ' s" 

: \>/ ` \ ` / ,L ssr ; 	| replaces DOS \ w RoW / .

: lf>nl "lf "nl ,L ssr ; 	| convert UNIX "lf line breaks to DOS "nl 
 				| changed names from "lf>"nl | 20190518
: lf>bl "lf "bl ,L ssr ; | find myself wanting to string out results | 20200804
: nl>lf "nl "lf ,L ssr ; 	| convert DOS "lf line breaks to UNIX "n| 
| Use to convert ' res> result for saving as CoSy source file .

: include^ ( fname -- flag ) { (include) ioerr @ _i } onvan ; | returns 0 on success

: Fcreate ( fn -- fileid ) dup van fcreate ref0del ; 
 
: Fwrite ( dat fn -- )  over van --abca van foc >r> write r> close 2ref0del ;
 

| \/ | THESE ARE THE MAIN FILE R<>W VERBS | \/ |
: >F : Foverwrite ( str flnm ) over van --abca van foverwrite  2ref0del ;
 
: F> ( str -- str ) >r> van slurp r> ref0del
	--aab str swap nakedfree ;
| Like "slurp" but takes and returns CoSy strings and frees original .
| /\ |                                    | /\ |

: Fbackup >a>  F> a> ` .bk cL >F ; 	| 20211227 | self explanatory

  
: Shell : shell^ ( str -- str ) dup van shell ref0del ; | 20200827 | updated name . deprecating old 
 
: Shell> : shell> ( str -- str ) dup van shell$ --aab str swap free swap ref0del ;
    | executes str in OS returns any output . 
	| need to double \\ in strings since \ is the escape for \" .
	| see also ` dosslash^  

: fullPaths s" |" VM >a> dsc s" /" cL a> 1 _cut ' cL 'R ; | 20200916 |
| flesh out full paths of multiple file selections from ' filedialog | 20190918 

: Dir ( path -- dir ) s" dir " swap cL shell> ; |  trumps Reva ~os dir | 20190704
| 20201201 | changed name to cap to make consistant w being CoSy level
: cd s" cd " shell> -1 _cut ; 	| current directory 
 
: start s" start C:\\Windows\\System32\\cmd.exe /k " swap cL shell^ ; 
| start DOS program in separate persistant ( keep ) command shell  . 


| ( filename -- ) makes new ` Job by cloning ` C:/4thCoSy/CoSy/MinJob.csy | 20211215
| : newJob> ..
 : newJob ` C:/4thCoSy/CoSy/MinJob.csy F> $ >F ;
| Currently name must end in ` .csy 
 
: startJob s" cosy@.bat " swap cL  start ; | 20200108 |
| Start a ` .csy Job | eg: | ` C:\CoSyBob\acnts\y20\Acnts.csy StartJob
| : startJobk s" cosy@.bat " swap cL  startk ;  | ` keep version | 20200603 |

| |/\| FILE & OS FNS |/\| with CoSy args


| s" C:/4thCoSy/lib/alg/hsort" include^ >_ $.s if z" load fail : hsort " throw then
| s" C:/4thCoSy/lib/helper" include^ >_ if z" load fail helper " throw then

: www ( str -- ) ` .\CoSy\BROWSER.txt F> "bl cL $ cL shell^ ;
| open URL in BROWSER  . .\CoSy\BROWSER.txt must be string to open browser .
| Changed from  vestigial   R s" BROWSER" v@  to centralize 20211031.1053

| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 

| \/ \/ \/ Stack made with CoSy obs \/ \/ \/ |  never been used | 20201226 | commented out
| ev refs+> variable, stk			| set stk to an empty vector 
| 
| : p ( obj -- ) stk @ cL  stk rplc ;		| push 
| 
| : P ( -- obj ) stk @			| pop
|   dup i# 0if drop ev refs+> ;then		| if empty return empty
|   dup dsc  swap i1 _   stk rplc  dup refs-ok ;
| 
| /\ /\ /\ Stack made with CoSy obs /\ /\ /\ |

| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ \/ \/ |  REF COUNT CHECKING  | \/ \/ \/ |

| These fns are useful for checking that created obs get collected .
| Useful phases are included in  ` state .
 
  0 _i 64 K* _take refs+> value AFbuf
variable AFptr 
 
: AFbufON ( -- ) 
	| note not modulo . subject to overflow . 
 { dup AFbuf vbody AFptr @>+! c+ ! } >defer AT+>
 { negate AT+> negate } >defer FT+> ;  | - adr  for freeing
 
: AFbufOFF ( -- ) undo AT+>  undo FT+> ;
 
: AF1 AFptr off  AFbufON ; 	: AF0 AFbufOFF ; 	: AF> AFbuf AFptr @ _take ; 
 
| /\ /\ /\ |  REF COUNT CHECKING  | /\ /\ /\ |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |

| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ \/ | Time Fns | \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ |
 
: ymd.hms_ time&date _ymd.hms_ ;  : ymd.hms ymd.hms_ str ; 
| : |ymd.hms| ymd.hms s" |" braket ; : |ymd.hms|_ |ymd.hms| str>pad_ ;
 
: _ymdhms _ymdhms_ str ;      : ymd.hm ymd.hm_ str ;
: ymdhms ( -- yyyymmdd.hhmmss ( string ) time&date _ymdhms ; 
 
: ymdhm ( -- yyyymmdd.hhmm ) ymdhm_ str ;
: |ymd.hm| ymd.hm s" | " s"  | " ,L braket ; : |ymd.hm|_ |ymd.hm| str>pad_ ;

| \/ Calendar \/ | 

: Monthnms 12 _iota { >_ monthname _str } 'm ;  | 3 ltr month names | 20200303 

: m/d/y>ymd s" /" VM -1 _rotate ,/ ; | convert format . requires leading 0s .

: m/d/y>ts ` / "bl ,L ssr Eval --bac dtpk _i ;  | 20200315 | convert datestamp

| Converting  ' daysdif  used to compute days of my life to take CoSy dates
: date_ ( yyyymmdd _i -- d m y ) >r> vbody @ dtupk r> ref0del ;
: Daysdif >r date_ r> date_ daysdif _i ; 	
| 20171112 | | 20200226 | changed name from daysdif^
  
| ( dates days -- dates ) adds number of days to dates . | 20200225 | for Don Silberger's 90th .
: Days+ { >_ swap date_ date>fixed + fixed>date dtpk _i } 'd ; 

 "lf |=| _str "bl braket cL refs+> value daylnTok 	| 20201210 |

: Dayln ( int -- dayln )  date_ _DMymd _str daylnTok 1 _cut enc braket ;

| ( yyyymmdd n -- ) | outputs daylines for begining date + n days . 
: Daylns >a date_ date>fixed _i a> iota +i { >_ fixed>date dayln _str } 'm lfMV ; 
| eg : | 20210517 10 2_i Daylns | 20210515 |	| 

: Today _date dtpk _i ; 	| 2021052 |
 
| Cut text into day entries ( approximate as can be seen from def . )

: daylncut ( str -- listOFstrings ) daylnTok tokcut ;

: daylnDS s" | " VM 2 _at ; | return DayStamp from ' dayln entry |
|  Thu.May,20190530 

| : dt time&date 6 s>iv ;
 
: daylns ( d m y n -- ) | outputs daylines for begining date + n days . 
 >r date>fixed _i r> _iota +i { fixed>date dayln type cr } eachM ;
| >r date>fixed _i r> _iota ['] +i aaply { fixed>date dayln type cr } eachM ;
 
: daily 10. _f %f f>i ; 	| converts floating timestamp to int day  
: monthly 100. _f %f f>i ; 	| converts floating timestamp to int month | 20190929


0 [IF]
: _jd ( v_yyyymmdd -- v_julian ) | same as K _jd except 00010101 is 1 instead of 20350101 -> 0 .  
[THEN]
 
| /\ /\ | Time Fns | /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 

| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ \/ | partitioned string & parsing fns | \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ |

| Convert character vec ( byte to integer ) | 20191208
: c>i 1p> i# intVecInit >aux R@ { aux@ ii i! } eachM 1P aux> ;

|  dup Type@ TypeC <>if ref0del z" must be character " throw ;then
|  dup i# intVecInit >aux> 0 ?do dup i ib@ aux@ i ii! loop ref0del aux> ;
 
| Convert integer to character vec . 
: i>c ( iv -- cv ) dup Type@ TypeI <>if ref0del z" must be integer " throw ;then
  dup i# byteVecInit >aux> i# 0 ?do dup i ii@ aux@ i ib! loop ref0del aux> ;
| fixed missing ' i#  20180629 | absurdly slow for some reason . 180218

: strCmpr ( s0 s1 -- -0+ ) | returns -1 if s0 < s1 , 0 if identical up to length of shorter , 1 if s0 > s1
  2p> i#i# min 
   0do L@ i i@ R@ i i@ >sn ?dup if _i 2P> unloop ;then loop 2P i0 ; 

 "nl "nl cL refs+> value emptyLn
 | MS-DOS definition of blank line . must be changed for UNIX \n

| Mask of ` quoted portions of strings . single symmetric delimiter | 20200202
| given bool of occurrences of delimiter , eg: | str ` " =c | returns bool covering quoted sections 
: qmsk I>M ['] <> scanI 0<i >a> 1 1 2 s>iv { *i ['] maxi ./ >_ } convo a> dsc swap cL ;
: "msk ` " =c qmsk ; 


: wsf?  { 33 < } f?m ; 	| index of first whitespace | 20210727 |

: WSb ( str -- bool_of_WhiteSpace ) 33 _i ' <i  'L  ,/ ; | 20200602 |
  
: WScut ( str -- list_of_strings_split_on_WhiteSpace ) dup WSb & cut ;

: WStable ( str -- table ) ev temp ! 
   lfVM { WScut enc temp @ swap cL temp ! } eachM temp @ ;
|  converts string containing table , eg read off browser screen , to CoSy
| list of lists splitting rows on "cr"s and columns on any white space .

| ( str -- str ) Delete Redundant ( all but first of sequences of )
|  blanks  in string  y 	| 20190325 | fixed 20190411 | really fixed 20191015
| 20200103 | really really honest to goodness fixxed it . Needed to trim bool 
: drb "bl : dre 2p> swap cL R@ =c >a> 1 _rotate a> mini -1 _cut 0=i & L@ swap at 2P> ;

: inb ( lst tok -- lst ) 2p> rho { take R@ match } 'L ,/ 2P> ;
| bool of lines starting w tok | see 20180729
 
: in 2p> --aab inb & at 2P> ;
| lines starting w tok 
 
: ninb inb 0=i ;
: nin 2p> --aab ninb & at 2P> ;
| the obvious complements 

| delete leading blanks . 20190430  | factored 20200104 |
: dlc >_ >aux 1p> dup { aux@ <> } f?m cut auxdrop 1P> ; 
: dlb "bl dlc ; 	| delete leading blank 
: dl, ` , dlc ; 	|  " comma . forced by lack of recursive { } | 20200421
: dtc >aux reverse aux> dlc reverse ;
: dtb reverse dlb reverse ; 	| delete trailing blanks  | 20190608 
| see also 20190713
: dlws 1p> dup { 32 > } f?m cut 1P> ; 	| Delete leading white space 
 
: trim ( str chr -- drop_last_if ) swap >a> -1 _at =c >_ a> swap if -1 _cut then ;
| delete last char if match | 20190713 | . fixed 20191201 |

: fmt ['] lst spool "lf trim ; 	| capture output of ' lst . 20180602
| moved here & added "lf trim | 20190821 | 

| 20190203 | \/ | vocabulary found useful over the years | \/ |
: prt<f ( str tok -- PaRT_Before_First ) 2p> ss1st L@ swap take 2P> ;
: prt<=f ( str tok -- PaRT_Before_Firstincluding )
   2p> ss1st R@ rho +i L@ swap take 2P> ;
: prt>=l 2p> ['] reverse on2 prt<=f reverse  2P> ; 
: prt>l 2p> ['] reverse on2 prt<f reverse  2P> ;

: prt>f  2p> ss1st R@ rho +i L@ swap cut 2P> ;
: prt>=f 2p> ss1st L@ swap cut 2P> ;
: prt<=l 2p> ['] reverse on2 prt>=f reverse  2P> ; 
: prt<l 2p> ['] reverse on2 prt>f reverse  2P> ;
| /\ |

: braketed ( str tok0 tok1 ,L -- str ) 2p> dsc prt>f R@ 1 _at prt<l 2P> ;
| portion of string between two token strings . 
 
: +braketed+ ( str tok0 tok1 ,L -- str ) 2p> dsc prt>=f R@ 1 _at prt<=l 2P> ;
| portion of string between but including two token strings . eg :
|   s" Gilgamesh Athorya <e9gille@hmail.com>," s" <" s" >" ,L braketed
| <e9gille@hmail.com> 


: wrapidxs ( dlimidxs len -- wraps ) 2p> --aab modi ' - _delta 0<i & at 2P> ;
| Given list of delimiter locations , eg: | str "bl ss | and desired wrap length .
| see 20210107 for more | http://cosy.com/y21/Wed.Jan,20210113.html#4th.CoSy

: blpad { "bl cL } 'm ;	| pad each item ( str ) w blank | 20200528 |

: ?pad 2p> # -1*i take R@ strmatch_ if L@ 2P> ;then L@ R@ cL 2P> ;                                          
| ( str suffix -- str ) append suffix , eg: "bl , iff not already suffixed . 
|  ` asdf ` q ?pad |>| asdfq 	|  ` asdf ` f ?pad |>| asdf 	| 20210719.2309 |
| /\ \/ need to be fixed for empty lines  | 20210727 |
: bl?pad { "bl ?pad } 'm ;	| pad each item ( str ) w blank if not already | 
 
: pad 1p> dup rho' ,/ ' maxi ./ ' fill 'L 1P> ; | pad each str to length of longest
 
| format table , list of columns , w space btwn each col 
: fmttbl >r { ' fmt 'm blpad pad } 'm flip  r> ' MV 'L ; 	| 20210621.2131 |
: fmttblh "ht fmttbl ; 
: fmttblb "bl fmttbl ; 
: fmttbl| s"  | " fmttbl ; 	| invert w s" | " .
 
 
: fmtDT >a> dsc a> 1 _at { cL enc } 'd fmttblh ; 	| 20210330 | 20210621 |
| format DictionaryTable | (' labels values ') 

: NmEm><@> >a> dsc "bl cL  a> 1th ` <> braket cL ; 	| 20210601 |
| Name Email pair ->  name <@> string 
 
: <@> { ` > prt<=f ` < prt>=l } 'm ; | picks out ( first ) email addresses in list | 20201127 |

| /\ /\ | partitioned string fns | /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 

| Convert hm timestamp , eg:  1537  to minutes | 20211128
: hm>min 2 2 2 s>iv take blMV iEval 60 1 2 s>iv *i +/ ; 

| convert list of clock ON OFF times , eg:  | 1058 |* *| 1130 | | 1227 |* *| 1348 | 
| to elapsed ON minutes | 20211128  
: ONtimes "bl braket s"  | " VM dae { ` * ssd ` | ssd drb blVM ' hm>min 'm ,/ ' -i ./ } 'm ;


| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ | DictionaryTable > < .csv text | ~\/~\/~\/~\/~\/~\/~\/~\/~\/~\/~ |

| I've used the term , abbreviated ' DT , in K.CoSy with a rather substantial
| vocabulary . It is the fundamental form of a Kdb columnar data base . 
| A DT is a Dictionary whose first item is a list of column labels and second is 
| a corresponding set of correlated lists of values . This vocabulary converts
| back and forth between CoSy DTs and standard .CSV strings , the most 
| universal format for bank ledger downloads . See 20171212 .
 
: csv>lst ( csv d0,d1 -- lst ) 2p> dsc VM dae R@ 1 _at ['] VM 'L 2P> ;
| Splits string first on d0 then each on d1 .
| Example |  t1  "nl "ht ,L  csv>lst
| see also 20180719 
: lst>DT ( lst -- DT ) 1p> dsc R@ 1 _cut flip ,L 1P> ; 
: csv>DT ( csv d0,d1 -- DT ) csv>lst lst>DT ;

| Splits each of list of strings on commas which are not in quotes 
: ,svMsk >a> "msk 0=i a> ` , =c mini ;  | mask of commas not in quotes | 20200421 |
: ,sv>lst { >a> dup ,svMsk & 0cut ' dl, 'm a- } 'm  ; 
 
| \/ | Example | \/ | 
| s" C:/CoSy/acnts/y17/CHK.CSV" F> >T0> -2 _take c>i 	|>| 13 10
|  read in and check if line delimiter is "lf or "cr "lf , ie: "nl 
| which is generally the trailing element .  Win uses "nl . most others "lf
 
| T0 "nl "ht ,L csv>DT >T1 	| splits on "nl then each on "ht 
|  | Note the combining of the line and item delimiters by ' ,L 
 
| And the inverse 
: DT>lst 1p> dsc enc R@ 1 _at flip cL 1P> ; 
: lst>csv ( lst d0,d1 -- csv ) 2p> dsc ['] MV 'L R@ 1 _at MV 2P> ; 
: DT>csv ( DT d1,d0 -- csv ) 2p> --aba dnames swap MV 2P> ;
 
|  | Note that the delimiters have to be reversed . 
| T1 "nl "ht ,L reverse DT>csv 
 
| related | 20191006 |
| executes lists of lines which produce lists , eg: ledger lists w lines like
|  (' 20190825.1322 _f ` lilBarn ` cash 200. _f  s" Nate " ')  
| and flips them into column form 
: str>tbl ( strlst -- table ) dae ['] ^eval 'm flip ;

| splits lst of strs , eg: dirs , on white space | 20191009 | 20191019 |
: blTbl dup Type@ TypeC =if lfVM then { drb blVM } 'm flip ; 


| /\ | DictionaryTable > < .csv text | \~/\~/\~/\~/\~/\~/\~/\~/\~/\~/\ |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ \/ | miscellaneous fns | \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ |


: forth> ( str -- str ) { ['] eval spool } onvan ; 
 | evaluates str spooling and returning output . | 20160605.1138

: _dasm ( adr n -- str ) cL fmtI "bl MV s"  disassemble " cL forth> ;
| ' disassemble raised CoSy level .  n is number of cells to be disassembled . 

| : _DMP> ( addr -- str ) s"  DMP " forth> ; | returns ' DMP as str
| ' _DMP> is useless as is | 20201123.1843 | Lousy name too

: Words ( str -- strL ) s" words " swap cL forth> blVM -2 _i cut ;
| see   s" help words" forth> | use "bl arg all words | renamed 20190529

: Xwords s" xwords " forth> "lf 2 _take toksplt dae
   { "lf toksplt 2 _take } 'm  ;
| all words in all contexts. returned  | renamed 20190529

: Allwords  Xwords flip 1th ,/ blVM dae ; 	| Simple list of all words in all contexts . 20220507 

| Reva help on Reva word returned as CoSy string | 20190225 
: Help ( word -- Reva_help_on_Reva_word ) s" help " swap cL forth> ;

| x86 assembler code of word .
: See ( word -- assembler_code ) s" see " swap cL forth> ;

: .needs> ['] .needs spool blVM i-1  _ dsc ;

: ^!! ( str -- ) dup van shell ref0del ;	| CS version of !! shell execute .

: ilst ( RA -- indexed_list ) | appends index to list and flips  
	1p> rho iota R@ ,L flip 1P> ;

| /\ /\ | miscellaneous fns | /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
| \/ \/ \/ MOST MIMIMAL MATH \/ \/ \/ | 

| Set & see significant digits variable used by formatting fns . 20180702 
: _>sigdig _i : >sigdig >_ sigdig ! ; 	: sigdig> sigdig @ _i ; 

: Pi fpi _f ;

: PoT 1p R@ R@ +/ %f 1P> ; | Proportion of Total . I find very useful 

: 2sComp i1 +i i-1 *i ; 	| useful for indexing from end   
|  s" Hello World " 12 _iota 2sComp at |>|  dlroW olleH | 20180724

: c>f ( fv -- fv )  1.8 _f *f 32. _f +f ; 	| centigrade to farenheit | 20141124 
: f>c ( fv -- fv )  32. _f -f 1.8 _f %f ; 	| farenheit to centigrade | 20141124 

 | ======================================== |

| Split integer vec into positives and negatives 
: +-splt ( iv -- v ) 1p> i-1 >i refs+> >r> & R@ swap at 
	R@ r@ 0=i & at ,L r> refs- 1P> ; 

| see also | math.f |
| /\ /\ /\ |  MATH  | /\ /\ /\ |

|  : ref " notepad \\cosy\\ref.txt" shell ;

| : $^  ( sym -- ) | display var in  res 
|	dup+ " source" (sym)  R " res" (sym)  ;

| \/ | ARK | \/ |

| `( Type0 TypeC TypeI TypeFl TypeS TypeV TypeA TypeFv )` dup+
|  { van eval _i } eachM> ' cL across  over refs-ok  cL  R ` Types v!

." | Furniture end | " cr