Incorporate these files into Icon programs using the $include
preprocessor macro:
- This may be readily achieved by including this directory
in your
LPATH
environment variable. - This may be require less preparation and updating than would translating
to "ucode" and using the
link
directive.
development repo: https://chiselapp.com/user/eschen42/repository/aceincl
mirror and release repo: https://github.com/eschen42/aceincl
-
Testing program
runt.icn
and working examples- In the
tests
directory are "working examples" of how to use the files in this directory. - The
runt.icn
runs the test programs to validate their output.
- In the
-
- Procedures to produce logical lines or fields from formatted data files.
-
- Procedures to manipulate files, directores, and their paths.
-
- Procedures to transform data structures into includable Icon declarations and statements.
-
- Procedures to suspend lists combining sequences.
-
- Procedures to produce/manipulate record-like tables.
-
- Procedures to embed RPN-based (Forth-like) interpreter into Icon programs; can also be run in REPL.
-
- Support computing summary statistics for normally distributed data using "Welford's online algorithm".
-
selectRecordFromListByField.icn
- Procedure to produce records from a list of records (or a list of tables), matching specified criteria.
-
- "Nominal vector", i.e., a list whose elements may be accessed by rank (index) or name (key).
- This construct is supported by a Lua-inspired metatable.
-
- Procedure to produce a value that can be read globally but can be reset only by the co-expression that set it it initially.
Working examples, named test_*.icn
, are in the tests
directory:
test_*.std
captures the corresponding test's expected output.icon runt.icn tests
will run the tests and compare the results to their expected output.- usage:
icon runt.icn [--continue] [--verbose] [<zero or more dirs>]
- By default, tests are located and run in the current working directory.
- Otherwise, tests are located and run in the specified directory or directories.
- Tests are not run unless an
.icn
file and a.std
file share exactly the same name. - Use the
--continue
option to run all tests regardless of whether any fail. - Use the
--verbose
option to show both the expected output from the.std
file and the actual output produced by the test program.
- By default, tests are located and run in the current working directory.
Procedures to produce logical lines or fields from formatted data files.
Produce record holding two co-expression factories:
lines
=== tabularLines | iniLinesfields
=== tabularFields | iniFields
Produce a FieldedData
record for filePath
corresponding to format.
format == ("tabular" | "ini")
Factory for a co-expression producing logical lines of a tabular file f
.
Factory for a co-expression producing fields from a logical line of a tabular file:
line
is a logical line produced bytabularLines
.sep
is the field separator; if omitted or &null, TAB is used.
Produce L of RecTable from a tabular file
typeName
: the first result to be produced by RecTableType(T), stsvPath
: the path to the tabular data file, scolL
: (optional) columns to select, L of isep
: (optional) separators, cdflt
: (optional) default value for RecTable fields, x
Factory for a co-expression producing logical lines of an INI file f
.
Factory for a co-expression producing fields from a logical line of an INI file
line
is a logical line produced byiniLines
.
Parse an INI file at path ini
into a table of tables
Procedures to manipulate files, directores, and their paths.
Produce modified fn
, substituting new_ex
for old_ex
- If
new_ex
is "", the trailing period will be removed.
Produce name(s) that name a directory
Suspend location then name of program file.
Suspend root, subdirectories, filename for a directory path
Construct paths from sequences
Return platform-specific command separator
Return platform-specific path separator
Return platform-specific path to the current directory
Procedures to transform data structures into includable Icon declarations and statements.
- Produce Icon code to reproduce value
x
, if possible
- Write Icon code to reproduce values in list
x
tof
if it is a file; otherwise to&errout
andf
is discarded.
Procedures to suspend lists combining sequences.
- Suspend lists combining infinite sequences. LiP:
- evaluates in a "breadth first" manner to ensure that all values of finite sequences will eventually be produced even when some sequences are infinite.
- uses memoization to avert the need to evaluate each sequence more than once.
- uses wora(LiP) to determine whether to use LiFiniteP (the default) or nAltP to combine memoized results.
- requires that
wora.icn
be previously included, for wora(id)
- Recursively suspend lists combining finite seqs;
- does not enforce "breadth first" evaluation.
- Recurrently suspend lists combining finite seqs;
- does not enforce "breadth first" evaluation.
Procedures to produce/manipulate record-like tables.
Produce a table with record-like aspects:
rec_name_s
: the "type" of the RecTablerec_fields_L
: a list of the field namesrec_data_L
: an optional list of values to assign to the fieldsrec_col_iL
: an optional list of column numbers to choose defaults to allrec_default_x
: default value for table members
For RecTable, produce:
- name
- set of all fields
- each field
For non-RecTable, return type(x).
Produce RecTable's field names.
- This will fail for a non-RecTable.
Return a list of the values produced by RecTableFields(x).
- This returns an empty list when x is not a RecTable instance.
Produce RecTable's field values.
- This will fail for a non-RecTable.
Return a list of the values produced by RecTableFieldVals(x).
- This returns an empty list when x is not a RecTable instance.
Return x, except abort when x is not instance of type_name
:
x
: value whose type is to be checkedtype_name
: expected string for RecTableType(x)col_name
: name of identifier-under-testpreamble
: initial string for error message; defaults value of name RecTablePreamble.
Produce a C that, when receiving a transmitted list of values (of the
same length as rec_fields_L
), produces a RecTable instance:
rec_name_s
the "type" of the RecTablerec_fields_L
a list of the field namesrec_col_iL
an optional list of column numbers to choose, defaults to allrec_default_x
default value for table members
Procedures to embed RPN-based (Forth-like) interpreter into Icon programs; can also be run in REPL.
This file may be used to embed RPN-scripted access to Icon procedures and operators, in a manner reminiscent of Forth.
- This needs full and user-friendly documentation, which deserves its own file.
- Words may be composed from existing words.
- Words could be composed to conform to Forth standards...
- New word definitions replace former definitions.
- There is no
forget
yet. - The colon in a definition goes after the string naming the new word, e.g.,
"hi" : "hello world" . cr ;
See the following to get started:
tests/test_rpn.icn
tests/test_rpn.rpn
rpn_core.rpn
rpn.icn
This work was inspired by Steve Wampler's "A (small) RPN calculator" example https://sourceforge.net/p/unicon/mailman/message/6144067/ and R. G. Loeliger's Threaded interprtive languages (1981, BYTE Books) https://lccn.loc.gov/80019392.
To run this "stand-alone" in a "read, evaluate, print, loop" (REPL),
I put the following in ~/bin/rpn
:
LPATH=~/src/aceincl icon -P '
# run rpn.icn
# Define procedure main(args) that imports:
# - ~/.rpn/*.rpn
# - any .rpn files specified as arguments
# and executes standard input if either:
# - *args = 0
# - "-" == !args
$define RPN_MAIN 1
$include "rpn.icn"
# required by rpn.icn
$include "fileDirIo.icn"
'
then I made it executable:
chmod +x ~/bin/rpn
so that I can run it with:
~/bin/rpn
If you have rlwrap (https://github.com/hanslub42/rlwrap) installed (or built), and you change the first line above to
LPATH=~/src/aceincl rlwrap icon -P '
then you can get proper interpretation of the arrow keys in the REPL loop.
These procedures support computing summary statistics for normally distributed data using "Welford's online algorithm", porting code from Wikipedia.
ref: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm
record welford_running(count, mean, M2)
- record accumulating online results without persisting raw data
record welford_cumulative(n, mean, variance, sampleVariance, SD, SE)
- record of statistical results extracted from
welford_running
procedure welford_new()
- produce an initialized
welford_running
record
procedure welford_add(W, x)
- produce an updated
welford_running
recordW
awelford_running
recordx
the next value to add to the record
procedure welford_get(welford_running)
- produce
welford_cumulative
record summarizing normal statistics for the series of x provided towelford_add
welford_running
awelford_running
record updated bywelford_add
Procedure to produce records from a list of records (or a list of tables), matching specified criteria.
- This is currently NOT coded efficiently, so only use it on small lists or tables.
- Also, at present, the co-expression is refreshed and (as an apparent consequence) leaks memory.
- For a better way to do this, see fix_selectRecordFromListByField.icn, which I will eventually apply here instead.
- Even so, there is yet the need to incorporate a "fuzzy binary search" to speed things up immensely for larger lists or tables.
- Produce matching records (or tables)
X
- from list
Lfrom
(type(Lfrom[i]) == "record" | "table"
) - where
X[sField] @ Ctest
succeeds
- from list
- Produce matching records (or tables)
X
- from list
Lfrom
(type(Lfrom[i]) == "record" | "table"
) - where this succeeds:
L := []; every put(L, X[!sFieldL]); L @ Ctest
- from list
"Nominal vector", i.e., a list whose elements may be accessed by rank (index) or name (key).
A use case for this construct might a dynamically-defined record (i.e., an ordered list of key-value pairs), such as might be used to represent a row returned by an SQL query.
Through use of a Lua-inspired "metatable", operations on this structure may be defined or extended with a few message-handler-extension functions. Note that a metatable may be shared among several VNom instances to give them identical behavior; for this reason, the copy constructor copies a reference to the metatable rather than making a copy of the metatable. Thus, behavior of the set of instances may (even dynamically) be modified by changing a single structure.
Construct a new VNom instance.
Original:T
&null
|table
|VNom
Type:s
- Type property
ID:s
- ID property
Metatable:T
- table mapping message strings to message-handler procedures
- By design, when
Original
is another VNom,vnew
copies a reference to the metatable rather than the metatable itself.
Disposable:n?
- if not null, set Disposable property to "yes"
Kind:s
- Kind property
Send messages to update or interrogate the VNom instance.
vmsg(V, "!" ) : x1, ... # generate values in order keys in L
vmsg(V, "*" ) : i # produce number of values
vmsg(V, "get" | "pop" ) : x # pop value, discarding key
vmsg(V, "pull" ) : x # pull value, discarding key
vmsg(V, "push", x1, x2) : V # push value with key
vmsg(V, "put", x1, x2) : V # put value with key
vmsg(V, "key" ) : x1, ... # generate keys in order keys in L
vmsg(V, "keylist" ) : L # copy of L of ranked keys
vmsg(V, "bykey", x ) : s # value, assignable by key
vmsg(V, "byrank", i ) : s # value, assignable by rank (index)
vmsg(V, "kind" ) : s # Kind property, assignable
vmsg(V, "id" ) : s # ID property, assignable
vmsg(V, "type" ) : s # Type property, assignable
vmsg(V, "image" ) : s # image property
vmsg(V, "metatable" ) : s # Metatable, assignable
`
Procedure to produce a value that can be read globally but can be reset only by the co-expression that set it it initially.
- Set or read a globally visible read-only value,
- which is resettable by the C that creates it.
id
identifies the value; it is a key to a static table.del
signifies that the value is to be deleted, but only when specified by the creator.- Otherwise, this argument is ignored.
If you are still using Git rather than the best thing since CVS, then you may need the following to recover from the mess that Git Submodule can create if you are not very careful.
Reference: http://openmetric.org/til/programming/git-pull-with-submodule/
- To add a submodule to a repo, do, e.g.:
git submodule add [email protected]:eschen42/aceincl.git
- For a repo with submodules, pull all submodules using
git submodule update --init --recursive
for the first time. All submodules will be pulled down locally. - To update submodules, use
git submodule update --recursive --remote
- To "commit" new changes in a submodule to the client project:
- Make sure that there are no unsaved changes in the submodule (are any files in the sandbox different from the committed code?). a. If so, commit and push.
- Next:
git submodule update --recursive --remote
- Now it's possible to add and commit changes to the client project.
- What's changed in the submodule? (or "Has the commit for the submodule changed?" or something):
git diff --submodule
Reference: https://www.loekvandenouweland.com/content/head-detached-from-origin-master.html
If a submodule is in a "detatched HEAD" state (and it is not 1789), there are two courses of action that to take, depending on whether commits require rescuing.
If there is no need to push commits to the submodule to a remote git repository, something like the following should work, e.g., to reattach origin/main from the remote for submodule aceincl:
cd aceincl
git branch -la
git checkout remotes/origin/main
git status
git pull
git status
If there are commits to preserve, the process is more involved; see the reference, the gist of which is something like:
- Put the commits onto a branch:
git branch fix-detached-HEAD $(git log | sed -n -e '/^commit/{s/commit[ ]*//; p; q}; d')
- Get the
main
ormaster
branch, as appropriate for your repo:
git checkout main
(orgit checkout master
) - Re-establish remote tracking:
git fetch
- Review changes if necessary:
git diff fix-detached-HEAD
- Merge the changes to the remote-tracking non-HEAD-less branch:
git merge fix-detached-HEAD
- Push changes to the remote:
git push --set-upstream origin master
orgit push --set-upstream origin main