General: File Contexts (or
FCs) describe the domains where Files and other File Contexts
reside. This allows separation of code dealing with the files from code dealing
with the placement of the files. By doing this, Glee programs can
be very portable and managable. You can move their domain of focus by simply
pointing the file contexts to different physical media. For now we'll
keep it simple and view them simply as paths (e.g. c:\glee\).
All file context names end in the " \ ". All file names do not. This
makes them easily distinguishable. In these examples I repeatedly do
""c:\glee"=> #fc" to assure that the context of
the example is known.
Assumption:These examples
assume that you have a directory named "c:\glee\" and that
directory contains the interpreter and website downloaded from
WithGLEE.com. To assure that the
examples will work, you must get the result shown in this example. This example
necessarily changes the current working directory to
"c:\glee\". This is an absolute as opposed to
relative specification. Glee uses a very simple test for
this. If the specification contains a colon (":") it is
taken as absolute (e.g. c:\glee\). If the specification does not
contain a colon, it is taken as relative (e.g. glee\). This test is
admittedly naive and may need to be made smarter later. For flexibility, based
on this test, Glee File Contexts are either implicitly absolute
or relative. An absolute File Context points directly to where Files and
File Contexts are stored. A relative File Context determines an absolute
location of Files and File Contexts by combining the system's current working
directory (result of #FC.cwd) and the relative File Context's path.
Relative contexts are reconciled at run time so they are not known to be valid
or invalid until they are tried.
Set Current Working Directory
(CWD): When you create an instance of a file context (e.g. #fc
=>fc) it is built with no reference to physical media (i.e. no path to
some physical device and directory). When Glee starts up, the
current working directory is the directory in which the Glee
executable is started. This will be "c:\glee\" if you used
the default installation process. You change the CWD by assigning a string to
the operator (e.g. 'c:\glee\' => #fc). This context must exist. If
it doesn't you receive a diagnostic message and CWD remains unchanged. File
contexts always end with a "\". File names never do. In
Glee you may use either the "\" or the
"/" as the directory delimiter. Glee will
always convert " /" to "\" and apply the
trailing "\" if elided.
<1> 'c:\glee'=> #fc: Absolute assignment changes to absolute
CWD.
<2> 'website'=> #fc: Relative assignment changes CWD relative
to CWD.
<3> '..'=> #fc: ".." moves to parent of
CWD.
<4> '..\..\..'=> #fc: ".." moves up
multiple ancestors of CWD.
<5> 'xxx'=> #fc: Directory must exist or an exception
results.
Empty Index:. You can index into
a File Context just as you can do with other Glee objects.
As with other objects, a null index delivers all the contents of the object.
<1>'c:\glee'#fc =>fc $; Set CWD
Setting the Current Working Directory affects all relative File Contexts (FCs).
<2>'website'#fc =>ws $; Create relative FC
An FC is relative if it contains no colon (:). Relative FCs relate to
the CWD.
<3>fc,ws %** $; Forming an FC by catenation.
Since fc is absolute and ws is relative, this catenation
results in an absolute FC.
<4>fc,ws[] %** $; Return the elements of the FC.
The FC's elements are the Files and FCs in its domain. This result is a
sequence.
Show File Contexts
(.fcs): In this example and the two that follow it I show
how you can use File Context methods to learn the contents of a File Context.
These contents are only known at run time as Files and File Contexts may be
added and removed at will. Further, if the File Context is relative, the File
Context on which it depends (i.e. the Current Working Directory - CWD) may
change during operation.
You can display just the File Contexts (i.e. no files listed) contained in a
File Context using the ".fcs" method. This returns a
sequence containing just the File Contexts.
Also note, sorted results can be obtained in the familiar manner:
"fcWeb .fcs >>> %** $;".
Show Files
(.files): You can display just the Files contained by a
File Context using the ".files" method. This returns a
sequence containing just the Files.
Show All Contexts
(.all): You can display all the elements contained
by a File Context using the ".all" method. This returns a
sequence containing both Files and File Contexts. Notice this yields the same
result as an empty index ( [] ).
Catenate:Catenating File
Contexts(FCs) is just like catenating strings. However, because FCs are
objects, they do special work to maintain themselves. A play by play here
should suffice:
<1> 'c:\glee'#fc =>fc1: the absolute root FC.
<2> 'website'#fc =>fc2: A relative FC
<3>'bases'#fc =>fc3: Another relative FC
<4> fc1,fc2,fc3=>fcGWB: An FC formed by pathing catenation
<5>fcGWB .all ,,\: Using the FC to show contents of a directory
<6>fc2,fc3=> fcWB: Another FC formed by pathing catenation
<7>fcWB .all ,,\ : No such directory produces an empty sequence
<8> fc1,fc1: The right argument must be relative ... not
absolute.
Relative Front Path (
<- ): This allows familiar take and drop at the front of a File
Context. You are taking or dropping elements of the file context, not simply
characters in a string. Glee determines these elements by
counting slashes \ from the beginning. If the FC is an absolute FC, this is the
same as the <<- operator. However, for relative FC's the full
path is not made up before applying the operator.
Relative Back Path (
-> ): This does takes and drops of FC elements from the end of
the FC.
Full Front Path (
<<- ): This operator behaves exactly like the Relative Path
Path Part ( <- ). However, if the File Context is a relative file
context, the Current Working Directory prefixes the relative path. The behavior
is identical for absolute file contexts.
Full Back Path (
->> ): This operator behaves exactly like the Relative Path
Name Part ( -> ). However, if the File Context is a relative file
context, the Current Working Directory prefixes the relative path. The behavior
is identical for absolute file contexts.