Post Reply 
[question]userRPL, functions or (sub)subprograms and directories
03-29-2017, 11:07 PM
Post: #17
RE: [question]userRPL and functions or (sub)subprograms
Regarding directory syntax:

In the context of RPL, directories are simply another type of object. They're actually conceptually similar to other compound objects such as lists, in that they encapsulate other objects into a single entity. So, like the syntax for lists ( { obj1 obj2 ... objN } ), the syntax for notating a directory object simply consists of a prefix (DIR), the contents (<whatever>*), then a suffix (END).

The syntax of notating a directory object's contents (<whatever>*) is an arbitrary sequence of 0 or more object id/definition pairs. So you could designate the syntax as follows:

Code:
DIR <obj1_ID> <obj1> <obj2_ID> <obj2> ... <objN_ID> <objN> END

Unlike lists, there's very little you can actually do with directory objects other than recalling them to the stack or storing them into variables. Their usefulness comes from the kernel knowing how to deal with them directly, which it exposes through the user interface, dedicated variables (such as HOME), and directory-specific commands and features (PATH, ORDER, CRDIR, PGDIR, etc.).

All of the IDs in a directory definition have to be valid RPL IDs, and all of the objects have to be valid single RPL objects. The objects themselves can be any valid RPL type that could normally be stored into a variable, including other directories. So, for example, all of the following are valid directory designations:

A directory containing three numeric objects:
Code:
DIR a 1 b 2 c 3 END

A directory containing two lists and an algebraic:
Code:
DIR a { 1 2 3 } b { 4 5 6 } c '(x+y)/z' END

A directory containing a single program named 'myprog':
Code:
DIR myprog \<< 1 + 5 / SQ \>> END

A directory containing a single directory with no objects:
Code:
DIR emptydir DIR END END

I've put all of the above on a single line to show the minimal syntax, but you can add newlines/indentation as desired for readability:
Code:
DIR
  a
    { 1 2 3}
    
  b
    { 4 5 6 }
    
  c
    { 7 8 9 10 11 12 }
    
  x
    12345
    
  myprog
    \<<
      1 +
      5 /
      SQ
    \>>
    
  emptydir
    DIR
    END
  
END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
about DIR END - pier4r - 03-29-2017, 06:15 PM
RE: [question]userRPL and functions or (sub)subprograms - DavidM - 03-29-2017 11:07 PM



User(s) browsing this thread: 2 Guest(s)