Skip to content

Commit 39d8b59

Browse files
authored
Go over documentation for Needs, Get, $Path, and $ContextPath (#1826)
1 parent 3047e87 commit 39d8b59

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

mathics/builtin/directories/user_directories.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class Path(Predefined):
16-
"""
16+
r"""
1717
<url>:WMA link:https://reference.wolfram.com/language/ref/Path.html</url>
1818
1919
<dl>
@@ -23,6 +23,13 @@ class Path(Predefined):
2323
2424
>> $Path
2525
= ...
26+
27+
'\$Path' used consulted in builtin functions <url>
28+
:\$Get:
29+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/file-and-stream-operations/get/</url>, \
30+
and <url>
31+
:Needs:
32+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/filesystem-operations/needs/</url> to resolve filenames, and to resolve contexts to file names.
2633
"""
2734

2835
attributes = A_NO_ATTRIBUTES

mathics/builtin/files_io/files.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,28 @@ class Get(PrefixOperator):
375375
= Cos[x] + I Sin[x]
376376
S> DeleteFile[filename]
377377
378+
If the 'Path' is not fully qualified built-in variable <url>
379+
:\$Path:
380+
/doc/reference-of-built-in-symbols/directories-and-directory-operations/user-file-directories/$path/</url> is consulted.
381+
382+
'Get' can also load packages:
383+
>> $ContextPath
384+
= ...
385+
S> << "VectorAnalysis`"
386+
= ...
387+
388+
If a package is loaded variable <url>
389+
:\$ContextPath:
390+
/doc/reference-of-built-in-symbols/scoping-constructs/$contextpath/</url> is updated with the new package context name:
391+
>> $ContextPath
392+
= ...
393+
394+
See also <url>
395+
:Needs:
396+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/filesystem-operations/needs/</url>.
397+
398+
378399
## TODO: Requires EndPackage implemented
379-
## 'Get' can also load packages:
380-
## >> << "VectorAnalysis`"
381400
"""
382401

383402
eval_error = Builtin.generic_argument_error

mathics/builtin/files_io/filesystem.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,21 @@ class Needs(Builtin):
834834
</dl>
835835
836836
>> Needs["VectorAnalysis`"]
837+
838+
In contrast to <url>
839+
:Get:
840+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/file-and-stream-operations/get/</url>, \
841+
'Needs' only loads a package if it has not already been loaded.
842+
843+
Like 'Get', <url>
844+
:\$ContextPath:
845+
/doc/reference-of-built-in-symbols/scoping-constructs/$contextpath/</url> is updated \
846+
when a new package context is added.
847+
848+
Builtin variable <url>
849+
:\$Path:
850+
/doc/reference-of-built-in-symbols/directories-and-directory-operations/user-file-directories/$path/</url> is used resolve the context to a file name.
851+
837852
"""
838853

839854
messages = {

mathics/builtin/scoping.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ class ContextPath_(Predefined):
316316
## #> System`$ContextPath
317317
## = {x`}
318318
## #> $ContextPath = {"System`", "Global`"};
319+
320+
Functions <url>
321+
:Needs:
322+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/filesystem-operations/needs/</url> and <url>
323+
:Get:
324+
/doc/reference-of-built-in-symbols/inputoutput-files-and-filesystem/file-and-stream-operations/get/</url>, \
325+
add to '\$ContextPath' when a new context is added.
326+
327+
See also Builtin variable <url>
328+
:\$Path:
329+
/doc/reference-of-built-in-symbols/directories-and-directory-operations/user-file-directories/$path/</url>.
319330
"""
320331

321332
messages = {"cxlist": "`1` is not a list of valid context names ending in `."}

0 commit comments

Comments
 (0)