From 5e2c76cf17cb0aae532e19ca2f93960882ef74cb Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 1 Dec 2020 16:54:27 -0500 Subject: Separate sections on script and file functionality --- docs/spec/system.html | 36 +++++++++++++++++++++++++++++------- spec/system.md | 29 +++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/docs/spec/system.html b/docs/spec/system.html index e8caea8e..64a43ce6 100644 --- a/docs/spec/system.html +++ b/docs/spec/system.html @@ -7,7 +7,7 @@

Specification: BQN system-provided values

This portion of the spec is definitely still a draft.

The symbol is used to access values other than primitives provided by BQN.

-

File access

+

Scripts

@@ -17,13 +17,37 @@ + + + + + + + + - - + + + + +
•ImportLoad a script file
•argsArguments passed to current file
•path Current file's path
•ImportLoad a script file•nameCurrent filename
+

•Import loads another BQN script. The script is evaluated in its own scope, and its result is either the result of the last line, or a module if it exports with at the top level. If it is a module, then it must be destructured immediately unless first-class namespaces are possible.

+

The right argument is a filename, which may be relative or absolute. Relative paths are taken relative to the source file where this instance of •Import was written. The left argument, if given, is the list of arguments that should be passed through to the file as •args. If no left argument is given then ⟨⟩ is used for •args. However, the behavior is different in this case. The same file will only be loaded once in a given BQN program by •Import calls with no left argument: the first such call saves the returned value, even if it is mutable, and subsequent calls return this saved value. To avoid this and reload the file, pass a left argument of ⟨⟩.

+

•args is the arguments passed as the file was invoked, either from the command line or •Import. For command line calls it is a list of strings.

+

•path simply gives the path of the file in which it appears. It includes a trailing slash but not the name of the file itself.

+

•name gives the name, including the extension, of the file in which it appears.

+

File access

+ + + + + + + @@ -38,10 +62,8 @@
NameSummary
•FChars Read from or write to an entire file, as characters
-

File paths for any of the commands in this section may be relative or absolute. Relative paths are taken relative to the source file that loads that instance of the system command.

-

•path simply gives the path of the file in which it appears. It includes a trailing slash but not the name of the file itself.

-

•Import loads another BQN script. The script is evaluated in its own scope, and its result is either the result of the last line, or a module if it exports with at the top level. If it is a module, then it must be destructured immediately unless first-class namespaces are possible.

-

Functions •FChars, •FLines, and •FBytes are all ambivalent. If only one argument is given, then it must be the name of a file, and the result is the contents of the file in the appropriate format. If there are two arguments, then the left argument is the filename and the right is the desired contents. These are written to the file, overwriting its contents. The three formats are:

+

As with •Import, file paths may be relative or absolute, and relative paths are relative to •path.

+

Functions •FChars, •FLines, and •FBytes are all ambivalent. If only one argument is given, then it must be the name of a file, and the result is the contents of the file in the appropriate format. If there are two arguments, then the left argument is the filename and the right is the desired contents. These are written to the file, overwriting its contents, and the filename 𝕨 is returned. The three formats are: