1 File: X09_ExternalObjects.doc By: J.M. Smeenk Revision: 5/19/09 9:46 PM -----------------------MORE ON EXTERNAL OBJECTS ------------------------9. MORE ON EXTERNAL OBJECTS. External names are names of objects or types (see section 12) outside the active workspace. The name of the active workspace is @, and global names within the active workspace are referred to as either @.Name, or more conventionally, just Name. A diagram of a typical system might be as follows: Absolute Path ------------root -->system_stuff1 -->system_stuff2 -->group1 -->user1 -->@ -->F -->D -->Y -->@Data1 -->@Data2 -->@StoredWS1 -->X -->D -->Z -->@StoredWS2 -->W -->user2 -->@Data3 -->@StoredWS3 -->W -->group2 -->user4 -->@ -->W Pathname Relative to User1 -------------------------@@@@ -->@@@system_stuff1 -->@@@system_stuff2 -->@@@group1 -->@@user1 -->@ -->@.F or F -->@.D or D -->@.D.Y OR D.Y -->@Data1 -->@Data2 -->@StoredWS1 -->@StoredWS1.X -->@StoredWS1.D -->@StoredWS1.D.Z -->@StoredWS2 -->@StoredWS2.W -->@@user2 -->@@user2.Data3 -->@@user2.StoredWS3 -->@@user2.StoredWS3.W -->@@@group2 -->@@@group2.user4 -->@@@group2.user4.@ ** INACCESSIBLE -->@@@group2.user4.@.W ** INACCESSIBLE The relative paths from user4's point of view are different. For all users, absolute paths starting with root (e.g. root.group1.user1.@.F) are the same. As mentioned in section 8, names beginning with @ are called external names, with the exception of the workspace @ which is neither an external name nor an internal name. External names are never local; local names are not permitted to begin with @. External names may be manipulated and assigned from within functions and in direct mode. BPL disallows references to another user's active workspace, to avoid concurrency problems. A typical BPL system has an administrator workspace that places prohibitions on user accounts so that users cannot access each other's workspace data. 9.1. DITTO ASSIGNMENTS. 2 When assigning lists of objects, the // token may be used to indicate "same objects as the opposite side of assignment". The following table illustrates ditto assignment: Ditto Assignment ---------------Dir1.//: Dir2.X @Dir1."X Y"== @Dir2.// @@Dir1.Subdir1.//>< Dir2."X Y" Meaning ------Dir1.X: Dir2.X @Dir1."X Y"== @Dir2."X Y" @@Dir1.Subdir1."X Y">< Dir2."X Y" This is simply a convenience to the user to save typing. 9.2. THE POWER OF EXTERNAL OBJECTS, DIRECTORIES, AND NAMELISTS. The power of external objects, directories, and namelists may not be readily apparent. The following table shows how they may be used to accomplish a variety of tasks: BPL Code -------@: @WS1 //: @WS1.Dir1."" //: @WS1."X Y Z" //: @WS1."" @WS1: @ @WS1.Dir1.//: "X Y Z" @WS.Dir1."X Y": {} "@": {} @."": {} @WS1.X: @WS2.Y @WS1.X>< @WS2.Y @."" @@."" Meaning ------load a saved workspace (including the values of all its saved system objects) into the workspace copy all objects from an external directory into the workspace under the same names copy 3 specific objects from a save directory into the workspace under the same names copy all objects of a saved workspace into the active workspace without resetting system objects to their default values save the workspace into an external directory save 3 specific objects from the active workspace into an external directory erase 2 objects from an external directory erase all user objects in the workspace and reset all system objects to their default values erase all objects in the workspace without resetting all system variables to their default values reassign an object in one saved workspace to a variable in another saved workspace swap an object in one saved workspace with an object in another saved workspace list all objects in the active workspace list all the user's workspaces The user must be careful, since one typographical error with the active workspace @ could wipe out a lot of work. BPL presumes that the user knows what s/he is doing. 9.3. FILES. Files do not exist per se as BPL objects; files are treated as external variables. Instead of reading/writing records from/to a file, portions of a variable are accessed by selections. For example: @FilelikeVar: 3@{} @FilelikeVar[1]: {{"John Smith",555 1111,"Red"}} @FilelikeVar[2]: {{"Jane Doe",555 2222,"Blue"}} @FilelikeVar[3]: {{"Joe Jones",555 3333,"Green"}} At all times, @FilelikeVar is stored externally to the workspace. A typical "record" of this "file" is "read" using @FilelikeVar[2] and "written" using 3 @FilelikeVar[2]: NewRecordlikeValue. Unlike files in many computer languages, @FilelikeVar is treated as a BPL variable and any expression using @FilelikeVar may be employed--regardless of the size of @FilelikeVar. Picked selection may also be used with external variables. Treating files as large variables allows far more flexibility than treating them as lists of records--but this may be an implementation challenge. 9.4. FOREIGN FILES. A foreign file created using a non-BPL program may be imported/exported to/from BPL by considering the foreign file's ASCII representation to be a literal vector in BPL. For example: MusicFile: @Song.MP3 @SongTwice.MP3: MusicFile~MusicFile Some details of importing and exporting would probably depend on the interface between BPL and the host operating system.