-
Notifications
You must be signed in to change notification settings - Fork 16
Packaging
Marcelo Cantos edited this page Jan 18, 2020
·
14 revisions
Below are some thoughts on syntax for referencing libraries.
(In the following, -> is a function body delimiter like Javascript's =>,
not a transform operator as per current language syntax.)
# Pack
\x -> (:x) # Function returning tuple (x: x)
\t -> (:t.*, x: t.x+1) # Function returning tuple with all t attributes, but new x
# Unpack
\(:x) -> x # = \t -> t.x
\(:*) -> x + y # = \t -> t.x + t.y
# Transform (t already bound)
\t=(:x) -> x # = t.x
\t=(:*) -> x + y # = t.x + t.y# "//" denotes a package reference.
//. # Standard library as tuple
//.math # Standard math library as tuple
//.math.sin # Standard math library sin function
//.math.sin(x)
# Other ways to compute sin x...
\//.=(:math) -> math.sin(x) # Unpack math from standard library.
\//.math=(:sin) -> sin(x) # Unpack sin from math.
# ...and beyond...
\//.math=(:*) -> sin(x)**2 + cos(x)**2 # Unpack everything from math.
# After "//" (except "//."), "/" means "." until the first "." after the first "/".
# This allows package paths to be used as follows:
//github.com/nlp/languages.english.parse("The rain in spain falls mainly on the plain.")
\primes = //oeis.org/A000040
\sq_primes = primes >> .**2
...Handling for //github.com and //oeis.org would be quite different. They could
perhaps be implemented through the macro system as shorthand for more explicit
constructs, like:
# //github.com/nlp/languages.english.parse(...)
//.fs("https://github.com/nlp/languages").english.parse(...)
\oeis = //.fs("https://github.com/oeis/arrai")
\raw = //.fs("https://oeis.org/search?q=id:A000040&fmt=text") ->
oeis.parse(raw).STU