From: jhmeyers@miu.edu (John H Meyers)
Subject: HIDEVARS - Yes, another hider!
Date: 18 Nov 1997 00:00:00 GMT
Message-ID: <64rha9$bit$1@news.iastate.edu>
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Reply-To: jhmeyers@miu.edu
Newsgroups: comp.sys.hp48


Having too many variables in any one directory is often
undesirable; not only does this cause the VARS command
and the Variable Browser application to slow down to a
crawl, but it also exposes any variable whose menu key
is visible to being accidentally stored into, allowing
important and hard-to-replace programs or data to be
wiped out, with no protective safety mechanism.

There are two basic themes to "hiding" variables, so that
they will neither have menu labels in the VAR menu
nor will they be listed by the VARS command
nor be seen in the Variable Browser:

o Hide some of the current directory's variable names, by
  creating a "no name" variable in front of those to be hidden;
  however, the hidden variables continue to work normally, and
  can be evaluated, recalled, stored, or purged when desired.

  Advantages:

    You can hide programs in this manner
    (especially useful in HOME, to protect programs
    which need to be callable from any other directory).

    Variables survive even after "Recover Memory" (see notes below).

  Disadvantage:

    Incorrect use in subdirectories (see below) can be hazardous;
    however, use in the HOME directory seems to be safe.

o Stash some variables in the common "Hidden Directory"
  instead of in the current directory.  Since only one actual
  directory is used, names must be unique; since the variables
  are not in the current directory, special functions must be
  used to evaluate, recall, store, or purge the variables.

  Disadvantages:

    Not as convenient or suitable for programs.

    Does not segregate variables by original directory.

    Variables are generally lost during "Recover Memory"
    (because the entire hidden directory gets deleted and re-created).

  Advantage:

    Use of the Hidden Directory is normal and safe --
    as long as you don't mess with the reserved system variables.


Quite a few "variable hiding" programs are available on
Goodies Disks, and in various toolkits and libraries --
but some of them can get you into trouble!

For access to variables using the "hidden directory," you can
use either the command set written in SysRPL called HSTO in the
Goodies Disks, or the User-RPL command set I have posted, which
is a little more general; references to where to find all the
programs I mention is summarized at the end of this post.

For hiding some of the variables within a given directory,
there exists quite a variety of programs from Goodies Disks
and a few libraries; however, some of the programs will work
only in directories *other* than HOME (which is usually the place
most in need of trimming the number of variables); some will work
*only* in HOME, and only two of the programs I found will work
in any directory you want, HOME or non-HOME; one of these is
part of a large tool library; the other is the small stand-alone
program I include here, which is small, works in *any* directory,
works consistently across all directories, and discourages
incorrect use of variable hiding, by requiring at least
one variable to remain visible in any directory
(the importance of this will be explained below).


