diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-01 16:54:27 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-01 16:54:27 -0500 |
| commit | 5e2c76cf17cb0aae532e19ca2f93960882ef74cb (patch) | |
| tree | 02fe862a8098910bce7e2fde5ee9d148054d5808 /spec/system.md | |
| parent | 722173cd3bd8c4b57263b2ba7449371a635360de (diff) | |
Separate sections on script and file functionality
Diffstat (limited to 'spec/system.md')
| -rw-r--r-- | spec/system.md | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/spec/system.md b/spec/system.md index 7ef17cf8..827af981 100644 --- a/spec/system.md +++ b/spec/system.md @@ -6,23 +6,36 @@ This portion of the spec is definitely still a draft. The `•` symbol is used to access values other than primitives provided by BQN. +## Scripts + +| Name | Summary +|------------|--------------------- +| `•Import` | Load a script file +| `•args` | Arguments passed to current file +| `•path` | Current file's path +| `•name` | Current 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 | Name | Summary |------------|-------------------------- -| `•path` | Current file's path -| `•Import` | Load a script file | `•FChars` | Read from or write to an entire file, as characters | `•FLines` | Read from or write to an entire file, as lines | `•FBytes` | Read from or write to an entire file, as bytes -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. +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. The three formats are: +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: - Chars: BQN characters, or UTF-32. The file is assumed to be UTF-8 encoded. - Lines: BQN strings. The file is decoded as with chars, then split into lines by CR, LR, or CRLF line endings. |
