General Operators: The File
object is an abstract object. It has two attributes: (1)File Context and (2)
File Name. The object is abstract in that it may not relate to anything
physical. Until it does relate to something physical, most of the operators
have benign effect. When operated on in a complying context a File object comes
to life. This section describes the operators, methods, and properties
associated with the File object.
#FILE (niladic):
Using the niladic form of the #FILE operator yields a totally abstract
File object. It will never find a compatible context. However, you can modify
its Name and File Context later on and bring it to life.
#FILE (monadic): The
monadic form of the #FILE operator takes a file name argument. If the
argument is file name only, a null File Context is given to the file. If a full
path is given, the File Context is extracted from the path. Rules for doing
this are very simple. Begin on the right and scan left until finding
"\", "/", or ":".
Everything before and including that position becomes File Context.
Everything up to that point is considered file name. Being an abstract
object, the file doesn't require compliance with a physical store nomenclature
until access is attempted. Then it either succeeds and performs the desired
operation or it fails and signals an event. This example illustrates several
permutations of the instantiation of a file object using the monadic form.
#FILE (dyadic): The
dyadic form of the #FILE operator takes a file name left argument and
a file context right argument. This form allows you direct the file operations
to different physical media while using the same file object. A typical
application would have a test environment in one place and the live environment
in another. You then easily switch between the two by changing a variable
holding the file context which is delivered as an argument.
Stream operations:
All stream operations on files are the same as on strings. This is because they
work on the file buffer property which is a string.
Hex Look (:hex
):This example illustrates that reading and displaying information in a
file object is exactly like doing the same on a string object. This is because
you are working with the file's buffer property which is just a
Glee string object.
General Properties and
Methods: File objects have properties and methods. For all intents and
purposes they can both be viewed as properties because (right now) the methods
do not take arguments ... they just return a result. For example, the
.crc method executes against the contents of the file and returns an
integer result. For all the user knows, that result is simple static data and
thus looks like a property of the file. For now, some properties are assignable
(e.g. :name) but no methods are assignable. This may change later on
as a need arises. Assigning to a method would essentially be a method call
where what is being assigned is an argument to that call. For example, I may
later create an :encrypt method. Assigning a key to this method would
encrypt the file using that key.
:name: This example
illustrates changing the .name property; observing its effect; and
reading the property and displaying it. As shown in this example, changing the
name makes the associated file object comply with a different stored file. When
this is done, the file is closed and all attributes (e.g. read and write
pointers) are cleared. The new file is not reopened. In Glee,
file opens take place implicity when the file is operated upon.
:fc: This example
illustrates change the file context on a file object thereby changing its
target physical media.
:props: The file
properties can be viewed just like string properties. This property is
principally used for troubleshooting and illustration. Note: Files are still
in early development so this example may not be exactly what you see until the
implementation stabilizes.