%%HP: T(3); @ HIDEVARS (or give it a short name, say 'HV'):
@ 'name' or { name1 name2 ... } ==>
@ ( Named variables are ORDERed, all others are hidden )
@ { } or empty stack ==> ( Unhide all variables )
\<< @ Uncomment the next line to restrict use to HOME only:
    @ PATH SIZE 1 > { 298 DOERR } IFT
  -55 CF DEPTH { } SWAP { + } IFT @ Assume { } if stack is empty
  @ Uncomment the next line for 'D' argument to mean "all directories"
    DUP 'D' POS 1 == { TAIL 15 TVARS SWAP + } IFT
  @ S/SX users: Replace TAIL with 2 OVER SIZE SUB
  @ Note that the addresses for SYSEVAL are in *HEX* mode (#...h)
  #15777h SYSEVAL DUP IFERR PURGE THEN DROP END @ NULLID
  OVER SIZE { DIR END OVER #8696h SYSEVAL SWAP @ CREATE
  IFERR ORDER THEN SWAP PURGE ERRN DOERR ELSE DUP END } IFT DROP2 \>>
@ HACK Lib users: You may replace ORDER with the faster ORD
@ Checksum (without commented lines): #6C3Ch,  Bytes (on stack): 150.5
@ Checksum    (with 'D' == All dirs): #F7BFh,  Bytes (on stack): 201


This program does basically the same thing as all other variable-hiding
programs; but it will work either in HOME or in any other directory,
and it will disallow hiding *all* the variables in any one directory,
which is a dangerous practice, as you can read in FPGDIR.DOC (GD#5).

Give HIDEVARS a variable name or a list of names, and it will arrange
those variables to be visible, in the order you want, while hiding
all other variables in the directory; give HIDEVARS an empty list
(or an empty stack), and it will unhide all the hidden variables.

It is still possible for you to subsequently purge all the remaining
unhidden variables from any directory in which you have used HIDEVARS;
this would create a directory which "looks empty" even though it isn't,
and since HP did not anticipate nor guard against this possibility in
its internal ROM code, this creates the danger that the normal protection
against purging non-empty directories will be lost, allowing you to purge
a whole directory full of all-hidden variables by making such an error.

Not only might you be allowed to purge a whole directory in this manner,
but if any of the purged variables are "referenced" on the stack,
or in Last Args, etc., then it could result in a Memory Clear
(see FPGDIR.DOC on GD#5/Postings for complete explanation).

However, if you do not deliberately delete all non-hidden variables
and then accidentally purge the whole directory while some of its
variables are still on the stack, etc., then this won't happen to you!

I also recommend that you always include all directories in your
argument list of "visible" variables; to make this easier to do
(especially in HOME, if you create many subdirectories there),
I have included a "feature" whereby you can simply supply
the argument 'D' if you want just directories to remain
visible, or { D name ... } if you want to keep visible all
current visible directories, plus specific other variables;
this feature can be enabled or disabled by you.

If you want all variables to be visible except for a very few,
you could start with the result of VARS and just edit out
the names of those you want to hide.  To make sure that VARS
lists everything, you might want to unhide all variables first.

Programs which list even hidden variables may also be used, since
the "invisible" null names disappear whenever you edit the list.

If you would like a program which lists all variables, even hidden,
but which does not include "null names" in the list, try, e.g.
VARS2 \->STR OBJ\-> (where VARS2 lists everything, even '').


Other notes:

With my Rev M and Rev R ROM versions, I find that every time
I perform the "Recover Memory" procedure, every null-named
variable in any directory gets purged -- including the
normal system "Hidden Directory" in HOME, in which is kept
all your Alarms and User key assignments.

You can take advantage of this "feature" to unhide all variables
in all directories at once, should you wish to do so; keep in
mind, however, that the original Hidden Directory is also lost.

The following post contains programs for making backup copies of
(and restoring) your Alarms and User keys lists:
1997/09/14  "How UserKeys & Alarms are stored"

Simone Rapisarda seems to deserve the credit for discovering that
you can hide variables even in the HOME directory (see HTRIM on GD#8);
however, HTRIM refuses to hide variables in any other directory,
which has its justifications because of the hazards mentioned
both above and below, especially since HTRIM takes an argument
{ } to mean "hide every variable in the directory" (Danger!)

Before anyone started writing "variable hiders," the HP48's
own "Hidden Directory" was the only object in the calculator
which ever had a null name; therefore, evaluating a null
name was sometimes used to "get into the hidden directory";
this no longer works when you use any variable hider, except for
Simone Rapisarda's HTRIM, which stores a small program into
each null-named object it creates while hiding your variables;
the small program in turn contains the correct code for entering the
"real" hidden directory, which is: #640BEh SYSEVAL #8DC4h SYSEVAL
(SetHiddenRes SYSLCONTEXT).  What I do instead is to store
an empty directory into each null-named object; this is
slightly safer than storing other arbitrary objects,
but not quite as fancy as Simone's program.

If you do not use programs which try to get into the Hidden Directory
in this obsolete fashion, then you need not be concerned with this.

The importance of always keeping all subdirectories "visible"
depends on exactly how PGDIR (XEQPGDIR) is implemented,
which I have not determined; note that CLVAR, however,
purges visible and hidden variables alike, except in HOME.

In the absence of assurances otherwise, I recommend that
you never hide directory variables (perhaps I should have
made this the default, but I left it optional).

If you will ever use BZDIR (compress whole directory) in a directory
where some variables are hidden, I recommend changing the string
"BZ VARS PG" within BZDIR to something like "BZ VARS2 PG",
where 'VARS2' is the name of any program which acts like
VARS but includes all hidden variable names as well;
see posts: 1997/11/15 "Lightning-fast VARS command"
and 1997/11/11 "BZDIR improved even further (v 3.2)"

Any program containing SYSEVAL should be used with caution;
besides verifying the coding and checksums carefully, it is
generally recommended to make a memory backup before use.


Summarized below are all other variable hiding programs and references
which I have come across, for your comparison shopping pleasure:

Name       Where     HOME?   Non-HOME    Bytes    Language    Remarks
----      -------    -----   --------    -----    --------    -------

HIDE      GD#1        No       Yes        388     User RPL    3 Cmds

HIDER     GD#5/HA     No       Yes       1474     User RPL    8 Cmds

HTRIM     GD#8/UT     Yes      No         110     SysRPL      1 Cmd

SMTK      GD9&10/UT   Yes      No        5691     Library
                     (Contains HTRIM)

HIDEV     GXTOOLS     Yes      Yes       4471     Library
                     (Also has fast VARS & ORD)

HIDEVARS  (Above)     Yes      Yes        150     User RPL    1 Cmd

HSTO      GD#7/PR     Hidden Directory    142     SysRPL      4 Cmds

(post)  1997/05/20   "Hidden Directory"   231     User RPL    6 cmds
                     (Programs to improve and expand upon HSTO)

FPGDIR    GD#5/PO    (Explains the hazards of hiding and then purging)

NULLNAME  GD#1       (Don't use these obsolete methods! -- see above)

STOPSIGN  GD#10/HA   (More hidden facts about the Hidden Directory)

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
