Hello Gerson,
You're welcome, of course.
A possible disadvantage is that often I don't really want a
directory stored in ASCII order. For example, I usually keep
reserved variables and "special" variables such as a list of flags
that I want easily accessible at the end of the directory.
Note that the 28 series and 48SX/S don't have a built-in SORT
command, so for those models a sorting program would have to be
called or a sorting routine substituted for SORT.
Also note that these programs can take a long time to execute.
Neither VARS nor TVARS is particularly fast, and ORDER can take a
long time if a lot of variables have to be moved.
To avoid an error if used on an empty directory, we could use:
%%HP: T(3);
@ Download to 49 series in exact mode.
@ Results from the BYTES command:
@ 48G series:
@ Checksum: # B9F0h
@ Size: 76
@ 49 series:
@ Checksum: # 991Bh
@ Size: 72.
\<< @ Begin program.
VARS @ Get list of variables.
DUP @ Copy of variables list.
IF
SIZE @ Variables list not empty?
THEN
SORT @ Sort list to ASCII order.
ORDER @ Reorder variables.
15 TVARS @ Get list of subdirectories.
DUP @ Copy of subdirectories list.
IF
SIZE @ Subdirectories list not empty?
THEN
ORDER @ Move subdirectories to front.
ELSE
DROP @ Discard empty subdirectory list.
END
ELSE
DROP @ Discard empty variables list.
END
\>>
But one wouldn't be likely to want to use such a program on an
empty directory anyway, so why bother? Well, I did so as a step in
developing a recursive sorted order program that will work on the
current directory and any subdirectories (which may happen to be
empty):
%%HP: T(3);
@ Download to 49 series in exact mode.
@ Recursive program; change ProgName within program to whatever
@ name is chosen for storing the program.
@ Results from the BYTES command:
@ 48G series:
@ Checksum: # 5394h
@ Size: 129
@ 49 series:
@ Checksum: # C209h
@ Size: 125.
\<< @ Begin program.
VARS @ Get list of variables.
DUP @ Copy of variables list.
IF @
SIZE @ Variables list not empty?
THEN
SORT @ Sort list to ASCII order.
ORDER @ Reorder variables.
15 TVARS @ Get list of subdirectories.
DUP @ Copy of subdirectories list
SIZE @ Number of subdirectories.
IF @
DUP @ Subdirectories list not empty?
THEN @
OVER @ Copy of subdirectory list.
ORDER @ Move subdirectories to front.
1 @ Loop begin index.
SWAP @ Move down number of subdirectories.
FOR n @ For each subdirectory.
DUP @ Copy of subdirectory list.
n GET @ Get subdirectory name.
EVAL @ Make subdirectory current.
ProgName @ Call this program recursively.
UPDIR @ Return to parent directory.
NEXT @
DROP @ Discard subdirectories list.
ELSE @
DROP2 @ Discard empty subdirectories list and size 0.
END @
ELSE @
DROP @ Discard empty variables list.
END
\>> @ End program.
Or one could use a subprogram stored in a local variable which
calls itself recursively. In this case, the program can be stored
with any global name without changing the name within the program.
Note that a "compiled local name" is used because I use the name
in the subprogram before the local variable actually exists.
%%HP: T(3);
@ Download to 49 series in exact mode.
@ Results from the BYTES command:
@ 48G series:
@ Checksum: # A5A5h
@ Size: 159
@ 49 series:
@ Checksum: # 5367h
@ Size: 155.
\<< @ Begin program.
\<< @ Begin recursive subprogram.
VARS @ Get list of variables.
DUP @ Copy of variables list.
IF @
SIZE @ Variables list not empty?
THEN
SORT @ Sort list to ASCII order.
ORDER @ Reorder variables.
15 TVARS @ Get list of subdirectories.
DUP @ Copy of subdirectories list.
SIZE @ Number of subdirectories.
IF @
DUP @ Subdirectories list not empty?
THEN @
OVER @ Copy of subdirectory list.
ORDER @ Move subdirectories to front.
1 @ Loop begin index.
SWAP @ Move down number of subdirectories.
FOR n @ For each subdirectory.
DUP @ Copy of subdirectory list.
n GET @ Get subdirectory name.
EVAL @ Make subdirectory current.
\<-s @ Put this recursive subprogram on stack.
EVAL @ Execute recursive subprogram.
UPDIR @ Return to parent directory.
NEXT @
DROP @ Discard subdirectories list.
ELSE @
DROP2 @ Discard empty subdirectories list and size 0.
END @
ELSE @
DROP @ Discard empty variables list.
END @
\>> @ End recursive subprogram.
\-> \<-s @ Bind recursive subprogram.
\<< @ Begin defining procedure
\<-s @ Put recursive subprogram on stack.
EVAL @ Execute recursive subprogram.
\>> @ End defining procedure.
\>> @ End program.
Other, perhaps better, programs could be made, for example perhaps
using the DOLIST command.
Oh, by the way, for the Classic RPN aficionados who feel that
putting the loop index numbers before the FOR itself is overdoing
the postfix notation, the above recursive programs demonstrate the
reason.
Regards,
James