On Tuesday, July 25, 2023 at 11:17:18 AM UTC+2, none albert wrote:
[..]
> A tool can make into my library if it has been (!) used more
> than 3 times, and occupies at most 3 screens.
>
> $@ $! $+! $C+ fits in one screen and it doesn't burden the
> memory. With $^ find-char-position $/ slash-from-the-front
> and $\ slash-from-the back I happily analyse the comma separated
> transaction lists from my bank for my taxes.
I've noticed that there are words one doesn't miss unless one sees
other use it. Here's a small selection from iForth's miscutil.frt .
In the process of writing iSPICE I needed many other string/parsing
words, but these are still in purgatory.
:ABOUT
??CR ." -- low-precision timing --"
CR ." TIMER-RESET \ ( -- )"
CR ." TIMER-PRESET \ ( u -- ) offset for .elapsed"
CR ." ?MS \ ( -- u ) ms since machine turned on"
CR ." MS? \ ( -- u ) ms since TIMER-RESET"
CR ." .ELAPSED \ ( -- ) prints number of ms since last TIMER-RESET"
CR
CR ." -- high-precision timing --"
CR ." USE-TSC-TIMER \ ( flag -- ) when true use TSC for the TICKS-GET, otherwise the system clock"
CR ." .TICKER-INFO \ ( -- ) gives information about the current TICKS-GET mode"
CR ." PROCESSOR-CLOCK \ ( -- mhz )
CR ." TICKS-INITED? \ ( -- TRUE=inited )"
CR ." CALIBRATE \ ( -- ) compute processor-clock"
CR ." RECALIBRATE \ ( -- ) recompute processor-clock"
CR ." TICKS-RESET \ ( -- )"
CR ." TICKS-GET \ ( -- ud ) ticks since machine turned on"
CR ." TICKS? \ ( -- ud ) ticks since TICKS-RESET"
CR ." TICKS>US \ ( ud -- ud ) convert to microseconds"
CR ." TICKS>MS \ ( ud -- u ) convert to milliseconds"
CR ." US? \ ( -- ud ) microseconds since last TICKS-RESET"
CR ." DTICKS-RESET \ ( -- )"
CR ." [TICKS \ ( -- )"
CR ." TICKS] \ ( -- ) accumulates ticks since [TICKS"
CR ." D-US? \ ( -- ud ) us since last DTICKS-RESET"
CR .~ .TICKS" \ ( <text>" -- ) time in clock ticks"
\ CR ." PMC@ \ ( u -- ud ) read performance monitor u (0|1)"
CR
CR ." -- formatting --"
CR ." ((n,3)) \ ( ud -- caddr u )"
CR ." (n,3) \ ( ud -- )"
CR ." ((.KB)) \ ( ud -- caddr u )"
CR ." (.KB) \ ( ud -- )"
CR ." .KB \ ( u -- ) prints 12345678 as 12,345.678"
CR ." .MB \ ( u -- ) prints 12345678 as 12.345"
CR ." .MSECS \ ( ud -- )"
CR ." .BOOL \ ( bool -- ) Type 'yes' or 'no' "
CR
CR ." BETWEEN \ ( n low high -- bool ) like WITHIN but inclusive
CR ." ENUM \ definer; ( init -- ) ENUM name: then use name: red name: blue etc."
CR ." 2^x \ ( x -- 2^x )"
CR ." SQRT \ ( u1 -- u2 )"
CR ." SQR \ ( u1 -- u2 )"
CR ." DSQRT \ ( ud -- u )"
CR ." LOG2 \ ( u -- hi_bit# | -1 )"
CR ." #BITS \ ( u -- #bits )"
CR ." LOWEST-BIT \ ( u -- lo_bit# | -1 )"
CR ." POWER-OF-2? \ ( u -- bool )"
CR ." 16B->S \ ( 16b -- n ) sign-extend a character/word"
CR ." DXOR \ ( d1 d2 -- d1^d2 )"
CR ." DAND \ ( d1 d2 -- d1&d2 )"
CR ." DOR \ ( d1 d2 -- d1|d2 )"
CR ." DINVERT \ ( d -- ~d )"
CR ." RANDOMIZE \ ( -- ) (Re)initialize random number generator"
CR ." RANDOM \ ( -- u ) Fairly random number (integer)"
CR ." CHOOSE \ ( n -- u ) 0 <= u < n pick random number from range"
CR ." FRANDOM \ ( F: -- r ) Random floating-point number < 2^31"
CR ." FCHOOSE \ ( n -- ) ( F: -- ur ) 0 <= ur < r pick random number from range"
CR ." FPREM \ ( F: r1 r2 -- rem[r1/r2] ) take FP remainder"
CR ." FP/REM \ ( F: r1 r2 -- rem[r1/r2] ) ( -- div[r1/r2] ) take FP remainder and quotient"
CR ." NOW? \ ( cfa -- ) Compile if compiling, else execute"
CR ." DEFER \ (compile) DEFER #<vector># define a vectored word"
CR ." \ (execute) #<vector># -- <addr>
CR ." IS [IS] \ ' <exectoken> IS #<vector># setup vector"
CR ." IS? [IS?] \ ( -- xt ) usage: vector IS?"
CR ." 32B, 16B, \ ( n -- ) comma 32 and 16-bit numbers without aligning"
CR ." F#80 \ text is ignored if package is not extended precision"
CR ." F#64 \ text is ignored if package is not double precision"
CR ." F#32 \ text is ignored if package is not single precision"
CR ." +E.R \ ( fieldwidth> -- ) ( F: r -- ) print in field"
CR ." +E. \ ( -- ) ( F: r -- ) print in default field"
CR ." (F.N1) \ ( -- c-addr u ) ( F: r -- ) format in engineering notation"
CR ." F.N1 \ ( F: r -- ) print in engineering notation with trailing space"
CR ." (F.N2) \ ( -- c-addr u ) ( F: r -- ) format in engineering notation, no space"
CR ." F.N2 \ ( F: r -- ) print in engineering notation, no space"
CR ." FDUMP \ ( a-addr +n -- ) print +n floats from a-addr"
CR ." DFDUMP \ ( a-addr +n -- ) print +n dfloats from a-addr"
CR ." SFDUMP \ ( a-addr +n -- ) print +n sfloats from a-addr"
CR ." F>SR \ ( F: r -- ) ( -- r ) rounding version of F>S"
CR ." SOURCELINE# \ ( -- +n )"
CR ." SOURCEFILENAME \ ( -- c-addr u )"
CR ." EXEC: .. EXEC; \ ( index -- ? ) EXEC: in-line jump (call) table"
CR ." BIT? \ ( base bit# -- ? ) test a bit"
CR ." -BIT? \ ( base bit# -- bit# ? ) test a bit"
CR ." BIT-RESET \ ( base bit# -- ) reset a bit"
CR ." BIT-SET \ ( base bit# -- ) set a bit"
CR ." BIT-FLIP \ ( base bit# -- ) flip a bit"
CR ." NETWORK@ \ ( -- ) what's my ID, with how many are we?"
CR ." ?FILE \ ( error# -- ) Default error handler for file I/O"
CR ." PAD$ \ create: ( u -- ) use: ( -- addr )"
CR ." NPAD$ \ ( size -- ) "
CR ." RINGBUFFER \ ( number_8K_buffers -- ) ( -- addr )"
CR ." CELLPACK \ ( c-addr1 u1 addr2 -- addr2 )"
CR ." CELLPLACE+ \ ( c-addr1 u a2 -- )"
CR ." CELLCHAR+ \ ( char addr -- )"
CR
CR ." $TEMP \ ( c-addr1 u1 -- c-addr2 u2 )"
CR ." $FREE \ ( c-addr2 u2 -- )"
CR .~ OVERWRITES \ ( c-addr u "name" -- ) uses (overw) ( c-addr u c-addr2 u2 -- c-addr3 u3 )~
CR .~ $+TO \ ( c-addr u "name" -- ) uses (addto) ( c-addr u c-addr2 u2 -- c-addr3 u3 )~
CR
CR .~ MULTI-LINE \ ( quote "ccc<quote>" -- str len ) Limited to 4096 characters~
CR ." C!+ C+!+ D+!+ \ ( <type> addr1 -- addr2 )"
CR ." CHAR-APPEND \ ( c-addr u c -- c-addr2 u2 )"
CR ." CHAR-PREPEND \ ( c-addr u c -- c-addr2 u2 )"
CR ." CPLACE+ \ ( char addr -- )"
CR ." Split-At-WS \ ( addr1 n1 -- addr1 n2 addr1+n2 n1-n2 )"
CR ." Split-At-Char \ ( addr1 n1 char -- addr1 n2 addr1+n2 n1-n2 )"
CR ." Split-At-Char-NC \ ( addr1 n1 char -- addr1 n2 addr1+n2 n1-n2 ) not case-sensitive"
CR ." Split-At-LastChar \ ( addr1 n1 char -- addr1 n2 addr1+n2 n1-n2 )"
CR ." Split-At-LastChar-NC \ ( addr1 n1 char -- addr1 n2 addr1+n2 n1-n2 ) not case-sensitive"
CR ." Split-At-Word \ ( addr1 n1 addr2 n2 -- addr1 n3 addr1+n4 n1-n4 )"
CR ." Split-At-Word-NC \ ( addr1 n1 addr2 n2 -- addr1 n3 addr1+n4 n1-n4 ) not case-sensitive"
CR ." -LEADING \ ( c-addr u -- c-addr2 u2 )"
CR ." -LEADING-WS \ ( c-addr u -- c-addr2 u2 )"
CR ." -TRAILING-WS \ ( c-addr u -- c-addr2 u2 )"
CR
CR .~ MACRO% \ ( "param1" ... "paramn" -- ) Macro creation word allowing parameter insertion if "%" found.~
CR ." LOOP~ LOOP[ \ ( end start -- ) use % to insert compile-time loop index"
CR ." +LOOP~ +LOOP[ \ ( end start step -- ) use % to insert compile-time loop index"
CR
CR ." ?EXIT ?LEAVE"
CR
CR ." -- system --"
CR ." KILL-PROCESS \ ( c-addr u -- bool ) Kill program
CR ." QUERY-PROCESS \ ( c-addr u -- bool ) interrogate process
CR ." _PID" \ ( -- c-addr u ) return PID as string
CR ." SHAREDMEM \ ( c-addr u sz -- addr ) ask for a name shared memory segment of size = sz"
CR ." UNSHARED \ ( addr -- ) release shared memory"
CR ." HIDE-CONSOLE \ minimize window"
CR ." SHOW-CONSOLE \ raise window"
CR
CR ." -- debug --"
CR ." ]^^[ \ executing: show compiled line#, stacks (rstack if rstackdump? = TRUE), wait for not ^Q"
CR ." ^^ \ compilation: compile current line#, and call to (^^)."
CR .~ ?^^ \ compiles "IF ^^ ENDIF"~
CR ." #^^ \ ( n -- ) compiles n instead of line#"
CR
CR ." -- relative file paths --"
CR ." CD$ \ ( -- c-addr u ) Current working directory"
CR ." ONLY-PATH \ ( c-addr u1 -- c-addr u2 ) Only path"
CR ." ONLY-FILENAME \ ( c-addr u1 -- c-addr u2 ) Only filename"
CR ." ONLY-BASEFILENAME \ ( c-addr1 u1 -- c-addr2 u2 ) filename without extension ( .xxxxxx )"
CR ." FILE-HERE \ ( -- c-addr u ) The name (without path) of the file currently being interpreted"
CR ." PATH-HERE \ ( -- c-addr u ) The dirpath to the file currently being interpreted"
CR ." +INCLUDED \ ( c-addr u -- ) INCLUDE the file (c-addr u), in the same directory as the current file"
CR .~ +INCLUDE \ ( "name" -- ) Parsing version of +INCLUDED~
CR ." FILE-EXISTS? \ ( c-addr u -- TRUE=exists ) TRUE if the file exists (See: FILE-STATUS)."
CR ." FILE-TIME \ ( c-addr u -- ftime|0 ) 100ns increments since the last write to this file (0 is probably FILE NOT FOUND)."
CR ." FILE-BIRTH \ ( c-addr u -- u ) Alias for FILE-TIME"
CR ." UNTAB \ ( c-addr u -- addr2 u2 ) remove TABs from this string (note: in-place!)"
CR ." /SLASHING \ ( c-addr u -- addr2 u2 ) normalize to Linux slashes (note: in-place!)"
CR ." \SLASHING \ ( c-addr u -- addr2 u2 ) normalize to Windows slashes (note: in-place!)"
CR ." UNSLASH \ ( c-addr u -- addr2 u2 ) according to the OS, exchange '\' and '/' in this path-string (note: in-place!)"
CR ." UNQUOTE \ ( c-addr u -- addr2 u2 ) Remove a leading and trailing double quote character"
CR ." +QUOTES? \ ( c-addr u -- addr2 u2 ) Add a leading and trailing double quote character if there is none"
CR .~ UNEXE \ ( c-addr u -- addr2 u2 ) Remove a trailing ".exe" string~
CR .~ +SLASH? \ ( c-addr u -- addr2 u2 ) Add a trailing "\" or "/" when it is not there yet~
CR ." SLURP-FILE \ ( c-addr u -- addr2 u2 ) The location addr2 is transient"
CR ." SLURP-FILE(1) \ ( c-addr u -- addr2 u2 ) Skips space at HERE (2 slurps), also: SLURP-FILE(2) and (3)"
CR
CR .~ $" \ ( 'cccc' -- addr ) compile string, leave address~
CR .~ :INLINE \ ( "text ;" -- ) define hybrid text macro. Not WORDLIST safe~
CR ." PLACE+ \ ( c-addr u 'sum$ -- ) add string to sum"
CR ." $+ \ ( c-addr1 u1 c-addr2 u2 -- c-addr3 u3 ) add str2 to str1. Result str3 is member of a bufferpool"
CR ." $>UPC \ ( c-addr u -- c-addr u ) convert (in place) to uppercase"
CR ." $>LWC \ ( c-addr u -- c-addr u ) convert (in place) to lowercase"
CR ." ZCOUNT \ ( zaddr -- addr u ) length of a C-string"
CR
CR ." LOCATE name find file and source line for `name'"
CR ." HEAD' name LOCATED alternative syntax"
CR .~ S" name" $LOCATE alternative syntax~
CR ." INSPECT after a successful LOCATE, jump to file at line"
CR ." /locate-context the number of lines actually printed"
CR
CR ." WHERE name ??? \ ( -- ) reads name from input and searches files for whitespace limited 'name'."
CR ." WHERE+ name ??? \ ( -- ) reads name from input and searches files for 'name'."
CR ." $WHERE ??? \ ( a l -- ) searches files for a text string given"
CR ." list files and matches, you can press ESC to exit, CASESENSITIVE is respected, ??? can be"
CR ." empty old style behaviour, search all files visited by LOCATE (excluding kernel source)"
CR ." * search the complete dfwforth directory tree."
CR ." directory any dfwforth subdirectory."
CR ." TREE-WALKER ( <baseaddr> <baselen> <maskaddr> <masklen> xt par -- ), see DOC in miscutil" ;
-marcel