A exploration (read: very incomplete implementation) of Scrapscript.
With Go installed, run go install github.com/Victorystick/scrapscript/cmd/scrap.
The aim is to implement Scrapscript along with the scrap CLI as documented on https://scrapscript.org/guide.
So far it supports
-
scrap evalto evaluate a script passed over standard input. -
scrap eval apply '...'works likescrap evalbut passes the result of the former to the function defined by'...'. For example:$ echo '0' \ | scrap eval apply 'n -> n + 1' \ | scrap eval apply 'n -> n + 1' \ | scrap eval apply 'n -> n + 1'
-
scrap typeto infer the type of a script passed over standard input.$ echo 'list/fold 0 (total -> text -> total + text/length text)' | scrap type list text -> int
-
scrap testto run the test cases of a script passed over standard input, made withlib/test.scrapand grouped in records and lists. It prints each failing case and exits with status 1 if any failed.$ cd lib && printf '{ adds = t.eq (1 + 1) 3 }\n; t = $"./test.scrap"' | scrap test FAIL adds got 2 want 3 1 failed, 0 passed
-
--root dirreads the script as if it were a file indir, which relative imports such as$"./test.scrap"resolve from, and--cache dirkeeps fetched scraps indirinstead of the user cache directory. Flags go before or after the command:$ scrap eval --root ./lib --cache ./tmp-scraps < some.scrap
-
scrap flat- due to a lack of details. -
scrap yard- just TODO.
Note: Scraps are currently fetched from the scrapyard at https://scraps.oseg.dev/ as text and cached locally.
Differences from https://scrapscript.org
-
Refers to scraps as
$source:<hex>, the sha256 of their source, instead of$sha1~~…, as SHA-1 is cryptographically weak and~~otherwise means base64. During development,$"./path"refers to a draft file. -
No attempt to implement Scrap Maps, Scrap passes or Scrapbooks.