You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
machines/sinq.shoddy
— Shoddy INtegrated Query: the half of a query the rest of the library could
not say, which is the word by. Ordering by a key and by several keys
(OrderBy, OrderByDesc, OrderWith, ByKey, ThenBy, Descending),
grouping (GroupBy), joining (JoinOn, GroupJoinOn), the set words
(Distinct, DistinctBy, Union, Intersect, Except), walking a record
type that holds itself (Descendants, Offspring, SelectMany), the
extremes by a key (MinBy, MaxBy, and their Opt twins), and the total
twins that answer an Option instead of aborting (FirstOpt, LastOpt, SingleOpt, FindOpt). It re-declares nothing: Map, Filter, Fold and Sort are still builtins and Sum is still stats'.
Sorting by a key at last.Sort is a builtin, ascending-only, and takes
no selector — handed records it stops the program with SORT expects all NUMBERs or all STRINGs. OrderByDesc(staff, Pay) is now
an ordinary line. The sort is a stable merge sort, so equal keys keep source
order and ThenBy means what it says.
No adapter for arrays, vectors or matrices, because none is needed. A Matrix's Cells is already an array and an array is already a sequence, so
a matrix is queried through the same words as a list.
seed-sinq puts thirteen of them at the reckoner keyboard in halifax and
sparky alike — SORTBY, SORTBYDESC, GROUPBY, MINBY, MAXBY, FINDFIRST, TAKEWHILE, SKIPWHILE, DISTINCT, UNION, INTERSECT, EXCEPT and CHUNK. The eight that take a selector take a quoted program: { 1 2 3 4 } [ 2 MOD ] SORTBY.
A worked example that the gate runs.tst/sinq-demo.shoddy queries a
customer/order graph, a catalogue, a self-holding org tree and a matrix in
one program, and is reproduced line for line on the machine's page — so the
page cannot show code that no longer compiles.
Changed
Five machines dropped code they should never have had to write.alg's
hand-rolled insertion sort is gone and its canonicalisation is n log n; json and xml both carried a written apology that Sort would not sort a
list of pairs, and both are gone with the per-key re-lookups they forced; reckoner's WORDS is a GroupBy where it was three Defs; bool's
Quine–McCluskey dedupes with Distinct and scores each implicant once
instead of twice.
seq's documented cost model was wrong, and is corrected everywhere. A
Shoddy list is contiguous underneath, so Rest hands back a copy of the
tail and a First/Rest walk is quadratic — 74 ms at 12,500 elements and
3,585 ms at 50,000. Lists are not cons cells. The machine header, the seq page and both
AI grounding pages said otherwise and now say this.
Only self-tail-recursion becomes a loop, which is now written down
where it can be found. Mutual recursion costs a frame per element like any
other call, and the ceiling is about 20,000 frames — a hard process kill with
no line number. sinq's own suite runs fifty thousand elements for exactly
this reason; it is the only suite in the tree big enough to catch either
fault.