


















                              ******************
                              ** mod12 v. 3.0 **
                              ******************

                                  USER GUIDE











































                                  mod12 User Guide - ii








Thomas Demske

E-mail: tdemske@msn.com







(C) Copyright 1996 Thomas Demske.
All rights reserved.

The "mod12 package" comprises this User Guide and all
of the programs and files on its accompanying disk.

The mod12 package was authored by Thomas Demske.

No part of the mod12 package may be reproduced or
transmitted in any form whatsoever or by any means
whatsoever without prior written consent of the author.







Limits of Liability and Disclaimer of Warranty:

The author has applied his best efforts in preparing
the mod12 package.

However, the author makes no warranty of any kind,
expressed or implied, with regard to the mod12 package,
in any of its parts or in its entirety.  The author
shall not be liable in any event for incidental or
consequential damages in connection with, or arising
from, the furnishing, performance, or use of the mod12
package, in any of its part or in its entirety.


















                                      mod12 User Guide - iii




                          CONTENTS



  About mod12                                           1
  Getting Started                                       2
  Entering Pitch-Class Set Expressions                  4
  Pitch-Class Set Operators                             9
  PRM2, COMPACT, and CLIP-COMMENT                      13
  Integer Expressions, Arithmetic, and Functions       16
  Getting Information about Pitch-Class Sets           19
  Test Expressions and Boolean Operators               22
  The UNIV Forms of SHOW and TALLY                     26
  Iteration and Conditional Execution with FOR         29
  Chaining Commands with SEQ                           35
  BREAK'ing Chains and Loops                           37
  Debugging with TRACE                                 39
  Formatting Text with DISPLAY                         43
  The Console and Files                                46
  LOG'ing System Transcripts                           50
  RECORD'ing Segmentations in the Database             52
  The Range Forms of SHOW and TALLY                    57
  Iterating over the Database with FOR                 59
  Storing and Recalling Databases with SAVE and LOAD   62
  DELETE'ing, MOVE'ing, and SORT'ing in the Database   64
  Automated Entry with AUTO                            69
  The MACRO Facility                                   71
  Building Macros and Assigning User Input             76
  Blocking Macro Expansion with FENCE                  81
  Scoping and LOCAL                                    83
  CALL'ed Macro Procedures                             88
  RETURN'ing Values through Macro Functions            94
  SCGROUPS: A Sample Script                            97
  ACKNOWLEDGMENT: An Essential Script                 103
  Works Cited                                         103
  Appendix A.  Catalog of Tests                       104
  Appendix B.  Catalog of Commands and Procedures     110

























                                        mod12 User Guide - 1

About mod12

     mod12 is a flexible tool for analysts, theorists, and
composers working with unordered collections of modulo
twelve pitch classes.

     At its most basic level, mod12 is a set identification
program.  You enter a set, and mod12 identifies it,
providing other information as well if requested.  The sets
you enter may be kept in a commented database that you can
save, restore, update, and reorganize in many ways.

     Just a few keystrokes beyond that lies mod12's powerful
query facility, which is always available to match sets from
the pitch-class set universe or a user database against
arbitrary criteria.  You can tally according to those
criteria, or iterate over segmentations and abstract sets to
conditionally execute mod12 commands.  A wide variety of
set-theoretical and analytical problems are amenable to this
approach, such as partitioning exercises, or discerning
transformational trends in large groups of segmentations.

     mod12 also includes scripting capabilities, which
amount to a small, but complete, programming language.
User-defined functions are supported, along with flow
control commands, integer arithmetic, variable scoping, and
debugging.

     mod12 is readily customized.  Its macro facility lets
you assign a name to any string and then invoke that string
by its name.  Text output can be formatted as desired.  You
can use Forte or Rahn prime form tables, and sets may be
entered in a variety of ways.  A full array of predefined pc
set operators and integer functions is available, including
various embedding counts and arbitrary pc set
transformations.  Operators and functions may be freely
mixed in any context, and test predicates may be combined to
form myriad boolean expressions of arbitrary complexity.

     mod12 is character-based and line-oriented.  The
benefits to this approach include portability across many
platforms and remarkably few demands on system resources.
Users comfortable with more modern, point-and-click
environments will still find it easy to work with mod12's
limited interface.  Input and output can be redirected to
files, for example, and entire sessions can be logged to
files for review in a favorite editor or word processor.
All file output is pure ASCII text, the lowest common
denominator for most systems and word processing programs.

     mod12 is fully documented through online help.  If you
are confused about command syntax, or need to find the right
test for a particular situation, help is always there.












                                        mod12 User Guide - 2


     Because mod12 is so flexible, its potential for
application resists quick summary.  This guide can offer
only a survey of the program's features.  How much of
mod12's potential is realized for you depends on your
knowledge, experience, patience, and imagination.


Getting Started

     mod12 is an interactive, line-oriented command
interpreter.  All mod12 sessions follow a simple pattern.
mod12 prompts you for input, you enter a line of text, and
mod12 evaluates it.  The process repeats until you end the
session with the EXIT command.

     mod12 greets you with this input prompt at the start of
each session:

-----

  mod12 >

-----

That prompt may change as the session progresses, although
it will always begin with the "mod12" name.  For example, it
might look like any of the following, depending on the
sequence of commands entered up to that point in the mod12
session:

-----

  mod12 >      mod12 A >             mod12 ACL >     mod12 P 379 >
  mod12 Q >    mod12 ACLPQ 379 >     mod12 378 * >   mod12 CP ! >

-----

The different prompts represent different system states;
type HELP PROMPT for more details.  However, regardless of
appearance, the prompt always indicates that mod12 is
waiting for you to enter a command to be carried out.

     mod12 will accept input lines of almost any practical
length from the console, but your operating system probably
imposes a limit.  For example, MS-DOS's input buffer is
restricted to only 120 characters.  Fortunately, most useful
mod12 input strings entered from the console are less than
80 characters in length.

     You may occasionally need to exceed the system-imposed
character-per-line limit at the console, however, and will













                                        mod12 User Guide - 3

likely want to split lengthy commands over more than one
line for readability.  Extending a single mod12 expression
over a literal line break is accomplished by including a
backslash character ("\") as the last, non-blank character
on the line.  The concatenation of two lines separated by a
literal line break results in a "logical line."  More
specifically, a logical line is either:

     (1)  a string of zero or more characters terminating
          with a literal line break; or

     (2)  a logical line whose last, non-whitespace
          character is a backslash ('\'), plus the next
          logical line in the input source.

"Whitespace" is any space, tab, or literal line break.  In
form (2) above, mod12 discards the terminal backslash, along
with any subsequent whitespace up to and including the
literal line break, before concatenating the two logical
lines.

     For example, the following command is one of many ways
to display all prime form trichords and tetrachords which
are both octatonic and diatonic:

-----

  mod12 > show univ pr and (cd 3 or cd 4) and asb 8-28 and asb 7-35

-----

Here is the same command distributed over several lines:

-----

  mod12 >      show univ         pr              \
                            and  (cd 3 or cd 4)  \
                            and  asb 8-28        \
                            and  asb 7-35

-----

     Notice the free use of blanks in the last example.
Before processing, mod12 removes any leading and trailing
whitespace, and replaces internal spans of multiple
whitespace with a single space.  The previous command would
also work if it were entered like this:

-----

  mod12 > SHoW UniV PR aNd (CD 3 oR cd 4) AnD asB 8-28 anD AsB 7-35














                                        mod12 User Guide - 4

-----

mod12 replaces all upper case letters with their lower case
equivalents before processing; consequently, case is
insignificant.

     All mod12 input is "normalized" like this with respect
to whitespace and case.  The only exceptions are: comments
(type HELP COMMENT), quoted text, and literal input to a
macro (type HELP MACRO).  Type HELP I/O for more details on
mod12 input.

     Two of the most important mod12 commands are

                           EXIT,

which terminates the current session, and

                           HELP.

HELP starts mod12's online HELP facility.  If you enter HELP
by itself at the mod12 > prompt, the first screen you see
gives instructions on using the HELP facility.  If you
specify a topic, HELP opens with a screen describing that
topic.  Once in the HELP facility, you can jump from topic
to topic, returning to previous screens if desired.

     The HELP facility is intended to be used, and used, and
used again.  It is the full reference of all mod12 features.
This guide is more discursive in nature.  It sidesteps
detail, and often refers you to online help for more
information.  Also, the guide may introduce symbols without
explaining them, such as SHOW, UNIV, PR, AND, CD, and ASB in
the preceding example.  Such symbols are all topics
accessible through HELP.  You are encouraged to become
familiar with the HELP facility before going further in this
guide.  Type HELP HELP to get started.


Entering Pitch-Class Set Expressions

     A set entered by itself at the mod12 prompt is
interpreted as a command to identify that set.  Sets entered
at the prompt, or in any mod12 context, are "set
expressions," and may be represented in several ways.

     One of these is as a set of pc letter names along with
any necessary accidentals, "#" for sharp, and "-" for flat.
Each element is separated from the next by a comma and
optional whitespace, and the entire set is enclosed in
square brackets.  Here, as with any set submitted to mod12,
duplicate pcs are ignored:













                                        mod12 User Guide - 5


-----

  mod12 > [ E-, C, B , B- , E , G ,g , F## , A--]
        0347ab        t10   6-z44

-----

     mod12 identifies a set by showing its pitch class
content, its TnI relationship to Allen Forte's prime form,
and the Forte name of the set class to which it belongs.
(The names are listed in Appendix 1 of Forte 1973).  Forte's
primes are the default in mod12, but you can change to
another prime form table with PRM2 (described below, or type
HELP PRM2).  The pc content is represented with pc digits,
which follow standard usage: '0' means C-natural, etc., 'a'
means pc 10, or B-flat, and 'b' means pc 11, or B-natural.
mod12 lists the digits in ascending order, although that
order may be changed with COMPACT (described below, or type
HELP COMPACT).

     Sets can be also be entered using a format resembling
that in Forte (1973).  Here, integer expressions are
delimited by commas and optional whitespace, and enclosed in
square brackets.  (Integer expressions are described below,
or type HELP INTEGERS.)  The integer expressions are
evaluated and automatically reduced modulo 12.  Simple
integers are entered in the first entry below, while the
integers in the second are calculated:

-----

  mod12 > [ 3, 0, 11, 10, 4, 7 ]           /* simple integers entered */
        0347ab        t10   6-z44

  mod12 > [ 12/2+2, 600, 10+1, 2*17, - abs -8, cd 7-1 ] ; not so simple
        0347ab        t10   6-z44 ; not so simple

-----

     Comments were appended to those last entries.  Any
mod12 entry may be commented, either with a "C-style
comment," or a "semicolon comment."  (Type HELP COMMENT for
details.)  C-style comments start with the character
sequence /* and end with the character sequence */; they are
nestable, and completely ignored by the system.  With
semicolon comments, mod12 usually ignores the semicolon and
any characters which follow it in the logical line.
Although optional, comments can be invaluable memory aids
when reviewing mod12 log files (type HELP LOG).  Also, the
first 200 characters of a semicolon comment entered with a
set are "associated" with that set, which is why the comment













                                        mod12 User Guide - 6

was displayed with the set identification in the second
entry above.  When recording sets into the database (type
HELP RECORD), any comment associated with a set is stored in
the same record as the set.  Databases can be searched and
sorted according to comments, along with many other
criteria; type HELP CMNT and HELP SORT for details.

     You can mix pc integers and letters-with-accidentals in
the same set, so long as the comma and square bracket
conventions are followed:

-----

  mod12 > [ E-, 6 + 6 + 6 + 6 , 11, B-, 4, F## ]
        0347ab        t10   6-z44

-----

     The style used in Morris (1987) is another acceptable
pc set entry format.  This describes a string of modulo 12
pc digits with optional whitespace enclosed in curly
brackets:

-----

  mod12 > { 048 159 26a 37b }
        0123456789ab  t0   12-1

-----

As in the most recent example, mod12 uses the standard
"extended Forte names" when naming sets of cardinalities
less than three and greater than nine.  The aggregate is
named 12-1; the null set is 0-1; monads belong to set class
1-1; dyadic set classes are named by the interval classes
they instance; and ten- and eleven-element sets share
ordinal numbers with their respective complements.

     The most convenient entry format accepted by mod12 is a
string of one or more modulo 12 pc digits only, without any
brackets or whitespace:

-----

  mod12 > 023
        023           t3i   3-2

-----

Although convenient, this notation may be confused with
integers in some contexts; type HELP PCSET and HELP TYPECAST
for details.













                                        mod12 User Guide - 7


     Forte set-class names are another acceptable set entry
format.  mod12 interprets these names as representing the
pcs in the prime form of the set class.  It is not necessary
to include a "z" in the name; an unwarranted "z" is ignored.
Otherwise, entries which look like set names, but in fact
name impossible sets, are interpreted as the null set:

-----

  mod12 > 4-z15
        0146          t0    4-z15

  mod12 > 4-29    /* Forgot the z?  No problem... */
        0137          t0    4-z29

  mod12 > 3-z11   /* [C,E-,G] is NOT a z set.  Well, okay... */
        037           t0    3-11

  mod12 > 3-13    /* no such set! -- interpreted as the null set */
                      t0    0-1

-----

The Forte name format is also ambiguous in a few contexts,
since it may be confused with an integer expression; type
HELP PCSET and HELP TYPECAST for details.

     You can use database ranges also in referring to sets.
The database is a collection of numbered slots where you
store sets for later use, and ranges are sets of
consecutively numbered slots.  (Type HELP DATABASE and HELP
RANGE.)  This pcset entry format requires that the database
range be preceded by an "at" symbol ('@') or an ampersand
('&').  The at format is interpreted as the union of all
sets in the specified range; and the ampersand format, as
the intersection of all sets in the specified range.  For
example, the records in slots 1 through 3 of a sample
database are shown below.  We can use the slot numbers in
the leftmost column of the display to refer to sets.

-----

  mod12 > show 1..3
  1     679           t6    3-2   ; pno tl m8.-m9
  2     08b           t0i   3-3   ; pno tl m1.-m2.
  3     28a           t8    3-8   ; pno tl m10.-m12. (up to rest)

  mod12 > @ 1..2 ; the union of sets in slots 1 and 2
        06789b        t6    6-z3  ; the union of sets in slots 1 and 2

  mod12 > @ 3 ; the pcs in the set stored at slot 3













                                        mod12 User Guide - 8

        28a           t8    3-8   ; the pcs in the set stored at slot 3

  mod12 > & 2..3 ; all pcs common to slots 2 and 3
        8             t8    1-1   ; all pcs common to slots 2 and 3

  mod12 > & 1..3 ; common to slots 1 through 3 -- none at all!
                      t0    0-1   ; common to slots 1 through 3 -- none at all!

  mod12 > & 3 ; pcs in slot 3 -- same as @ 3
        28a           t8    3-8   ; pcs in slot 3 -- same as @ 3

-----

     mod12's MACRO facility offers another way to reference
sets: define your own descriptive set names with the MACRO
command (described below, or type HELP MACRO).  For example,
two famous Russian sets are named in the next example.  The
names are then used as arguments to SUBSETS (described
below, or type HELP SUBSETS), which lists mutual subset
types with cardinality greater than 2:

-----

  mod12 > macro "Mystic-chord" [c,f#,b-,e,a,d]

  mod12 > macro "Petrouchka-chord" [c,e,g,f#,a#,c#]

  mod12 > subsets Mystic-chord Petrouchka-chord cdg 2

  3:  2    3    5    7    8    10   11

  4:  12   15   25   27   29

  5:  28

-----

     You also can define macro functions which return sets
(described below, or type HELP CALL).  These functions are
themselves set expressions.  For example, given any set S
and any inversion index N, define a smallest set FIX-MIRROR
such that the union of S and FIX-MIRROR is invariant under t
N i.  Since FIX-MIRROR is defined in terms of S and N, the
function which calculates it should take S and N as
arguments:

-----

  mod12 > macro "fix-mirror_"         \
    local "s" set "index" int         \
      return set (t index i s) not s














                                        mod12 User Guide - 9

  mod12 > macro "fix-mirror" set call "fix-mirror_"

-----

Having defined this function, it can now be used like other
set expressions.  Below, the mirror fixes of {0146} are
shown as N ranges over the indices 0 through 11.  For
example, at N = 0, the mirror fix of {0146} at t0i is {8b},
since the original set's 0 and 6 invert onto themselves,
while the original set's 1 and 4 invert onto the mirror
fix's b and 8, respectively:

-----

  mod12 > for int 0 11 display ?i0 tab 3 ": {"            \
                               pcs fix-mirror {0146} ?i0  \
                               "}" nl
  0  : {8b}
  1  : {79}
  2  : {28a}
  3  : {239b}
  4  : {3a}
  5  : {5b}
  6  : {25}
  7  : {37}
  8  : {278}
  9  : {3589}
  10 : {9a}
  11 : {57ab}

-----


Pitch-Class Set Operators

     Pitch-class set operators are accepted in all set
expressions.  Unary operators return standard Tn/I/M
transformations, user-defined pc transformations,
complements, prime forms, and z-related prime forms.  Binary
operators return set intersections, unions, differences, and
symmetrical differences.

     The transformations, Tn, I, and M, may be combined in
strings of arbitrary length.  Tn represents transposition by
n semitones (n is an integer), I represents pc inversion
around pc 0, and M represents the M5 transform:

-----

  mod12 > t3 047
        37a           t10i  3-11














                                       mod12 User Guide - 10

  mod12 > i 047
        058           t5    3-11

  mod12 > m 047
        08b           t0i   3-3

  mod12 > im 047                     /* im = M7 = mi */
        014           t0    3-3

  mod12 > t3im 047
        347           t3    3-3

  mod12 > t1it7mimit11t(39+2*14)iiiiiiiit3t25784mmmmmmimmit3t4t5t1t2t3t0mi \
          imt28mimimit5t6t7t8mt-10t-9t-8t-7m [c,e,g]  ; check it yourself!
        7ab          t11i  3-3   ; check it yourself!

-----

(Type HELP CALL for a sample procedure which reduces
arbitrary Tn/I/M operator strings to their simplest forms.)

     User-defined transformations express arbitrary one-to-
one and many-to-one mappings of the aggregate into itself.
The format for a user-defined mapping is:

                         OP mapstring

where mapstring comprises exactly twelve pc digits.  The
first digit in mapstring is the (image) pc onto which
(preimage) pc 0 will map under the transformation; the
second digit, the pc which pc 1 will map onto; the third
digit, the pc which pc 2 will map onto; and so forth.  For
example, Morris (1982) uses cyclical notation to represent
mappings.  His "AL3" mapping exhibits this cycle: (0) (2)
(4) (6) (8) (10) (11-9-7-5-3-1).  AL3 applied to the prime
form of set class 3-1 -- i.e., [0,1,2] -- can be expressed
in mod12 like this:

-----

  mod12 > op 0b29476583a1 3-1
        02b           t11   3-2

-----

(Type HELP CALL for an example of a one-to-many mapping
function.)

     The CMP operator returns the literal complement of its
argument:

-----













                                       mod12 User Guide - 11


  mod12 > cmp 01356
        24789ab       t7    7-z12

-----

     The PF operator returns the prime form of its argument:

-----

  mod12 > pf 24789ab
        0123479       t0    7-z12

-----

The PF operator is sensitive to the current prime form table
(described below, or type HELP PRM2).

     The ZSET operator returns the prime form set which is
z-related to its argument (i.e., is of a different set
class, but has the same interval vector).  If the argument
to ZSET is not a z set, ZSET returns the null set.

-----

  mod12 > zset 24789ab
        0123568      t0    7-z36

  mod12 > vectors  24789ab  zset 24789ab

  SC     TnI   PCS           INTVEC       VTICS
  7-z12  t7    24789ab       444342       443444744434
  7-z36  t0    0123568       444342       245444546434

  mod12 > zset [c,d,e,f,g,a,b] ; not a z set
                     t0    0-1   ; not a z set

-----

The ZSET operator is sensitive to the current prime form
table (described below, or type HELP PRM2).

     N is a binary, infix operator, and returns the
intersection of its two arguments:

-----

  mod12 > [c,e,g] n [c,e-,g]
        07            t7    2-5

-----














                                       mod12 User Guide - 12

     U is a binary, infix operator, and returns the union of
its two arguments:

-----

  mod12 > [c,e,g] u [c,e-,g]
        0347          t0    4-17

-----

     SYMDIF is a binary, infix operator, and returns the
symmetrical difference of its two arguments (i.e., those pcs
in the union which are not part of the intersection):

-----

  mod12 > [c,e,g] symdif [c,e-,g]
        34            t3    2-1

-----

     NOT is a binary, infix operator, and returns the pcs of
its leftmost argument without the pcs of its rightmost
(i.e., the set difference of its arguments).  NOT is also a
boolean operator in some contexts; type HELP BOOLEAN for
details.  Unlike the other binary operators, NOT does not
commute:

-----

  mod12 > [c,e,g] not [c,e-,g]
        4             t4    1-1

  mod12 > [c,e-,g] not [c,e,g]
        3             t3    1-1

-----

     Pc set operators may be freely combined and nested
arbitrarily.  So long as an expression reduces to a single
set, it will be accepted wherever a set is expected:

-----

  mod12 > i t1 pf cmp zset op 0b29476583a1 t1 {01} u {3} u {56}
        24789ab       t7    7-z12

-----

     All operators are of equal precedence, and follow a
strict, recursive order of evaluation.  For unary operators,
the entire set expression to the right of the operator is













                                       mod12 User Guide - 13

first evaluated before applying the operator.  For binary
operators, the entire set expression to the left of the
operator is first evaluated, then the entire set expression
to the right of the operator is evaluated, and then the
operator is applied.  Ignoring this order of evaluation may
lead to unexpected results:

-----

  mod12 > t1 [0,2,4] u [0,2,4]
        135           t1    3-6

  mod12 > cmp [c#,e,g,a#] not cmp [c#,e,g,a#]
        0235689b      t2    8-28

-----

     Parentheses may be used to force a different order of
evaluation:

-----

  mod12 > ( t1 [0,2,4] ) u [0,2,4]
        012345        t0    6-1

  mod12 > ( cmp [c#,e,g,a#] ) not cmp [c#,e,g,a#]
                      t0    0-1

-----

     As with any mod12 expresssion, operators can be
assigned descriptive names with the MACRO command.  (More
complicated operators are defined as called macros, such as
the FIX-MIRROR function described above in the previous
section.)  For example, Lewin's inversion notation seems
more appropriate than Babbitt's in many contexts.
Accordingly:

-----

  mod12 > macro "I-c#/d" t3i

  mod12 > I-c#/d 01479
        2368b         t2    5-32

-----


PRM2, COMPACT, and CLIP-COMMENT

     You can change the way mod12 displays sets and their
associated comments with PRM2, COMPACT, and CLIP-COMMENT.













                                       mod12 User Guide - 14


     The PRM2 command determines whether mod12 will use the
primes from Forte (1973) or Rahn (1980) as a reference.  The
two systems coincide for the most part, but differ with
respect to set classes 5-20, 6-z29, 6-31, 7-z18, 7-20, and
8-26.  mod12 takes Forte's system as the default.  Here is
how PRM2 is used to change the referential prime form table:

-----

  mod12 > [c,d-,e-,g,a-]
        01378         t0    5-20

  mod12 > prm2 on                   /* ON means change to Rahn table */

  mod12 P > [c,d-,e-,g,a-]
        01378         t7    5-20

  mod12 P > [c,d-,f,g-,a-]
        01568         t0    5-20

  mod12 P > prm2 off                /* OFF means change to Forte table */

  mod12 > [c,d-,f,g-,a-]
        01568         t5    5-20

-----

The prompt changes after typing PRM2 ON to remind you that
Rahn's system is in force.  It reverts to the earlier form
after PRM2 OFF re-establishes Forte's system as the default.
Type HELP PRM2 for more details.

     COMPACT changes the way a set's pc contents are listed
in all mod12 displays.  In compact mode, pcs are listed in:

       - normal order, when the set is a transposition of
         the prime form; or

       - reversed normal order, when the set is an inversion
         of the prime form.

Generally, COMPACT listings conform to Friedmann's (1990,
43) "most compact order."  Compact mode is entered by typing
COMPACT ON, and left with COMPACT OFF.  The prompt changes
accordingly:

-----

  mod12 > [c#,b-,a]
        19a           t9    3-3














                                       mod12 User Guide - 15

  mod12 > compact on

  mod12 C > [c#,b-,a]                  ; *** N.B. ***
        9a1           t9    3-3

  mod12 C > [c#,c,a]                   ; *** N.B. ***
        109           t1i   3-3

  mod12 C > compact off

  mod12 > [c#,c,a]
        019           t1i   3-3

-----

COMPACT ordering makes it easy to compare at a glance
different forms of the same set class.  Above, the first pcs
in the two commented sets (9 and 1, respectively) sum to 10,
as do the second two (a and 0), and the third two (1 and 9).
The sets are thus related by t10i.

     COMPACT displays are influenced by the current PRM2
setting, since exactly what constitutes "normal order"
depends on which prime form table -- Rahn's or Forte's -- is
in force at the time:

-----

  mod12 C > { 1 2 4 6 7 9 A B } ; a la forte
        9ab12467      t9    8-26  ; a la forte

  mod12 C > prm2 on

  mod12 CP > { 1 2 4 6 7 9 A B } ; same set, a la rahn
        679ab124      t6    8-26  ; same set, a la rahn

-----

     Sets may have up to 200 characters of comment text
associated with them (type HELP COMMENT for details).
Normally, the full comment is displayed along with a set in
identifications such as those above.  This can result in
confusing and tedious displays when there are many long
comments.  CLIP-COMMENT changes the number of comment
characters shown in identification displays.  Its syntax is:

                    CLIP-COMMENT newSize

where newSize is an integer between 0 and 200, inclusive.
After calling CLIP-COMMENT, at most newSize characters per
comment will be displayed in identifications.  Only
identification display size is affected by CLIP-COMMENT; the













                                       mod12 User Guide - 16

comments themselves remain intact (type HELP CLIP-COMMENT
for more details).  For example, the null set is here
associated with a long comment, and automatically recorded
into the database (type HELP RECORD):

-----

  mod12 1 > [] ; I have completed the construction of my burrow and \
  it seems to be successful.  All that can be seen from the outside \
  is a big hole; that, however, really leads nowhere; if you take a \
  few steps you strike against natural firm rock.
  1                  t0    0-1   ; I have completed the construction o
  f my burrow and it seems to be successful.  All that can be seen fro
  m the outside is a big hole; that, however, really leads nowhere; if
  you take a few steps you st

  mod12 2 > clip-comment 20

  mod12 2 > show 1 ; this displays the record at slot #1...
  1                  t0    0-1   ; I have completed th

  mod12 2 > clip-comment 40 ; show a little more now...

  mod12 2 > show 1
  1                  t0    0-1   ; I have completed the construction o
  f my

-----


Integer Expressions, Arithmetic, and Functions

     mod12 integer expressions evaluate to whole numbers in
the range -32767 to 32767, inclusive.  Commas or other
punctuation are not used when representing simple integers;
thus, 32767 is a valid integer, while 32,767 is not.

     Arithmetic operators are used freely in integer
expressions.  They include negation, addition, subtraction,
multiplication, integer division (remainders discarded), and
modular reduction.  In general, the operators are
interpreted exactly in accordance with standard usage; type
HELP ARITHMETIC for a few examples.  The symbol listing
below assumes that n, n1, and n2 are all integer
expressions:

           - n    means zero minus n (unary negation).
        n1 + n2   means n1 plus n2.
        n1 - n2   means n1 minus n2.
        n1 * n2   means n1 times n2.
        n1 / n2   means the integral part of n1 divided by
                  n2.













                                       mod12 User Guide - 17

        n1 % n2   means n1 modulo n2.

An error is generated if the result of an arithmetic
operation is greater than 32767 or less than -32767.
Division by zero also generates an error, as does taking an
integer modulo 0.

     All operators are of equal precedence.  In unary
negation, the entire expression to the right of the minus
sign is evaluated before applying the negation.  For binary
operators, first the entire expression to the left of the
symbol is evaluated, and next the entire expression to the
right of the symbol; the operator is then applied to the
results of those evaluations.  Parentheses may be used to
alter the order of evaluation:

-----

  mod12 > display 3 * 2 + 1 /* no parentheses -- display the product \
                               of 3 times the sum of 2 plus 1       */
  9
  mod12 > display (3 * 2) + 1 /* yes parentheses -- display the sum of \
                               1 plus the product of 3 times 2        */
  7

-----

     mod12 includes several built-in functions which are
themselves integer expressions, and so may be mixed freely
with simple integers and arithmetic operators.  The
functions are listed below; type HELP followed by a function
name for more details.

     The integer function ABS returns the absolute value of
its argument:

-----

  mod12 > display "ABS(-5) = " abs -5 nl
  ABS(-5) = 5

-----

     CD and ORD split a Forte set name into its cardinal and
ordinal number components.  CD returns the cardinality of
its pc set argument, while ORD returns the ordinal number:

-----

  mod12 > display cd [0,1,4,7] n [0,4,7,9] nl ; i.e., cd [0,4,7]
  3














                                       mod12 User Guide - 18

  mod12 > display ord [0,1,4] nl ; i.e., the prime form of 3-3
  3

-----

     EMB, IEMB, and TEMB return embedding numbers, with each
taking two pc sets as arguments.  (EMB is reviewed in Lewin
1987, 105ff.)  EMB pcset1 pcset2 returns the number of
transpositions or inversions of pcset1 contained in pcset2;
IEMB pcset1 pcset2 returns the number of inversions of
pcset1 contained in pcset2; and TEMB pcset1 pcset2 returns
the number of transpositions of pcset1 contained in pcset2.
For example, there are five forms of [c,d-,e-] embedded in
[a,b,c,d,e-,f,g#], three transpositions and two inversions:

-----

  mod12 > display temb [c,d-,e-] [a,b,c,d,e-,f,g#] nl
  3

  mod12 > display iemb [c,d-,e-] [a,b,c,d,e-,f,g#] nl
  2

  mod12 > display emb [c,d-,e-] [a,b,c,d,e-,f,g#] nl
  5

-----

     TR pcset1 pcset2 returns the least, positive
transposition index N which maps pcset1 into pcset2; if no
such N exists, TR returns -1.  For example, [c,d-,e-] maps
into [a,b,c,d,e-,f,g#] under T2, T8, and T11; the least,
positive index is thus 2.  [c,e,g#] does not transpose at
all into [a,b,c,d,e-,f,g#]; TR's return in this case is thus
-1:

-----

  mod12 > display tr [c,d-,e-] [a,b,c,d,e-,f,g#] nl
  2

  mod12 > display tr [c,e,g#]  [a,b,c,d,e-,f,g#] nl
  -1

-----

     TALLY is a generic counting function which returns the
total number of database records or all possible sets which
meet specified criteria.  Its syntax is described later in
this guide (or type HELP TALLY).  For example, this command
displays the total number of primes in Forte's (1973, 96ff.)
Kh relation with both 5-10 and 6-z4:













                                       mod12 User Guide - 19


-----

  mod12 > display tally univ pr and kh 5-10 and kh 6-4 nl
  10

-----

     FIRSTREC, LASTREC, and NEXTREC return database slot id
numbers (described below, or type HELP DATABASE).  FIRSTREC
returns the number of the first occupied slot in the
database; LASTREC returns the number of the last occupied
slot in the database; and NEXTREC returns the number of the
next slot to be assigned in the database.  For example:

-----

  mod12 > show db                  /* SHOW DB displays the entire database */
  35    0134         t0    4-3   ; Greetings from slot 35 ...
  59    0123456789ab t0   12-1   ; ... and, last but not least

  mod12 > record at lastrec - 12   /* RECORD AT sets db insertion point */

  mod12 > display firstrec tab 5 lastrec tab 5 nextrec nl
  35   59   47

-----

(SHOW, RECORD, and DISPLAY are described below, or type HELP
SHOW, HELP RECORD, and HELP DISPLAY.)

     CHARSONLINE returns the number of characters displayed
on the current output line.  (Type HELP I/O for information
on mod12 output.)  In the example below, the first
CHARSONLINE evaluates to 3, the length of "ABC"; the second,
to 7, the length of "ABC3DEF"; and the third, to 0, since
nothing was displayed up to that point on the new line:

-----

  mod12 > display "ABC" charsonline "DEF" charsonline nl charsonline
  ABC3DEF7
  0

-----

     You can define your own integer functions with LOCAL
and CALL; type HELP CALL for details and an example.


Getting Information about Pitch-Class Sets














                                       mod12 User Guide - 20

     mod12 allows you to create and run scripts which are
custom-tailored to the precise requirements of your current
project.  Examples of such scripts appear throughout this
guide and in mod12's online help facility.

     But mod12 also includes several predefined scripts
which display information of general utility.  These scripts
are loaded automatically when a mod12 session starts (type
HELP PREDEF for details), and include VECTORS, COMMON-TONE,
EMBED, MAP, SUBSETS, and IS.

     VECTORS takes a list of sets as an argument.  For each
set S in the list, VECTORS displays an interval vector and a
VTICS (cf. Rahn 1980, 111-114: "vector of the TnI common-
note structure").  The first entry in the latter is the
cardinality of S-intersect-T0I(S); the second entry, the
cardinality of S-intersect-T1I(S); the third entry, the
cardinality of S-intersect-T2I(S); and so forth.  Any
letters a, b, and c in the vectors represent the integers
10, 11, and 12, respectively:

-----

  mod12 > vectors  5-z12    cmp 5-z12    7-1      \
                   [c,c#,d,d#,e,f,f#,g,g#,a,a#,b]

  SC     TnI   PCS           INTVEC       VTICS
  5-z12  t0    01356         222121       221222522212
  7-z12  t7    24789ab       444342       443444744434
  7-1    t0    0123456       654321       223456765432
  12-1   t0    0123456789ab  ccccc6       cccccccccccc

-----

     COMMON-TONE takes a list of set pairs as an argument.
For each successive pair of sets S1 and S2 in the list,
COMMON-TONE displays the common-note function vector of S1
over S2.  The first vector entry is the cardinality of
T0(S1)-intersect-S2; the second, of T1(S1)-intersect-S2; the
third, of T2(S1)-intersect-S2; and so forth:

-----

  mod12 > common-tone [0,1,2,4,7] cmp [0,1,2,4,7] 6-14 6-14

  SC 1   TnI   PCS           SC 2   TnI   PCS           CMNF VECTOR
  5-z36  t0    01247         7-z36  t11i  35689ab       033343334333
  6-14   t0    013458        6-14   t0    013458        632343034323

-----

     EMBED also takes a list of set pairs.  For each
successive pair of sets S1 and S2 in the list, EMBED












                                       mod12 User Guide - 21

displays the number of unique transpositions or inversions
of S1 which are literal subsets of S2; the number of
transpositions of S1 which are literal subsets of S2; and
the number of inversions of S1 which are literal subsets of
S2.  The following entry reviews Lewin's (1987, 106) EMB
example and Morris's (1987, 90) example of Lewin's COV:

-----

  mod12 > embed [ C, E, G ] [ C, D, E, F, G, A, B ] /* Lewin's EMB ex. */ \
                cmp 4-1 cmp 3-2         /* Morris's ex. of Lewin's COV */

  set 1 ----------           set 2 ----------           set 1 in set 2 ----
  SC     TnI   PCS           SC     TnI   PCS           TOTAL   TR      INV
  3-11   t7i   047           7-35   t11   024579b       6       3       3
  8-1    t4    456789ab      9-2    t11i  2456789ab     1       1       1

-----

     MAP takes a set-pair list as an argument, too.  For
each successive pair of sets S1 and S2 in the list, MAP
displays all Tn, TnI, TnM, and TnMI operations under which
S1 maps into S2:

-----

  mod12 > map   3-12 6-35   3-12 8-28   3-12 12-1

  Map 048 (t0 3-12) into 02468a (t0 6-35):
  t0    t2    t4    t6    t8    t10
  t0i   t2i   t4i   t6i   t8i   t10i
  t0m   t2m   t4m   t6m   t8m   t10m
  t0mi  t2mi  t4mi  t6mi  t8mi  t10mi

  Map 048 (t0 3-12) into 0134679a (t0 8-28):
  No Tn, TnI, TnM, or TnMI found.

  Map 048 (t0 3-12) into 0123456789ab (t0 12-1):
  t0    t1    t2    t3    t4    t5    t6    t7    t8    t9    t10   t11
  t0i   t1i   t2i   t3i   t4i   t5i   t6i   t7i   t8i   t9i   t10i  t11i
  t0m   t1m   t2m   t3m   t4m   t5m   t6m   t7m   t8m   t9m   t10m  t11m
  t0mi  t1mi  t2mi  t3mi  t4mi  t5mi  t6mi  t7mi  t8mi  t9mi  t10mi t11mi

-----

     SUBSETS takes two arguments: a list of single sets and
an optional test expression.  (Tests are described in the
next section; type HELP TESTS for general information.)
SUBSETS displays the names of all primes of at least two
elements which are proper, abstract subsets of each set in
the list; if the optional test expression is supplied, only
those mutual subsets for which the test holds true are













                                       mod12 User Guide - 22

acknowledged.  For example, this entry shows the types of
all mutual subsets of the diatonic and octatonic collections
which contain more than three elements, and which are not
invariant under inversion:

-----

  mod12 > subsets [c,d,e,f,g,a,b] cmp [0,3,6,9] cdg 3 and not isym

  4:   13   27   29

  5:   25

-----

     The IS command matches sets against arbitrary tests.
IS takes a single list as an argument, whose every even
element (zero-based) is a set expression, and every odd
element is a test expression.  For each successive set/test
pair in the list, IS simply displays the word "yes," if test
holds true for the set, or "no," otherwise.  For example,
this entry asks: first, whether 5-z12 types are z-related to
5-z36 types; second, whether 5-z12 types map into their
complements under transposition or inversion; and third,
whether 5-z36 types map into their complements under
transposition or inversion:

-----

  mod12 > is     5-12 z 5-36     5-12 cm      5-36 cm
  yes
  no
  yes

-----


Test Expressions and Boolean Operators

     mod12 includes a large number of built-in tests, which
are accepted as arguments in several commands and predefined
macros.  The tests are cataloged briefly in Appendix A at
the end of this guide, and described more fully in the
online HELP facility.  Type HELP ALLTESTS for a quick
overview of all tests, and type HELP followed by a test name
for more specific information.

     All tests return either true or false.  Most tests are
applied to "operand" sets or database records.  Exactly what
the operand set (or record) is in a given context depends on
the command.  For example, the pcset argument to the IS
macro mentioned earlier is an operand set, while every













                                       mod12 User Guide - 23

prime, mutual subset takes its turn as operand set in
SUBSETS.

     Most tests fall into one or another of these
categories:

                cardinality
                comment match
                complementation/complement mapping
                database membership
                embedding/inclusion
                set equivalence/invariance
                interval vector
                iteration priority
                macro match
                partitioning
                relation to prime forms
                set complex/genera
                subset/superset

Some overlap is apparent among these categories.  For
example, the entry at line 1 below tests whether [0,1,3,4]
has four elements.  So does the entry at line 2, in a
roundabout way, when it asks whether [0,1,3,4] has exactly
four notes in common with itself.  The entry at line 3 does,
too, when it asks whether exactly four unique transpositions
of C natural are embedded within [0,1,3,4]:

-----

  mod12 > is [0,1,3,4] cd 4             /* 1 */ \
             [0,1,3,4] cmn [0,1,3,4] 4  /* 2 */ \
             [c] temb [0,1,3,4] 4       /* 3 */
  yes
  yes
  yes

-----

Cardinality queries could be framed in many other ways, too,
but noting these other ways is not to dismiss the simple
cardinality test at line 1 as redundant.  Like all tests, it
is optimized for its advertised task; testing cardinality is
faster than calculating embedding numbers.  Also,
formulating a query is that much easier when a test conforms
closely to the intuition of the problem at hand.

     "Intuition" may seem an odd word in the context of
tests with names such as, e.g., "CMN," "TPR," "SC," or
"IINC."  mod12 test names are short, easily-typed mnemonics,
and are not intended to be especially evocative.  The MACRO
facility is always available, however, if you prefer
descriptive names:












                                       mod12 User Guide - 24


-----

  mod12 > macro "in-the-same-set-class-as" sc

  mod12 > is [0,1,2] in-the-same-set-class-as [1,2,3]
  yes

  mod12 > macro "a_major_triad?" tr [c,e,g]

  mod12 > Is [ d , f# , a ] a_major_triad?
  yes

  mod12 > Is [ d , f , a ] a_major_triad?
  no

-----

     Tests may be combined with the boolean operators AND,
OR, and NOT to form larger test expressions.  mod12 accepts
any such larger expression as a single test wherever a test
is expected.  Like single tests, larger test expressions
return either true or false.  The boolean operators are
interpreted as follows:

       t1 AND t2    returns true iff both test t1 and test
                    t2 are true.

       t1 OR  t2    returns true iff one or both of tests t1
                    and t2 are true.

       NOT t        returns true iff test t is false.

     Here are some sample boolean expressions used with IS.
The expressions can be as complicated as desired:

-----

  mod12 > is 4-1 cd 4 and isym ; isym = invariant under some TnI
  yes

  mod12 > is 4-1 cd 4 and tsym ; tsym = invariant under some Tn, n <> 0.
  no

  mod12 > is 4-1 cd 4 or tsym ; nb -- cd in this context is a test
  yes

  mod12 > is 4-1 not tsym
  yes

  mod12 > is 4-1 cd 1 or cd 2 or cd 3 or sc [c,c#,d,e-] ; sc = in same setclass
  yes













                                       mod12 User Guide - 25


  mod12 > is 4-1 not not not not eq {0123} and prtn ; prtn = Tn system prime
  yes

  mod12 > is 4-1 not not not eq {0123} and prtn
  no

-----

     As with pc set and integer operators, boolean operators
are all of equal precedence, and follow a strict, recursive
order of evaluation.  The entire test expression to the
right of unary NOT is first evaluated before applying the
negation.  For binary operators AND and OR, the entire test
expression to the left of the operator is first evaluated,
then the entire test expression to the right of the operator
is evaluated, and only then is the conjunction or
disjunction is applied.  In fact, AND and OR each evaluate
right-side expressions only if necessary: in the case of
AND, the right side is evaluated only when the left side is
true; and in the case of OR, the right side is evaluated
only when the left side is false.

     Ignoring the order of evaluation in boolean expressions
may lead to unexpected results; parentheses can force a
particular evaluation order in such cases.  For example, the
first entry below tests whether [0,1]: (1) is
transpositionally invariant (ignoring T0); AND (2a) either
contains five elements, OR (2b) is a literal subset of
[0,1,2].  Parentheses in the second entry change the
grouping of tests.  There, [0,1] is tested to see whether
it: (1a) is transpositionally symmetrical AND (1b) contains
five elements; OR (2) is a literal subset of [0,1,2]:

-----

  mod12 > is [0,1] tsym and cd 5 or lsb [0,1,2] ; no parens...
  no

  mod12 > is [0,1] ( tsym and cd 5 ) or lsb [0,1,2] ; yes parens...
  yes

-----

     Frequently used boolean test expressions are good
candidates for MACRO definition.  Generally, as in this
example, you should enclose test expression macro
definitions in parentheses to avoid unexpected precedence
problems when the macro is expanded:

-----














                                       mod12 User Guide - 26

  mod12 > macro "all-combinatorial-hex" (cd 6 and tcm and icm)

  mod12 > tally univ all-combinatorial-hex
  TALLY > Total tallied: 48
  6-1   :   12      6-7   :    6      6-8   :   12      6-20  :    4
  6-32  :   12      6-35  :    2

  mod12 > show univ pr and all-combinatorial-hex and not tsym
        012345        t0    6-1
        023457        t0    6-8
        024579        t0    6-32

-----

     More complicated macro test expressions may be defined
using LOCAL and CALL; type HELP CALL for an example.


The UNIV forms of SHOW and TALLY

    Several examples above have featured UNIV forms of SHOW
or TALLY.  The UNIV form of SHOW identifies and displays all
possible sets which conform to an optional group of
properties.  Its syntax is:

                SHOW UNIV < testExpression >

Angle brackets used in syntax forms like this indicate that
the bracketed expression is optional; when actually entering
an optional expression, the brackets are not used.  If the
optional testExpression is not specified, SHOW displays all
4,096 pitch-class sets (including the null set).
Fortunately, any long, unwanted mod12 display can be
interrupted with the system break key sequence -- e.g.,
Ctrl-C in DOS:

-----

  mod12 > show univ ; will show 4,096 sets
                      t0    0-1
        0             t0    1-1
        1             t1    1-1
        2             t2    1-1
        3             t3    1-1
        4             t4    1-1
        5             t5    1-1
        6             t6    1-1
        7             t7    1-1
        8             t8    ^C

  -- USER BREAK --














                                       mod12 User Guide - 27

  mod12 > show univ pr ; will show all prime forms
                      t0    0-1
        0             t0    1-1
        01            t0    2-1
        02            t0    2-2
        03            t0    2-3
        04            t0    2-4
        05            t0    2-5
        06            t0    2-6
        012           t0    3-1
        013           t0    3-2
        014           ^C    3-3

  -- USER BREAK --

  mod12 >

-----

     Notice the order in which mod12 systematically iterates
through the pc set universe in these examples.  All sets are
considered in (extended) Forte set name order: first, the
null set; then, all forms of 1-1; then, all forms of 2-1, 2-
2, etc.; then, all forms of 3-1, 3-2, etc.; and so forth up
to 12-1.  Within that order scheme, all transpositions of
the prime form are considered in ascending T order, starting
with T0, and then all inversions are considered in ascending
T order, starting with T0.  This general iteration order is
fixed for all mod12 commands which cover the pc set
universe, although switching prime form tables with PRM2
produces the expected changes.

     Often, a long display that we do want to keep spills
over from one screen to another.  Say our concern is with
all sets embedded exactly four times in 9-11, and which
include exactly four instances of 3-11:

-----

  mod12 > show univ emb 9-11 4 and inc 3-11 4
        013458        t0    6-14
        124569        t1    6-14
        23567a        t2    ^C

  -- USER BREAK --

-----

Ninety-six sets meet these criteria, so the complete display
will not fit on the screen.  One way around this problem is
through the WRITE command, which reroutes all console output
to a file; another way is to use LOG to echo the display to













                                       mod12 User Guide - 28

a file.  If you are working in a multi-tasking environment,
the file can then be viewed immediately by loading it into
any text editor.  WRITE and LOG are described later in this
guide; or type HELP WRITE and HELP LOG.

     The UNIV form of the TALLY command helps in cases where
a quick overview is all that is needed in response to a
query regarding the pc set universe.  Its syntax is similar
to that of SHOW:

               TALLY UNIV < testExpression >

This form displays the set-class distribution of all
possible operand sets for which testExpression is true.  As
with SHOW, the testExpression is optional; if absent, all
4,096 possible pc sets are tallied.

     Recasting our last example now with TALLY:

-----

  mod12 > tally univ emb 9-11 4 and inc 3-11 4
  TALLY > Total tallied: 96
  6-14 : 24      6-z19 : 24      6-31 : 24      6-z44 : 24

-----

Since the EMB and INC tests are based on abstract inclusion,
all forms of 6-14, 6-z19, 6-31, and 6-z44 meet the
specification, and so all forms are tallied, giving a total
of ninety-six.  After testing the waters with this TALLY, we
can refine our original SHOW request for a more cogent
display:

-----

  mod12 > show univ emb 9-11 4 and inc 3-11 4 and pr
        013458        t0    6-14
        013478        t0    6-z19
        013589        t0    6-31
        012569        t0    6-z44

-----

     TALLY may be used, with the same syntax, as an integer
function.  It displays nothing in such contexts, but merely
returns an integer representing the tally total:

-----

  mod12 > display nl "The octatonic collection can be partitioned into " \
                     "inversionally or " nl "transpositionally related " \













                                       mod12 User Guide - 29

                     "tetrachords from "                                 \
                     tally univ cd 4 and pr and gen 8-28 /* <--- N.B. */ \
                     " different set classes." nl

  The octatonic collection can be partitioned into inversionally or
  transpositionally related tetrachords from 11 different set classes.

-----

     As with the FOR command described in the next section,
forms of SHOW and TALLY are available for iterating through
a user-supplied database of sets.  Those forms are discussed
later in this guide; type HELP SHOW and TALLY for more
details.


Iteration and Conditional Execution with FOR

     SHOW only displays each set it identifies.  What if
something more were required, such as displaying an interval
vector along with each identification?  The FOR command
provides a more general iteration capability to handle
situations like this.  For example,

-----

  mod12 > for univ pr and emb 9-11 4 and inc 3-11 4 \
            display nl name ?u0 tab 10 iv ?u0

  6-14      323430
  6-z19     313431
  6-31      223431
  6-z44     313431

-----

     FOR commands afford a great deal of flexibility.  The
next example generates TnI trichord vectors for all TnI
hexachord types.  Only part of the display is shown here
(DISPLAY and SEQ are described below):

-----

  mod12 > for univ cd 6 and pr                     /* 1 */ \
            seq : display nl name ?u0 ":" tab 10   /* 2 */ \
                : for univ cd 3 and pr             /* 3 */ \
                    display emb ?u1 ?u0 tab 5      /* 4 */

  6-1:      4    6    4    2    0    2    2    0    0    0    0    0
  6-2:      3    5    3    1    1    2    2    2    0    1    0    0
  6-z3:     2    4    3    3    2    1    3    1    0    1    0    0
  ^C













                                       mod12 User Guide - 30


  -- USER BREAK --

-----

Just a little more code now will generate Tn trichord
vectors for all Tn hexachord types.  The extra code is
needed to qualify the names of Tn primes which are not also
Tn/TnI primes; thus, lines 2 through 4 below correspond to
line 2 in the preceding example:

-----

mod12 > for univ cd 6 and prtn               /* 1 */ \
          seq : display nl name ?u0          /* 2 */ \
              : for ?u0 not pr display "a"   /* 3 */ \
              : display ":" tab 9            /* 4 */ \
              : for univ cd 3 and prtn       /* 5 */ \
                  display temb ?u1 ?u0 tab 3 /* 6 */

6-1:     4  3  3  2  2  1  1  0  0  2  1  1  0  0  0  0  0  0  0
6-2:     3  3  2  2  1  1  0  1  0  2  1  1  1  1  0  1  0  0  0
6-2a:    3  2  3  1  2  0  1  0  1  2  1  1  1  1  0  1  0  0  0
6-z3:    2  2  2  2  1  2  1  1  1  1  2  1  1  0  0  1  0  0  0
6-z3a:   2  2  2  1  2  1  2  1  1  1  1  2  0  1  0  1  0  0  0
^C

-- USER BREAK --

-----

(Long mod12 entries such as those in the two previous
examples are best composed in a favorite text editor, and
then loaded into mod12 using the READ command.  READ is
described below, or type HELP READ.)

     The syntax for the UNIV form of FOR is,

        FOR UNIV < testExpression > < promptString >

The optional argument "promptString" here, and in other
syntax forms below, stands for any string that would be
accepted as input at the mod12 > prompt.  This form
exhaustively iterates through the pc set universe,
considering each set S in turn as the implied operand set
for testExpression.  If the test returns true, FOR performs
these three steps in order:

       1, it defines a special macro which expands to a pc
          digit representation of S in curly brackets;















                                       mod12 User Guide - 31

       2, it submits promptString to mod12 for evaluation,
          exactly as if it had been entered manually at the
          mod12 prompt; and

       3, it undefines the special macro defined in step 1.

The special macro is named by a string comprised of the
characters "?u" followed by a single digit representing the
FOR "nesting" level.  All instances of the special macro
name in promptString are expanded immediately before mod12
evaluates the string.  (The TRACE command may be used to spy
on this behind-the-scenes activity in all FOR forms; TRACE
is described below, or type HELP TRACE.)

     Any valid mod12 expression at all may serve as
promptString -- for example, a set for identification, a
call to a database command, a call to TALLY, or even another
FOR command.  When one FOR command calls another in its
promptString, the second FOR is "nested" within the first,
and has a "nesting level" number which is one greater than
the first.  In any string entered at the mod12 prompt, the
first FOR is at level 0; the second, level 1; the third,
level 2; and so forth up to level 9 (the FOR nesting level
limit).  These level numbers are included in the special
macro names: level 0 defines the macro ?u0; level 1, ?u1;
level 2, ?u2; etc.  (The LOCAL command temporarily resets
the current nesting level to zero.  LOCAL is described later
in this guide; type HELP LOCAL for more details.)

     Many set-theoretical tasks can be approached through
nested FOR commands.  The trichord vector examples above
typify one class of such tasks; partitioning problems typify
another.  Say we wish to exhaustively partition the
aggregate into three non-symmetrical sets: a trichord, a
tetrachord, and a prime-form pentachord.  The pentachord
must include at least one transposition of the tetrachord,
which must in turn include at least one transposition of the
trichord.  Here is one of many ways this can be accomplished
through nested FOR commands:

-----

  mod12 > for univ cd 5 and pr and not isym                               /* 1 */ \
            for univ cd 4 and lsb cmp ?u0 and tsb ?u0 and not isym        /* 2 */ \
              for univ cd 3 and eq cmp ?u0 u ?u1 and tsb ?u1 and not isym /* 3 */ \
                display nl pcs ?u0 " (" name ?u0 ")" tab 20               /* 4 */ \
                        pcs ?u1 " (" name ?u1 ")" tab 20                  /* 5 */ \
                        pcs ?u2 " (" name ?u2 ")"                         /* 6 */

  01236 (5-4)         457a (4-13)         89b (3-2)
  01346 (5-10)        289b (4-13)         57a (3-7)
  01347 (5-16)        28ab (4-12)         569 (3-3)













                                       mod12 User Guide - 32

  01367 (5-19)        289b (4-13)         45a (3-5)
  01367 (5-19)        2589 (4-18)         4ab (3-5)
  02358 (5-25)        14ab (4-13)         679 (3-2)
  01368 (5-29)        457a (4-13)         29b (3-7)
  01469 (5-32)        358b (4-27)         27a (3-11)
  01247 (5-z36)       568b (4-13)         39a (3-5)

-----

All of the "real" work gets done in lines 1 through 3; the
remaining lines only format the display.  Everything from
line 2 on is the level 0 promptString; everything from line
3 on is the level 1 promptString; and everything from line 4
on (i.e., the entire DISPLAY expression) is the level 2
promptString.

     Efficiency is always an issue when using nested loops,
and especially so with interpreters like mod12.  All
statements manually or automatically submitted to mod12 must
be parsed before evaluation.  Since parsing takes time,
limiting the number and size of automatically submitted
statements will almost certainly speed things up.

     The greatest gains in efficiency come when you place
strong restrictions on sets tested at lower nesting levels,
since that cuts back on the number of times higher level
promptStrings are submitted for evaluation.  Eliminating
unnecessary tests can also help.  For instance, it was not
really necessary to test cardinality in line 3 of our most
recent example, since the complement of ?u0 and ?u1 at that
point is guaranteed to be three.

     Our example could be further improved by using another
form of FOR:

       FOR pcSet < testExpression > < promptString >

This form does not iterate, but simply considers pcSet as
the operand set to testExpression.  Its behavior is
otherwise exactly like that of the UNIV form discussed
above.  Returning to our partitioning example now, line 3
could be replaced with:

-----

  [ ... ]

  for cmp ?u0 u ?u1 and tsb ?u1 and not isym /* 3 */

  [ ... ]

-----













                                       mod12 User Guide - 33


We are really interested in exactly one set by the time we
reach line 3, and that is the complement of ?u0 and ?u1.
The suggested replacement could therefore eliminate 4,096
unnecessary tests.

     The pcset form of FOR is also useful for efficient self
reference.  For example, say we want to identify every prime
form which contains exactly seven transposed or inverted
forms of its complement.  The most efficient way to do this
is with the pcset form of FOR:

-----

  mod12 > for univ pr              /* 1 */ \
            for ?u0 inc cmp ?u0 7  /* 2 */ \
              ?u0                  /* 3 */
        01234568     t0    8-2
        0123568a     t0    8-22
        012345678    t0    9-1
        01234568a    t0    9-6
        01235678a    t0    9-9

-----

Only 4,096 sets are actually iterated over in this example,
and only 224 of those (i.e., the primes of cardinalities
zero through twelve) cause the second line to be evaluated.
Had we instead used the UNIV form of FOR at line two, like
this:

-----

  mod12 > for univ pr                          /* 1 */ \
            for univ eq ?u0 and inc cmp ?u0 7  /* 2 */ \
              ?u0                              /* 3 */

-----

we would have obtained the same results, but only after
iterating over 4,096 + (224 x 4,096) = 921,600 sets.

     The integer form of FOR can also boost efficiency in
some cases.  Its syntax is:

               FOR INT n1 n2 < promptString >

where n1 and n2 are integer expressions.  No test expression
is accepted in this form.  For each integer N in the range
n1 to n2, inclusive, this form:

       1, defines a special macro which expands to the
          integer N












                                       mod12 User Guide - 34


       2, submits promptString to mod12 for evaluation,
          exactly as if it had been entered manually at the
          mod12 prompt; and

       3, undefines the special macro defined in step 1.

If n1 is less than n2, N increases through the iteration; if
n1 is greater than n2, N decreases.  The special macro is
named by a string comprised of the characters "?i" followed
by a single digit representing the FOR nesting level.  All
instances of the special macro name in promptString are
expanded immediately before mod12 evaluates the string.

     Say that we want now to identify the intersection of
[0,1,4,7] and its Nth transpose, where N ranges from 0 to
11.  Using the univ form of FOR:

-----

  mod12 > for univ tpr and sc [0,1,4,7]                     \
            display "At " tni ?u0 ":" tab 10 ?u0 n [0,1,4,7]
  At t0:          0147         t0    4-18
  At t1:          1            t1    1-1
  At t2:                       t0    0-1
  At t3:          47           t4    2-3
  At t4:          4            t4    1-1
  At t5:          0            t0    1-1
  At t6:          17           t1    2-6
  At t7:          7            t7    1-1
  At t8:          0            t0    1-1
  At t9:          14           t1    2-3
  At t10:                      t0    0-1
  At t11:         0            t0    1-1

-----

4,096 sets are iterated over in the first line just to
identify the transposes of interest.  Here is the same
problem now formulated with the INT form of FOR:

-----

  mod12 > for int 0 11                                                  \
            display "At t" ?i0 ":" tab 10 (t ?i0 [0,1,4,7]) n [0,1,4,7]
  At t0:          0147         t0    4-18
  At t1:          1            t1    1-1
  At t2:                       t0    0-1
  At t3:          47           t4    2-3
  At t4:          4            t4    1-1
  At t5:          0            t0    1-1
  At t6:          17           t1    2-6













                                       mod12 User Guide - 35

  At t7:          7            t7    1-1
  At t8:          0            t0    1-1
  At t9:          14           t1    2-3
  At t10:                      t0    0-1
  At t11:         0            t0    1-1

-----

This iterates only over the integers 0 through 11, each of
which serves in turn as a transposition index in a DISPLAY
string set expression.  As a bonus, this formulation will
work as advertised for any set, even those with special
transpositional symmetries, such as [0,4,8]; the UNIV
formulation, of course, would not recognize twelve
transposes of such sets.


Chaining Commands with SEQ

     SEQ groups an arbitrary number of mod12 commands
together in a single expression.  Its syntax is,

               SEQ delimChar promptStringList

where delimChar is any non-whitespace character, and
promptStringList is an arbitrary number of valid mod12 >
prompt entries delimited by delimChar.  Each prompt entry is
submitted to mod12, one after another, in the order in which
it appears in promptStringList.

     Here are some examples using SEQ:

-----

  mod12 > seq , prm2 on , compact on

  mod12 CP > seq / prm2 off / compact off

  mod12 > seq + 6-19 + zset 6-19 + show univ cd 5 and        \
                                             pr and          \
                                             asb 6-19 and    \
                                             asb zset 6-19
        013478        t0    6-z19
        012569        t0    6-z44
        01458         t0    5-21
        01478         t0    5-22

-----

The first SEQ command uses the comma as its delimChar, and
turns both PRM2 and COMPACT on, in that order; while the
second uses the slash as its delimChar, and turns both PRM2













                                       mod12 User Guide - 36

and COMPACT off, in that order.  The plus sign is the
delimChar in the third SEQ command, which requests that
first 6-z19, and then the Z relative of 6-z19, be
identified, and also that all prime, pentachordal, abstract
subsets common to the two hexachords be shown.

     SEQ makes it possible for FOR commands to execute more
than one command per successful iteration.  For example, say
we want to identify the types of all tetrachords comprising
a triad decorated by an abstract "neighbor note" a semitone
away from the root, third, or fifth.  Each line of the
display should show the name of the tetrachordal set class
along with all relevant partitionings.  One of many ways to
do this with SEQ appears below.  The tetrachords are "out of
order" here because they arise through construction, not
iteration:

-----

  mod12 > for univ cd 1 and lsb t1 3-11 or lsb t11 3-11          /* 1 */ \
            seq + macro "TET" (pf ?u0 u 3-11)                    /* 2 */ \
                + display nl name TET                            /* 3 */ \
                + for univ sc 3-11 and lsb TET                   /* 4 */ \
                    display tab 15 pcs ?u1 " | " pcs TET not ?u1 /* 5 */

  4-z29          037 | 1
  4-14           037 | 2
  4-17           037 | 4        047 | 3
  4-18           047 | 1
  4-20           058 | 1        158 | 0
  4-19           148 | 0

-----

The level 0 FOR command at line 1 calls a SEQ expression
with three commands in its promptStringList at lines 2
through 5.  The MACRO definition at line 2 is not really
necessary, but makes the entire command a little easier to
read.  Line 3 displays the name of the tetrachord, after
which the level 1 FOR command at lines 4 and 5 prints out
the partitions.

     SEQ commands may be nested, a useful feature when
generating special displays.  The next example lists
trichordal and tetrachordal subsets of all pentachords,
although only the display for 5-1 is shown below.  The first
column in the display names the pentachords; the second
column, the tetrachords in the corresponding pentachord; and
the third column, the trichords in the corresponding
tetrachords.  When nesting one SEQ command within another,
make sure that their respective delimChars differ.  Below,
the enframing SEQ of lines 2 through 7 uses the colon as its













                                       mod12 User Guide - 37

delimChar; the nested SEQ of lines 4 through 7 uses the
comma:

-----

  mod12 > for univ cd 5 and pr                              /* 1 */ \
            seq : display nl tab 10 name ?u0                /* 2 */ \
                : for univ cd 4 and pr and asb ?u0          /* 3 */ \
                    seq , display tab 20 name ?u1           /* 4 */ \
                        , for univ cd 3 and pr and asb ?u1  /* 5 */ \
                            display tab 30 name ?u2 nl      /* 6 */ \
                        , display nl                        /* 7 */

            5-1       4-1       3-1
                                3-2

                      4-2       3-1
                                3-2
                                3-3
                                3-6

                      4-3       3-2
                                3-3
  ^C

  -- USER BREAK --

-----


BREAK'ing Chains and Loops

     BREAK is used to immediately stop pending processing in
various command contexts.  Three forms are available.

     This form applies to FOR commands:

            BREAK nestingLevel < promptString >

where the optional nestingLevel argument is an integer
expression valued between 0 and 9, and the promptString
expression is any valid mod12 command.  First, BREAK submits
promptString to mod12 for evaluation, exactly as if it had
been entered manually at the mod12 prompt.  Once that
evaluation is complete, BREAK then immediately aborts all
processing in all active FOR commands whose nesting levels
are greater than or equal to nestingLevel.

     For example, this form is handy in cases where interest
lies only in whether any set exists to meet certain
criteria.  Say we wanted a list of prime-form octads which
can be partitioned into two, non-symmetrical tetrachords of













                                       mod12 User Guide - 38

the same type, one of which is an inversion of the other.
Here is one of many ways to accomplish that:

-----

  mod12 > for univ cd 8 and pr                        /* 1 */ \
            for univ cd 4 and lsb ?u0 and not isym    /* 2 */ \
              for ?u0 not ?u1 inv ?u1                 /* 3 */ \
                break 1 ?u0                           /* 4 */
        01234567     t0    8-1
        01235678     t0    8-6
        01234589     t0    8-7
        01236789     t0    8-9
        02345679     t0    8-10
        01345689     t0    8-17
        01245789     t0    8-20
        0123578a     t0    8-23
        0124568a     t0    8-24
        0134679a     t0    8-28

-----

All of these octads can be partitioned according to the
specifications in more than one way, and some admit more
such partitionings than others.  The BREAK in line 4 above
locks us into a single partitioning for each case, ensuring
that no prime form is displayed more than once in the list.
It does that by aborting the level 1 FOR loop at line 2,
which provides candidate tetrachords for the partitions.

     Another form applies to SEQ commands:

                   BREAK < promptString >

First, BREAK submits the optional promptString to mod12 for
evaluation, exactly as if it had been entered manually at
the mod12 prompt.  Once that evaluation is complete, BREAK
immediately aborts all processing in the current SEQ chain.
The "current SEQ chain" is that containing the BREAK as a
command in its promptStringList argument (type HELP SEQ).

     This form of BREAK can be used to emulate the if-then-
elseif structures of conventional programming languages.
Cases involving mutually exclusive conditions are usually
best handled through this technique.  For example, Forte's
(1973, 48ff.) R0, R1, and R2 interval vector "similarity"
relations are mutually exclusive.  The following example
defines a macro procedure "Rn," which takes two sets as
arguments, and displays which of those relations, if any,
holds between the two sets.  If R0 holds in line 3, that
relation is displayed and the enframing SEQ chain is broken,
so that lines 4 through 6 are never processed:













                                       mod12 User Guide - 39


-----

  mod12 > macro "Rn?_"                                  /* 1 */ \
            local "s1" set "s2" set                     /* 2 */ \
              seq > for s1 r0 s2 break display "R0" nl  /* 3 */ \
                  > for s1 r1 s2 break display "R1" nl  /* 4 */ \
                  > for s1 r2 s2 break display "R2" nl  /* 5 */ \
                  > display "No Rn similarities!" nl    /* 6 */

  mod12 > macro "Rn?" call "Rn_" ; a "wrapper" -- type HELP CALL

  mod12 > rn? 5-1 5-6 ; this BREAK's at line 3
  R0

  mod12 > rn? 5-1 5-35 ; this BREAK's at line 4
  R1

  mod12 > rn? 5-1 5-2 ; this BREAK's at line 5
  R2

  mod12 > rn? 5-1 5-3 ; this makes it all the way to line 6
  No Rn similarities!

-----

     The remaining form of BREAK stops all processing in any
command context.  Its syntax is:

              BREAK TOPLEVEL < promptString >

First, BREAK submits the optional promptString to mod12 for
evaluation, exactly as if it had been entered manually at
the mod12 prompt.  Once that evaluation is complete, BREAK
immediately aborts all processing, and returns control to
the mod12 > prompt.

     This form is most useful for exiting deeply nested
macro procedures and functions; type HELP BREAK for an
example.


Debugging with TRACE

     As mod12 commands become larger and more complicated,
they grow increasingly susceptible to lapses in orthography,
syntax, and logic.  Tracking down the source of an error is
often frustrating, since so much goes on behind the scenes,
such as special macro assignments, conditional executions,
and so forth.

     TRACE helps by revealing the hidden activity.  Its
syntax is:












                                       mod12 User Guide - 40


              TRACE < onOff > < promptString >

where promptString is any mod12 command.  The optional onOff
argument is either one of the tokens, ON or OFF; omitting
onOff has the same effect as TRACE ON.

     TRACE turns mod12's trace facility on or off, submits
promptString to mod12 for evaluation, and then restores the
trace facility to its original state.  When the trace
facility is on, all commands are displayed on the screen
immediately prior to their evaluation.  All macros in those
commands are fully expanded, including the special macros
automatically defined by FOR.  The displayed commands are
also preceded by additional debugging information.

     For example, here is a TRACE'd FOR command which
displays the names of z tetrachord classes:

-----

  mod12 > trace on for univ cd 4 and pr and az display name ?u0 nl

  TRACE 1 / 0 > for univ cd 4 and pr and az display name ?u0 nl

  TRACE 2 / 0 / 0 > display name {0146} nl
  4-z15

  TRACE 2 / 0 / 0 > display name {0137} nl
  4-z29

-----

Each line starting with the word "TRACE" was displayed by
the TRACE facility. The first traced line is the entire FOR
command; at this point, the special macro ?u0 has not been
defined, so no expansion is shown.  The second traced line
is the DISPLAY command submitted by FOR when the prime form
of 4-z15 passed the CD 4 AND PR AND AZ test.  As the test
succeeded, ?u0 was defined to the pcs of that set, {0146};
thus, ?u0 is replaced by its expansion in the second traced
line.  Similarly, the third traced line is the DISPLAY
command submitted by FOR when the prime form of 4-z29 passed
the test.  As the test succeeded, ?u0 was defined to the pcs
of that set, {0137}; thus, ?u0 is now replaced by {0137} in
the third traced line.

     Preceding each traced command are at least two, and
sometimes three, numbers.  These numbers represent various
processing levels:















                                       mod12 User Guide - 41

               TRACE    P     /    S    /    N     >
                        |          |         |
                      mod12      LOCAL      FOR
                     parsing    scoping   nesting
                      level      level     level

P, the mod12 parsing level, is an indication of how deeply
nested the current command structure is.  Commands entered
manually at the mod12 > prompt are parsed at level 0;
commands automatically submitted by level 0 commands are
parsed at level 1; commands automatically submitted by level
1 commands are parsed at level 2; and so forth.

     For example, the first command below (TRACE) is
manually submitted at P=0; the next command (FOR) is
automatically submitted by that TRACE, so P=1; and the third
command (DISPLAY) is automatically submitted by that FOR, so
P=2:

-----

  mod12 > trace on for univ cd 4 and pr and az display name ?u0 nl

  TRACE 1 / 0 > for univ cd 4 and pr and az display name ?u0 nl

  TRACE 2 / 0 / 0 > display name {0146} nl
  4-z15^C

  -- USER BREAK --

-----

S, the LOCAL scoping level, shows how deeply nested the
current macro scope is.  Scoping is affected by the LOCAL
command (described below, or type HELP LOCAL).  N, the FOR
nesting level, shows the FOR nesting level in the current
scope.  The last command (DISPLAY) in the preceding example
was automatically submitted within the context of a FOR
command at nesting level 0, so N=0 in the trace display.  If
no FOR command is executing in the current scope, N is not
shown in the trace.

     TRACE OFF excludes a section of code from a trace.  For
example, some mod12 procedures such as SUBSETS are actually
predefined macros (type HELP PREDEF).  If you are tracing a
command which invokes SUBSETS, all of the commands within
SUBSETS would also appear in the trace.  Here is a TRACE'd
FOR command which displays subsets of cardinality greater
than two for each prime hexachord:

-----














                                       mod12 User Guide - 42

  mod12 > trace on                                          \
            for univ pr and cd 6                            \
              seq : display nl nl "Subsets of " name ?u0 nl \
                  : subsets ?u0 cdg 2

  TRACE 1 / 0 > for univ pr and cd 6 seq : display nl nl "Subsets of " name ?u0
   nl : subsets ?u0 cdg 2

  TRACE 2 / 0 / 0 > seq : display nl nl "Subsets of " name ?u0 nl : subsets ?u0
   cdg 2

  TRACE 3 / 0 / 0 > display nl nl "Subsets of " name {012345} nl


  Subsets of 6-1

  TRACE 3 / 0 / 0 > fence call "subsets_" {012345} cdg 2

  TRACE 4 / 0 / 0 > call "subsets_" {012345} cdg 2

  TRACE 5 / 1 > seq $ call "buildTest1" args $ for { } not mac "builtTest" " as
  b " error "SUBSETS syntax: " mac "args" $ for univ cdg 1 and pr and (builttes
  t ) seq : for { } intgt cd ?u0 lastcard seq % for { } intgt lastcard 0 displa
  y nl % display nl cd ?u0 ":" tab 5 % macro build "lastCard" cd ?u0 : for { }
  inteq charsonline 70 display nl tab 5 : display ord ?u0 tab 5 $ display nl

  TRACE 6 / 1 > call "buildTest1" {012345} cdg 2

  TRACE 7 / 2 > seq $ for { } maceq "s" "" break fence call "buildTest2" r $ ma
  cro build "builtTest" mac "builtTest" " and asb " mac "s" $ call "buildTest1"
   r

  TRACE 10 / 3 > for { } maceq "s" "" break fence call "buildTest2" r

  TRACE 11 / 3 / 0 > break fence call "buildTest2" r

  TRACE 12 / 3 / 0 > fence call "buildTest2" r

  TRACE 13 / 3 / 0 > call "buildTest2" cdg 2
  ^C

  -- USER BREAK --

-----

At the fifth traced line, SUBSETS ?u0 is replaced by its
expansion, CALL "SUBSETS_" {012345}.  SUBSETS_ itself is a
macro procedure, defined as a LOCAL command whose
promptString is the SEQ chain revealed as the sixth traced
line above.  Each command in that chain is then traced.
Those commands in turn invoke still other macro procedures,
whose commands are also traced.  Were it not interupted here













                                       mod12 User Guide - 43

with a break-key press, this would be a very long trace
indeed.

    The inner workings of SUBSETS are unlikely to be of much
interest during debugging, so tracing should be turned off
for that call:

-----

  mod12 > trace on                                          \
            for univ pr and cd 6                            \
              seq : display nl nl "Subsets of " name ?u0 nl \
                  : trace off subsets ?u0

  TRACE 1 / 0 > for univ pr and cd 6 seq : display nl nl "Subsets
  of " name ?u0 nl : trace off subsets ?u0

  TRACE 2 / 0 / 0 > seq : display nl nl "Subsets of " name ?u0 nl : trace off s
  ubsets ?u0

  TRACE 3 / 0 / 0 > display nl nl "Subsets of " name {012345} nl


  Subsets of 6-1

  TRACE 3 / 0 / 0 > trace off fence call "subsets_" {012345}

  2:   1    2    3    4    5

  3:   1    2    3    4    6    7

  4:   1    2    3    4    7    10   11

  5:   1    2    3

  TRACE 2 / 0 / 0 > seq : display nl nl "Subsets of " name ?u0 nl : trace off s
  ubsets ?u0
  ^C

  -- USER BREAK --

-----

Without the break-key interuption, this too would be a long
trace, even while excluding the unwanted display of SUBSETS
commands.  Usually, it is best to log a trace, or write it
to a file.  (LOG and WRITE are described below, or type HELP
LOG and HELP WRITE.)  The resulting "autopsy" file can then
be reviewed afterwards in any text editor.


Formatting Text with DISPLAY













                                       mod12 User Guide - 44


     Rudimentary text formatting options are available
through the DISPLAY command.  DISPLAY prints out the items
in an expression list according to user specifications.  As
shown later in this guide, the DISPLAY syntax is also used
to construct macros on the fly (type HELP MACRO), which you
can then submit manually or automatically to mod12 for
evaluation.

     The DISPLAY syntax is,

                   DISPLAY < expressionList >

where expressionList comprises zero or more items.  Each
item falls into one of the categories below:

       - An integer expression, displayed as an integer.

       - A pcset expression, which displays the set in the
         standard mod12 format.

       - A string enclosed in quotes, which is displayed
         without quotes.

       - A format token, which may be any of the following:

         PCS   followed by a pc set expression, which
               displays only the pitch classes of the
               specified set (pc digits, no braces).

         TNI   followed by a pc set expression, which
               displays only the relationship to the prime
               form of the specified set.

         NAME  followed by a pc set expression, which
               displays only the set-class name of the
               specified set.

         REC   followed by an (integer expression) record
               id, which displays the record stored at the
               specified record id in the standard mod12
               format.

         CMNT  followed by an optional (integer expression)
               record id, which displays only the comment
               from the record stored at the specified
               record id.  A missing integer argument causes
               the current comment to be displayed (type
               HELP COMMENT).

         IV    followed by a pc set expression, which
               displays the interval vector of the specified
               set.












                                       mod12 User Guide - 45


         CMNF  followed by two pc set expressions, S1 and
               S2, which displays the common-tone function
               vector of S1 over S2 (type HELP COMMON-TONE
               for more information).

         MAC   followed by a quoted macro name, which
               displays the expansion of the specified
               macro; if the named macro is undefined,
               nothing is displayed.

         HEAD  followed by a quoted macro name (NM) and a
               quoted pattern string (PAT).  This format
               displays all characters in the expansion of
               NM up to, but not including, the first
               instance of a character included in PAT.  The
               match is case-insensitive, and applies even
               to quoted characters in the expansion.  An
               apostrophe in PAT will match an apostrophe or
               quotation mark in the expansion.  If no PAT
               character appears in the expansion, the
               entire expansion is displayed.

         TAIL  followed by a quoted macro name (NM) and a
               quoted pattern string (PAT).  This format
               displays all characters in the expansion of
               NM which immediately follow the first
               instance of a character included in PAT.  The
               match is case-insensitive, and applies even
               to quoted characters in the expansion.  An
               apostrophe in PAT will match an apostrophe or
               quotation mark in the expansion.  If no PAT
               character appears in the expansion, no
               characters are displayed.

         QU    which is displayed as a quotation mark.

         TAB   immediately followed by an integer expression
               evaluating to n, which causes DISPLAY to
               behave as if tab stops were set at every n
               characters in the line, and that it is now to
               advance to the next tab stop.  Cf. the
               integer function, CHARSONLINE; type HELP
               INTEGER.

         NL    which causes DISPLAY to start a new line.

    A few examples of DISPLAY follow.  Many other examples
appear elsewhere in this guide, and mod12's online HELP
facilty also includes numerous DISPLAY examples:

-----













                                       mod12 User Guide - 46


  mod12 > display nl "No quotes -- "                             \
                      qu "Quotes" qu " ; looks like a comment" nl

  No quotes -- "Quotes" ; looks like a comment

  mod12 > macro "dispStr" "{" pcs ?u0 "}" tab 10

  mod12 > display nl mac "dispStr" nl

  "{" pcs ?u0 "}" tab 10

  mod12 > seq , display nl                           \
              , for univ cd 2 and pr display dispStr \
              , display nl

  {01}      {02}      {03}      {04}      {05}      {06}

  mod12 > macro "aList" 3-11,4-11,5-11

  mod12 > display nl "the list: " mac  "aList"     nl \
                     "head:     " head "aList" "," nl \
                     "tail:    "  tail "aList" "," nl

  the list: 3-11 , 4-11 , 5-11
  head:     3-11
  tail:     4-11 , 5-11

  mod12 > display 3 + 2 * 5 tab 10 (3 + 2) * 5 nl
  13        25

  mod12 > display - ((3 * 7) - (14 % 5)) * (27 / 3) - 2 nl
  -119

-----


The Console and Files

     mod12's user interface is based on the old-fashioned,
terminal-style model of the "console."  The console
comprises a keyboard for data entry, and a rectangular area
on the screen allotted to mod12 by the operating system for
output.  By default, mod12 accepts input characters from the
console, and sends output characters to the console.

     The only editing support for mod12 text input is that
provided through the operating system.  For example, text in
the MS-DOS input buffer can be manipulated in various ways
with function keys.  When running mod12 in a multi-tasking
environment, such as on the Macintosh, or in a Windows 95
DOS box, it may be possible to select text with a mouse for













                                       mod12 User Guide - 47

simple cutting and pasting; see your operating system's
documentation for details.

     mod12 has no direct control over how the characters it
sends to the console are actually displayed.  The operating
system handles those details, usually by assigning a fixed-
size font to the console, wrapping text around the side of
the screen when a line is more than eighty characters long,
and scrolling the entire display when the screen is full.
However, mod12 does keep track of how many characters it has
sent to the console.  That count is available to the user
through the integer function CHARSONLINE (type HELP
INTEGERS), and is reset to zero whenever mod12 sends a
newline character (ENTER or RETURN key press) to the
console.  CHARSONLINE is useful when formatting mod12
output; type HELP DISPLAY for an example.

     Screen clutter is one consequence of mod12's display
style.  You can clear the screen with the CLS macro (type
HELP CLS for details).  Entering CLS at the mod12 > prompt
does nothing more or less than display twenty-five newline
characters, effectively scrolling all clutter off the
screen.

     The QUIET command also cuts down on clutter.  QUIET ON
suspends all output to the console until QUIET OFF is
entered.  For example, every time a set is recorded into the
database, mod12 shows the new database record (described
below, or type HELP DATABASE).  This can get tedious if you
are copying sets from the pc set universe into the database.
Here is how to accomplish that without the unwanted display:

-----

  mod12 > seq , quiet on                                \
              , for univ cd 3 and pr record ?u0         \
              , quiet off ; this set was entered by FOR

-----

If you were to SHOW the database now, you would find all
prime trichords recorded with a comment as expected.  (Type
HELP QUIET for more details.)

     The READ and WRITE commands temporarily sever mod12's
default attachment to the console.  READ diverts the input
focus from the console keyboard to a named file.  Its syntax
is

              READ "fileName" < promptString >















                                       mod12 User Guide - 48

where fileName must be enclosed in quotes, and promtpString
is any mod12 command.  If no path information is supplied in
fileName, mod12 assumes the current directory or folder.

     When the optional promptString is given, READ submits
it to mod12 for evaluation.  By default, all input request
during that evaluation is taken from the named file, rather
than the console.  This form of READ is useful only when
promptString invokes MACRO INPUT or MACRO LITERALINPUT
(described below, or type HELP MACRO).  Input focus returns
to the console once processing of promptString is complete,
or if an error occurs during processing.

     Without the optional promptString, READ takes logical
lines one at a time from the named file, and submits them
for evaluation exactly as if they had been entered manually
at the mod12 > prompt.  All lines read from the file are
echoed to the current output device (by default, the screen)
immediately prior to submission; use QUIET ON to suppress
the echo.  Input focus returns to the console once the named
file is exhausted, or if an error occurs while processing a
command from that file.

     READ allows you to use your preferred editor or word
processor to shape mod12 input strings.  READ files must be
ASCII, so turn off any special formatting such as font
settings or justification.  Many word processors also
require special commands to save an ASCII file.  Check your
word processor documentation for details.

     A typical use of READ is to type analytical
segmentations in an editor, and then add them with READ to
mod12's database for processing.  mod12 scripts of any any
appreciable length are also best composed in a text editor,
and then loaded using READ; the "PREDEF.MAC" file
automatically loaded at the start of each mod12 session is
an example of such a script file.  MACRO definitions, AUTO
strings, and environment settings could also be stored in
files for recall into later mod12 sessions with READ.  For
example, here is a file named "Gleich.env" designed
specifically for working with Webern's Opus 12, Number 4:

-----

  quiet on            ; loading settings for "Gleich und Gleich"

  log off             ; ensure a clean slate for prompts, macros, database
  record off
  prm2 off
  compact off
  macro clear
  delete db













                                       mod12 User Guide - 49


  log on "Gleich.log" ; put session transcript in gleich.log

  macro "area1" [c#,d,f,f#,a,b-] ; macro definitions
  macro "area2" ( t11 area1 )
  macro "backup" save "w12n4.db"

  ; automatically announce when an identified set is in one of the "areas"
  auto on seq ^ for ?a lsb area1 display "** in area1" nl \
              ^ for ?a lsb area2 display "** in area2" nl

  load "Gleich.db"    ; load previously stored segmentation database

  quiet off           ; return to keyboard input

-----

READ'ing this into mod12 puts everything in a known state
tailored for "Gleich und Gleich:"

-----

  mod12 CP > read "Gleich.env"

  mod12 > quiet on ; loading settings for "Gleich und Gleich" ...

  mod12 AL >

-----

     WRITE is the output counterpart to READ.  The WRITE
command temporarily redirects output to a file.  Its syntax
is:

             WRITE "fileName" < promptString >

The fileName is required and must appear in quotes.  When no
path information is given in fileName, WRITE assumes the
current directory or folder.  If the named file already
exists, WRITE renames it by replacing its first character
with a tilde, and then creates a new file of the specified
name.

     After opening the output file, WRITE submits
promptString to mod12 for evaluation.  All default output
goes to that file during the processing of promptString.
Output control returns to the console once processing is
complete, or if an error occurs during processing.

     Any mod12 prompt entry string will do as the
promptString argument.  Debugging TRACE's are typical
candidates, as are all commands whose displays spill over













                                       mod12 User Guide - 50

the confines of a single screen.  Here, all Rahn prime forms
are written to an ASCII file named "Rahnprm.dat" in the
current directory or folder:

-----

  mod12 > write "Rahnprm.dat" seq , prm2 on , show univ pr , prm2 off

-----

Rahnprm.dat can now be examined at leisure in any text
editor or word processor.  If working in a multi-tasking
environment, there is no need to quit the current mod12
session; just open another window with a text editor.

     READ and WRITE commands can be nested arbitrarily.
However, the operating system will enforce some limits
regarding the number of open files and the sharing of open
files; consult your operating system's documentation for
details.


LOG'ing System Transcripts

     The LOG command puts a transcript of all mod12 input
and output into an ASCII file.  Logging starts after LOG ON
is entered, and continues until LOG OFF is entered.  To
begin capturing text, enter:

                   LOG ON < "fileName" >

where fileName is optional and names the log file.  If
fileName is given, it must appear in quotes; if not, the
default log file is mod12.log.  The current directory or
folder is assumed unless other path information is supplied.
If the specified or default log file already exists, LOG
will append the current transcript to it.  Otherwise, LOG
creates a new log file.

     Whenever a log file is opened, mod12 inserts a header
announcing the name of the log file and the current system
time and date.  Apart from that header, nothing more or less
than what appears on the screen during a mod12 session is
echoed to the log file.  The sole exception is output
generated while QUIET is ON.  Although that output does not
appear on the screen, it is recorded in the log file.

     Only one log file may be open at a time.  When a log
file is open, attempting to log to another file will produce
an error message.  In such cases, you are instructed to
first close the active log file.  The active log file is
closed by typing LOG OFF at the mod12 prompt.  mod12













                                       mod12 User Guide - 51

automatically closes any open log file when you end a
session with EXIT.

     The mod12 > prompt shows the current LOG status.  If an
"L" appears in the prompt, a log file is open; otherwise,
logging is off.  Typing LOG by itself at the mod12 prompt
will tell you the name of any open log file.

     Here is a sample session using a log file:

-----

  mod12 > log on "test"
  logging to file test

  mod12 L > 01379 ; should be in log file
        01379         t3i   5-28  ; should be in log file

  mod12 L > log
  log file test is open

  mod12 L > log off
  log file test is closed

  mod12 > 023 ; will not be in log file
        023           t3i   3-2 ; will not be in log file

  mod12 > log on "test"
  logging to file test

  mod12 L > !@#$%$# ; intentional error

  ERROR > Extra input: ! @ # $ % $ #

  mod12 L > exit

-----

Here are the contents of "test" in the current directory or
folder (assuming "test" did not exist prior to this
session):

-----

  ***
  * mod12 log file
  * Sat Jun  8 02:01:19 1996
  ***

  logging to file test

  mod12 L > 01379 ; should be in log file













                                       mod12 User Guide - 52

          01379        t3i   5-28  ; should be in log file

  mod12 L > log
  log file test is open

  mod12 L > log off

  ***
  * mod12 log file
  * Sat Jun  8 02:02:08 1996
  ***

  logging to file test

  mod12 L > !@#$%$# ; intentional error

  ERROR > Extra input: ! @ # $ % $ #

  mod12 L > exit

-----


RECORD'ing Segmentations in the Database

     mod12's database can store pc set segmentations
abstracted from musical works.  Through database reference,
all of mod12's resources are then immediately available for
application in the particularities of your analysis.  You
can iterate over the database, organizing, partitioning,
filtering, and querying your segmentations according to a
huge variety of relationships.  With TALLY, FOR, and other
mod12 expressions, the database is analogous to the pc set
universe, serving as a source of sets.  But there are
differences, too.  For example, databases typically do not
contain all possible pc sets, and they could very well
contain multiple instances of a single set.

     Sets are entered into the database with the RECORD
command.  Adding a single segmentation is accomplished with
this syntax:

                         RECORD set

where set is the set you want recorded.  Any comment
associated with set is stored with set in the database
record.  Comments are not required, but you will find an
uncommented database useless for analytical purposes.  Type
HELP COMMENT for details on associating comments with sets.
For example, here is the intro set of Schoenberg's Op. 15,
No. 11:














                                       mod12 User Guide - 53

-----

  mod12 > record [b-,d-,f,d] ; r.h. intro, m1.-m2.
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.

-----

     mod12 displays new records as they are added to the
database.  Each record includes a record id number
automatically assigned by mod12, a pitch class set, and a
comment.  In the example above, the record id is 1, the set
is {125a}, and the comment is "r.h. intro, m1.-m2."  If we
add more sets now, they will have different record id
numbers:

-----

  mod12 > record [c,e-,g,e] ; sop. "Ich erinnere" m6.
  2     0347          t0    4-17  ; sop. "Ich erinnere" m6.

  mod12 > record [b-,d-,f,d] ; pno. lh m6.
  3     125a          t10   4-17  ; pno. lh m6.

-----

Each record id number refers to a slot in the database.
There are 32,000 slots in all.  You will likely use only a
fraction of those, but having so many slots available makes
it easier to organize the database.

       Typing RECORD ON at the mod12 prompt causes all
manually entered segmentations to be automatically recorded:

-----

  mod12 > record on

  mod12 4 > [c-,e-,b-,a-,c,a] ; sop m8. "Als wir ... Tore"
  4     0389ab        t8    6-z36 ; sop m12. "Als wir ... Tore"

  mod12 5 > [c#,e,g#] ; sop m14. "dass wie schwa -"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"

-----

A number appears in the prompt whenever automatic recording
is on.  That number identifies the next database slot to be
assigned.  You can also access that information directly
through the NEXTREC integer function; type HELP INTEGERS for
details.

     Recording sets automatically is the only effect of
having RECORD ON.  Otherwise, mod12 behaves exactly as












                                       mod12 User Guide - 54

described in preceding sections, processing commands and
queries as expected:

-----

  mod12 6 > is     3-11 asb 4-17     4-17 asb 6-36
  yes
  yes

-----

     If you want a set identified when RECORD is ON, but do
not want it recorded, use SCRATCH:

-----

  mod12 6 > scratch [c,c#,d,d#] ; not added to the database
        0123          t0    4-1 ; not added to the database

-----

You stop automatic recording by typing RECORD OFF at the
prompt:

-----

  mod12 6 > record off

  mod12 > [0,1,2,3] ; also not added to the database
        0123          t0    4-1 ; also not added to the database

-----

Segmentations stored in the database remain there even when
RECORD is OFF.

     As evident in the preceding examples, each new record
added to the database is automatically assigned a record id
number which is one greater than that of the previously
stored set.  This can be changed with the RECORD AT form of
RECORD:

                RECORD AT slotNumber < set >

After entering this command, mod12 will begin automatically
assigning record id numbers beginning at slotNumber.  If the
optional set argument is also supplied, mod12 first stores
the set at slotNumber, and then sets the next slot to be
assigned at slotNumber + 1.  For example:

-----














                                       mod12 User Guide - 55

  mod12 > record on

  mod12 6 > record at 200 ; (without optional set argument)

  mod12 200 > [c,a,g#,b,g] ; sop m11. "warden uns erdach -"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"

  mod12 201 > @ 200 u [f#,c#] ; sop. m11.-m12. "warden -- dachte"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"

-----

In that last entry, notice that a database reference ("@
200") was used as a set.  Refer back to the section above on
pc set entry formats for more information, or type HELP
PCSET.

     Continuing with our example now:

-----

  mod12 202 > [d#,c#,d#,c] ; sop m12. "Seligkeiten"
  202   013           t0    3-2   ; sop m12. "Seligkeiten"

-----

Whoops.  That last set should include a D-natural.  We can
correct it by recording over 202 with RECORD AT:

-----

  mod12 203 > record at 202 [d#,c#,d,c] ; sop m12. "Seligkeiten"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

-----

     Using RECORD AT indiscriminately can result in unwanted
overwrites.  When automatic recording is on, and the next
set entered for storage will overwrite an existing record,
mod12 announces this with an asterisk in the prompt.  That
is what happens at the second line in this example:

-----

mod12 203 > record at 200 ; (NB. no optional set argument)

mod12 200 * > record at 203 ; now get back to safe territory

mod12 203 >

-----














                                       mod12 User Guide - 56

     Typing RECORD LIST gives an overview of which database
slots contain sets:

-----

  mod12 203 > record list
      1..5        200..202

-----

What RECORD LIST shows is all of the occupied "ranges" in
the database.  Ranges are taken as input by many commands.
Valid range input formats are:

        n1..n2   interpreted as all records between n1 and
                 n2.

        n..      interpreted as all records between n and
                 32000.

        ..n      interpreted as all records between 1 and n.

        n        interpreted as n..n (i.e., the single
                 record n).

n, n1, and n2 are all integer expressions (type HELP
INTEGERS).  Apart from the literal integers 1 through 32000,
some other expressions relevant to ranges include FIRSTREC
(the lowest occupied slot in the database), LASTREC (the
highest occupied slot), and NEXTREC (the next database slot
to be assigned).  The predefined macro DB (type HELP PREDEF)
is defined as FIRSTREC .. LASTREC; notice that this is not
the same as 1 .. 32000.

     RECORD LIST itself takes a range as an optional
argument in its full syntax:

                   RECORD LIST < range >

If the optional argument is supplied, only those entries in
the specified range are listed:

-----

  mod12 203 > record list ..100
      1..5

  mod12 203 > record list 100..
      200..202

  mod12 203 > record off














                                       mod12 User Guide - 57

  mod12 > record list 2..201
      2..5        200..201

-----


The Range Forms of SHOW and TALLY

     The range forms of SHOW and TALLY are similar to their
respective UNIV forms, except that they iterate over the
database, rather than the pc set universe.  The syntax for
the range form of SHOW is:

               SHOW range < testExpression >

The testExpression argument is optional.  If not given, SHOW
will display all records whose id numbers fall in the
specified range.  The syntax for the range form of TALLY is:

               TALLY range < testExpression >

Again, the testExpression argument is optional.  If not
given, TALLY will count all records whose id numbers fall in
the specified range.

     Here are some examples using the database entered so
far:

-----

  mod12 > show db ; show entire database
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  2     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  3     125a          t10   4-17  ; pno. lh m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > tally db ; tally the entire database

  TALLY > total tallied: 8
   3-11  :    1

   4-1   :    1      4-17  :    3

   5-3   :    1

   6-z36 :    1

   7-5   :    1













                                       mod12 User Guide - 58


  mod12 > show db cmng @ 1 0 ; intersect with [b-,d-,f,d] ?
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  3     125a          t10   4-17  ; pno. lh m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > show db not asp 3-11 ; no triad _properly_ included
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > tally db asp 3-11 ; yes, properly includes a triad
  TALLY > total tallied: 5
   4-17  :    3

   6-z36 :    1

   7-5   :    1

  mod12 > show 4 ; only record 4
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"

  mod12 > show ..100 not isym ; everything to 100 not isym
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"

  mod12 > show db isymn 3 ; all sets invariant under I-c#/d
  1     125a         t10   4-17  ; r.h. intro, m1.-m2.
  3     125a         t10   4-17  ; pno. lh m6.
  202   0123         t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > show db cmnt "m11." ; only show sets from m. 11
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"

  mod12 > show db cmnt "sop" and cd 5 or cd 6 ; show soprano pentads \
                                                and hexachords only
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"

  mod12 > show db asb 8-28 ; octatonic sets
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  2     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  3     125a          t10   4-17  ; pno. lh m6.
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"

  mod12 > show db asb 8-28 and asb 7-35 ; both octatonic and diatonic
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"














                                       mod12 User Guide - 59

-----


Iterating over the Database with FOR

     The range form of FOR parallels the UNIV form described
earlier, iterating over the database to conditionally submit
mod12 expressions for evaluation.  But it differs from the
UNIV form, too, in that it defines an additional macro for
record id numbers.  Its syntax is:

       FOR range < testExpression > < promptString >

     This form systematically iterates through the database,
considering each record R in turn as the operand for the
optional testExpression.  If the test returns true, or if no
testExpression is given, FOR performs these four steps in
order:

          1, it defines a special macro ?Un which expands to
             a pc digit representation of R's pc set in
             curly brackets (n is the current FOR nesting
             level);

          2, it also defines a special macro ?Dn which
             expands to the record id number of R (n is the
             current FOR nesting level);

          3, it submits the optional promptString to mod12
             for evaluation, exactly as if it had been
             entered manually at the mod12 prompt; and

          4, it undefines the special macros defined in
             steps 1 and 2.

     A typical use of the range form is to pair off sets in
a database.  Here, sets in the Schoenberg database are
paired off based on pc inversion around D/Eb.  Since
inversion is commutative, the range formula at line 2
ensures that no pair will be listed more than once in the
display:

-----

  mod12 > for db                           /* 1 */ \
            for ?d0 + 1 .. eq t5i ?u0      /* 2 */ \
              display nl rec ?d0 rec ?d1   /* 3 */

  1     125a         t10   4-17  ; r.h. intro, m1.-m2.
  2     0347         t0    4-17  ; sop. "Ich erinnere" m6.

  2     0347         t0    4-17  ; sop. "Ich erinnere" m6.













                                       mod12 User Guide - 60

  3     125a         t10   4-17  ; pno. lh m6.

-----

     Given the variety of available tests in mod12, and
given that those tests may be combined arbitrarily, the same
technique could be used to extract pairs according to all
sorts of criteria.  The next example identifies
complementary sets with literal inclusion -- i.e., possible
instances of embedded complements.  For illustration
purposes, assume that we are starting a new mod12 session
with a database of segmentations from Webern's Op. 12, No.
1.  Only part of the display is shown here:

-----

  mod12 > for db                        \
           for db ac ?u0 and lsp ?u0    \
            display nl rec ?d0 rec ?d1

  19    1689          t6    4-14  ; "storbnen die e-" m18.-m19.
  130   1345689a      t10i  8-14  ; pno m10. w/ c# pickup

  20    126b          t11   4-14  ; pno last beat m11 (tied over).
  129   1234678b      t8i   8-14  ; all pno m12.

  39    2468          t2    4-21  ; gib .. -storbnen
  132   0234568a      t2    8-21  ; gib .. -storbnen w/ pno tl m16.-m18.

  [ ... ]

-----

     The technique can be extended to triplets, quadruplets,
and so forth, by using FOR forms with deeper nestings.  More
free-form groupings are possible using SEQ.  For example,
this command shows all (R1,Rp) relatives in the current
database.  Again, only part of the display is shown:

-----

  mod12 > for db                                           \
            seq + display nl "---" nl rec ?d0              \
                          "... is in (R1,Rp) with ..." nl  \
                + for db r1 ?u0 and rp ?u0 display rec ?d1 \
                + display "---" nl

  [ ... ]

  ---
  10    589a         t10i  4-4   ; pno m1. 1st att
  ... is in (R1,Rp) with ...













                                       mod12 User Guide - 61

  11    59ab         t11i  4-5   ; pno m2. 2nd vert
  16    679b         t6    4-11  ; pno chd 2 m7.
  19    1689         t6    4-14  ; "storbnen die e-" m18.-m19.
  20    126b         t11   4-14  ; pno last beat m11.
  21    059a         t0i   4-14  ; pno m1. 2nd vert
  ---

  ---
  11    59ab         t11i  4-5   ; pno m2. 2nd vert
  ... is in (R1,Rp) with ...
  7     3458         t3    4-4   ; pno m10. last quarter
  8     4569         t4    4-4   ; "ewige Ruh"
  9     4569         t4    4-4   ; pno lh m10.
  10    589a         t10i  4-4   ; pno m1. 1st att
  28    0278         t7    4-16  ; "kommt herzu" m15.-m16.
  29    0278         t7    4-16  ; "Nacht ist schon hier" m6.-m7.
  ---

  [ ... ]

-----

     Potentially useful information about the database may
be obtained through non-range forms of FOR as well.  The
following command relies heavily on the SCDB test, which
returns true if the implied operand is included in the
current database at a specified range (type HELP SCDB).  The
command displays a nexus-set candidate table, each row of
which is formatted as follows: the first column shows the
name of a set class represented in the database, along with
the name of the complementary set class, if also represented
in the database (see lines 4 and 5); the second column shows
a count of all instances of the named set class/es in the
database (line 6); the third column shows a count of all
database records whose sets are in Forte's Kh relation with
the named set class (line 7); and the fourth column shows a
count of all set classes represented in the database which
are in the Kh relation with the named set class (line 8).
The BREAK in the nested, single-set FOR forms of lines 2 and
3 ensures that no set-class/complementary-set-class pair is
represented more than once in the table (type HELP CDG and
HELP UNLT for details).  Again, only a portion of the
display is shown here:

-----

  mod12 > /* ... the command starts on the next line for readability ... */ \
  for univ pr and scdb db                                           /* 1 */ \
    seq ^ for ?u0 cdg 5                                             /* 2 */ \
            for pf cmp ?u1 unlt ?u1 and scdb db break               /* 3 */ \
        ^ display name ?u0                                          /* 4 */ \
        ^ for cmp ?u0 (not sc ?u0) and scdb db display "/" name ?u1 /* 5 */ \













                                       mod12 User Guide - 62

        ^ display tab 20 tally db sc ?u0 or ac ?u0                  /* 6 */ \
                  tab 10 tally db kh ?u0                            /* 7 */ \
                  tab 10 tally univ pr and scdb db and kh ?u0 nl    /* 8 */

  [ ... ]

  5-32                1         16        6
  5-33                1         6         4
  5-z36/7-z36         2         8         5
  5-z37/7-z37         4         10        4
  6-2                 1         33        20
  6-z3/6-z36          2         16        11
  6-z4/6-z37          2         6         5
  6-5                 1         50        28
  6-9                 1         40        23
  6-z10/6-z39         2         15        9
  6-15                1         42        23

  [ ... ]

-----


Storing and Recalling Databases with SAVE and LOAD

     You can save the current database to a file with the
SAVE, whose syntax is:

       SAVE "fileName" < range >  < testExpression >

The fileName argument is required, and must appear in
quotes; if no path information is supplied, the current
directory or folder is assumed.  If the named file already
exists, it is renamed (type HELP WRITE), and a new file with
the specified name is created.  If the optional range
argument is specified, only records from that range are
saved; otherwise, the range argument is assumed to be
FIRSTREC .. LASTREC.  If the optional testExpression is
supplied, only records whose sets pass the test are saved.

     Assume that we are now still working with our
Schoenberg database, entered earlier in the section on the
RECORD command.  This command saves the database to
"s15n11.db" in the current directory or folder:

-----

  mod12 > save "s15n11.db"

-----















                                       mod12 User Guide - 63

It is usually a good idea to define a file-saving MACRO when
working with a database, so that you do not always have to
remember the file name:

-----

  mod12 > macro "update" save "s15n11.db"

-----

Entering UPDATE by itself now at the prompt automatically
saves the database in the right file.

     Databases saved with SAVE are reloaded with LOAD.  One
form of LOAD has this syntax:

                      LOAD "fileName"

The fileName argument is required, and must appear in
quotes.  If no path information is included, mod12 assumes
the current directory or folder.

     Assume we have EXIT'ed the preceding mod12 session, and
have now just begun a new session with an empty database:

-----

  mod12 > show db ; nothing there

  mod12 > load "s15n11.db"
  8 record(s) loaded from s15n11.db

  mod12 > show db
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  2     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  3     125a          t10   4-17  ; pno. lh m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

-----

The database is now restored to the state it was in when we
last saved it.  If the database had contained records prior
to calling LOAD, and the records' id numbers coincided with
those in the LOAD'ed database, the old records would have
been overwritten.

     Another form of LOAD keeps the sets and comments of
saved records, but discards the saved record id numbers.
The syntax for this form is:












                                       mod12 User Guide - 64


                    LOAD AT n "fileName"

A quoted fileName argument is required.  This form loads the
saved records into the database at consecutive slots
beginning with slot n:

-----

  mod12 > load at 300 "s15n11.db"
  8 record(s) loaded from s15n11.db

  mod12 > show 300..
  300   125a          t10   4-17  ; r.h. intro, m1.-m2.
  301   0347          t0    4-17  ; sop. "Ich erinnere" m6.
  302   125a          t10   4-17  ; pno. lh m6.
  303   0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  304   148           t1    3-11  ; sop m14. "dass wie schwa -"
  305   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  306   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  307   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > record list
      1..5        200..202      300..307

-----

The current database now contains two copies of the original
database.  The first copy is stored with the original id
numbers at 1..202, while the second is stored at consecutive
slots in the range 300..307.

     Both SAVE and LOAD are pre-defined macro procedures
loaded at the start of each mod12 sessions; type HELP PREDEF
for more details.


DELETE'ing, MOVE'ing, and SORT'ing in the Database

     Unwanted sets are deleted from the current database
with the DELETE command.  Its syntax is

              DELETE aRange < testExpression >

aRange is required, but the testExpression argument is
optional.  If included, DELETE will remove only those
records in the specified range which pass the test.  If no
testExpression is given, all records in the specified range
are deleted.  For example,

-----














                                       mod12 User Guide - 65

  mod12 > record list
      1..5        200..202      300..307

  mod12 > show 300.. cmnt "sop" and cd 4
  301   0347          t0    4-17  ; sop. "Ich erinnere" m6.
  307   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > delete 300.. cmnt "sop" and cd 4

  mod12 > record list
      1..5        200..202      300..300      302..306

  mod12 > delete 300..

  mod12 > record list
      1..5        200..202

-----

     The MOVE macro is useful for partitioning the database.
Its syntax is:

          MOVE range < testExpression > slotNumber

MOVE moves all records in the specified range which pass the
optional testExpression to consecutive slots beginning at
slotNumber.  If testExpression is not given, all records are
moved.  Any existing record at a destination slot will be
overwritten by the move.  For example:

-----

  mod12 > show db
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  2     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  3     125a          t10   4-17  ; pno. lh m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  200   0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  201   016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  202   0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > move ..300 cmnt "sop" 1000
  moved to 1000..1005

  mod12 > show db
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  3     125a          t10   4-17  ; pno. lh m6.
  1000  0347          t0    4-17  ; sop. "Ich erinnere" m6.
  1001  0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  1002  148           t1    3-11  ; sop m14. "dass wie schwa -"
  1003  0789b         t7    5-3   ; sop m11. "warden uns erdach -"













                                       mod12 User Guide - 66

  1004  016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  1005  0123          t0    4-1   ; sop m12. "Seligkeiten"

  mod12 > move db 1
  moved to 1..8

  mod12 > show db
  1     125a          t10   4-17  ; r.h. intro, m1.-m2.
  2     125a          t10   4-17  ; pno. lh m6.
  3     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  6     0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  7     016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  8     0123          t0    4-1   ; sop m12. "Seligkeiten"

-----

     The integer function NEXTREC is useful when MOVE'ing
single sets automatically within a FOR loop.  (NEXTREC
returns the next database slot number to be assigned; type
HELP INTEGERS.)  The goal in the following example is to
have set classes be uniquely represented in the range 1..8,
with all "duplicates" moved to slots starting at 100.  The
IDLT test returns true if the implied operand record has a
lower database id than the specified argument (type HELP
IDGT):

-----

  mod12 > record at 100

  mod12 > for ..8                        \
            for ..8 sc ?u0 and idlt ?d0  \
              move ?d1 nextrec
  moved to 100..100
  moved to 101..101

  mod12 > show db
  3     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  4     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  5     148           t1    3-11  ; sop m14. "dass wie schwa -"
  6     0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  7     016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  8     0123          t0    4-1   ; sop m12. "Seligkeiten"
  100   125a          t10   4-17  ; r.h. intro, m1.-m2.
  101   125a          t10   4-17  ; pno. lh m6.

-----

    SORT sorts all records in a specified range by set class
and Tn/TnI level.  Its full syntax is:













                                       mod12 User Guide - 67


                 SORT < DOWN > range < CMNT >

Notice that test arguments are not accepted by SORT, and
that the range argument is required.  The optional tokens
DOWN and CMNT affect the sort order.

     When neither DOWN nor CMNT is specified, the sort order
coincides with the order in which mod12 iterates over the pc
set universe.  For any records R1 and R2 in the range with
pcsets S1 and S2, respectively, R1 will precede R2 in this
default sort if: (1) the cardinality of S1 is less than that
of S2; or (2) S1 and S2 are of the same cardinality, and the
Forte ordinal number of S1 is less than that of S2; or (3)
S1 and S2 are in the same set class, and S1 is a
transposition of the prime form, while S2 is not; or (4) S1
and S2 are in the same set class, and are either both
transpositions or both inversions of the prime form, and the
transposition index of S1 relative to the prime form is less
than that of S2.  If S1 and S2 are identical, the order is
undefined.  (This SORT order is sensitive to the current
prime table; type HELP PRM2 for details.)

     Keeping our same database now:

-----

  mod12 > sort 1 ..
  sorted at 1..8

  mod12 > show db
  1     148           t1    3-11  ; sop m14. "dass wie schwa -"
  2     0123          t0    4-1   ; sop m12. "Seligkeiten"
  3     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  4     125a          t10   4-17  ; pno. lh m6.
  5     125a          t10   4-17  ; r.h. intro, m1.-m2.
  6     0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  7     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  8     016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"

-----

     Including the token DOWN in the command reverses the
sort order:

-----

  mod12 > sort down db
  sorted at 1..8

  mod12 > show db
  1     016789b       t6    7-5   ; sop. m11.-m12. "warden -- dachte"













                                       mod12 User Guide - 68

  2     0389ab        t8    6-z36 ; sop m8. "Als wir ... Tore"
  3     0789b         t7    5-3   ; sop m11. "warden uns erdach -"
  4     125a          t10   4-17  ; pno. lh m6.
  5     125a          t10   4-17  ; r.h. intro, m1.-m2.
  6     0347          t0    4-17  ; sop. "Ich erinnere" m6.
  7     0123          t0    4-1   ; sop m12. "Seligkeiten"
  8     148           t1    3-11  ; sop m14. "dass wie schwa -"

-----

     When the CMNT token is specified, sorting is based on
lexical ordering of comment fields.  The comparison is not
case sensitive.  If the DOWN token is not specified, records
are sorted in ascending dictionary order:

-----

  mod12 > sort db cmnt
  sorted at 1..8

  mod12 > show db
  1     125a         t10   4-17  ; pno. lh m6.
  2     125a         t10   4-17  ; r.h. intro, m1.-m2.
  3     0789b        t7    5-3   ; sop m11. "warden uns erdach -"
  4     0123         t0    4-1   ; sop m12. "Seligkeiten"
  5     148          t1    3-11  ; sop m14. "dass wie schwa -"
  6     0389ab       t8    6-z36 ; sop m8. "Als wir ... Tore"
  7     0347         t0    4-17  ; sop. "Ich erinnere" m6.
  8     016789b      t6    7-5   ; sop. m11.-m12. "warden -- dachte"

-----

Including the token DOWN reverses the sort:

-----

  mod12 > sort down db cmnt
  sorted at 1..8

  mod12 > show db
  1     016789b      t6    7-5   ; sop. m11.-m12. "warden -- dachte"
  2     0347         t0    4-17  ; sop. "Ich erinnere" m6.
  3     0389ab       t8    6-z36 ; sop m8. "Als wir ... Tore"
  4     148          t1    3-11  ; sop m14. "dass wie schwa -"
  5     0123         t0    4-1   ; sop m12. "Seligkeiten"
  6     0789b        t7    5-3   ; sop m11. "warden uns erdach -"
  7     125a         t10   4-17  ; r.h. intro, m1.-m2.
  8     125a         t10   4-17  ; pno. lh m6.

-----















                                       mod12 User Guide - 69

Automated Entry with AUTO

     Sets entered by themselves at the mod12 > prompt are
interpreted as commands for identification.  When RECORD'ing
is ON, any such set entry additionally triggers a command to
store the set in the database, as described above in the
section on RECORD.

     In fact, set entries can trigger commands of any type
or complexity.  Automatic entry of the triggered commands is
carried out by mod12's AUTO facility.  Commands are
registered with the AUTO facility using this syntax:

                     AUTO ON autoString

where autoString is any mod12 command.

     Whenever an autoString is registered, the AUTO facility
performs these steps in order for each set S entered for
identification:

          1, if RECORD'ing is ON, it assigns a database id
             to S, but does not add S to the database;

          2, it displays the identification of S;

          3, it defines a special macro named "?A" to a pc
             digit representation of S in curly brackets;

          4, it submits autoString to mod12 for evaluation,
             with any references to ?A in autoString
             expanded;

          5, it undefines ?A; and

          6, if RECORD'ing is ON, it adds S to the database.

A letter 'A' appears in the mod12 > prompt to show that an
autoString is currently registered.  No more than a single
autoString at a time may be registered with the AUTO
facility.  Registering a new autoString replaces any
currently registered autoString.

     No set submitted for identification within the context
of an autoString will itself trigger the AUTO facility,
meaning that AUTO-generated infinite loops will never arise.
However, sets automatically submitted within the context of
a manually entered, top-level command such as SEQ or FOR
will trigger the AUTO facility.  To avoid potential
conflicts with FOR nesting levels, scripts which rely on
this behavior should cast the autoString as a LOCAL command
(described below, or type HELP LOCAL).













                                       mod12 User Guide - 70


     In the following example, an autoString signals when a
set being entered into the database is included in, or equal
to, a set already in the database:

-----

  mod12 > auto on for db eq ?a or lsp ?a display "Same pcs are in" cmnt ?d0 nl

  mod12 A > record on

  mod12 A 1 > 01379 ; clarinets m1.-m2.
  1     01379        t3i   5-28  ; clarinets m1.-m2.

  mod12 A 2 > 371 ; viola m6.
  2     137          t1    3-8   ; viola m6.
  Same pcs are in clarinets m1.-m2.

  mod12 A 3 > [c,d,d#] ; violin + pno m2.
  3     023          t3i   3-2   ; violin + pno m2.

  mod12 A 4 > [c,e-] ; cello m6.
  4     03           t0    2-3   ; cello m6.
  Same pcs are in clarinets m1.-m2.
  Same pcs are in violin + pno m2.

-----

     Entering AUTO by itself at the mod12 > prompt displays
the current autoString.  That autoString is stored in a
system macro named "auto-string," which may be directly
altered by the user.  In the example below, the macro is
manipulated using MACRO BUILD (described below, or type HELP
MACRO).  Now, in addition to the behavior displayed above,
the AUTO facility will also display a Forte (1988) genus
type profile:

-----

  mod12 A 5 > auto
  for firstrec .. lastrec eq ?a or lsp ?a display "Same pcs are in" cmnt ?d0 nl

  mod12 A 5 > macro build "auto-string"                   \
                "seq $ " mac "auto-string"                \
                   " $ for int 1 12                       \
                         for ?a genus ?i0                 \
                           display " qu "G" qu "?i0 tab 4 \
                     $ display nl"

  mod12 A 5 > auto
  seq $ for firstrec .. lastrec eq ?a or lsp ?a display "Same pcs are in" cmnt ?d0
   nl $ for int 1 12 for ?a genus ?i0 display "G" ?i0 tab 4 $ display nl













                                       mod12 User Guide - 71


  mod12 A 5 > [0,3,7] ; tremelo strings m4.
  5     037          t0    3-11  ; tremelo strings m4.
  Same pcs are in clarinets m1.-m2.
  G9  G10 G12

  mod12 A 6 > [3,11,5,6,2] ; 1st appearance of motto, m11., clarinets
  6     2356b        t6i   5-16  ; 1st appearance of motto, m11., clarinets
  G1  G2  G3  G6  G9

-----

     Entering AUTO OFF deletes the currently registered
autoString, effectively turning the AUTO facility off:

-----

  mod12 A 7 > {137} ; auto now ON
  7     137          t1    3-8   ; auto now ON
  Same pcs are in clarinets m1.-m2.
  Same pcs are in viola m6.
  G2

  mod12 A 8 >  auto off

  mod12 8 > {137} ; auto now OFF
  8     137          t1    3-8   ; auto now OFF

-----

The MACRO Facility

     Several examples in preceding sections have assumed
some familiarity with general macro concepts.  That is
because mod12 macros are similar to the macros used in word
processing programs, operating systems, spreadsheets,
database programs, and programming languages.  The most
obvious advantages of any macros are that they can cut back
on keystrokes and make obscure language structures more
readable.  In mod12, macros also provide the foundation for
a powerful scripting language.

     The basic idea behind macros is simple.  One sequence
of characters, the macro "name," is defined to represent
another sequence of characters, the macro "expansion."  In
each string evaluated after that definition, mod12 replaces
any instance of the name with a copy of the expansion.

     There are a few complications behind this simple
description.  For example, macro expansion is deferred in
FENCE, LOCAL, and SEQ commands.  Also, different macros may
share the same name, provided they are defined in different
"scopes."  These exceptions are treated in later sections.












                                       mod12 User Guide - 72


     The MACRO command defines, redefines, and lists macros.
This syntax is used to define a global macro, or to redefine
a macro in the current scope:

             MACRO "nameToken" expansionString

where nameToken is the name of the macro, which must appear
in quotes, and expansion string is the macro expansion.

     Macro names must be forty characters or less in length.
They may not include any whitespace, commas, quotes, or any
of the characters, ']', '}', or ')'.  Case is insignificant
in macro names, but the names of user-defined macros must
begin with a letter.  Some system macro names -- e.g., ?a,
?u0, ?d0, ?i0, ?end-of-file, ?prm2-on, and ?trace-on --
begin with a question mark.  These name "reserved" macros,
which may be referenced, but not redefined or deleted.
mod12 syntax form tokens -- e.g., HELP, SEQ, ON, etc. -- are
not accepted as user-defined macro names.  Consequently,
although with a few exceptions, all of the tokens listed on
the ALLTOPICS help screens are invalid macro names (type
HELP ALLTOPICS).

     Any mod12 expression will serve as an expansionString:
a range, an integer, operators or a group of operators,
boolean expressions, a command, a test, part of a command
along with part of a test, and so forth.  An expansionString
may contain references to other macros, so long as no
circular references arise.  Those references are themselves
expanded when expansionString is expanded:

-----

  mod12 > macro "G-dom7" [g,b,d,f]

  mod12 > macro "C-maj" [c,e,g]

  mod12 > macro "C-min" [c,e-,g]

  mod12 > macro "scale" G-dom7 u X

  mod12 > macro "X" t9 C-min ; assume that X is undefined prior to this entry

  mod12 > scale
        024579b       t11   7-35

  mod12 > macro "X" t8 C-maj ; now X is redefined

  mod12 > scale
        023578b       t11   7-32














                                       mod12 User Guide - 73

-----

      SCALE is defined here in terms of G-DOM7 and X.
Because the definition of G-DOM7 precedes that of SCALE,
SCALE's expansion includes a copy of G-DOM7's expansion.
However, X is still undefined at the time of SCALE's
definition, so SCALE's expansion includes only a reference
to X, rather than a copy of X's expansion.  Next, X is
defined first in terms of T9 C-MIN, which causes scale to
evaluate to [ c , d , e , f , g , a , b ], and then in terms
of T8 C-MAJ, which causes SCALE to evaluate to [ c , d , e-
, f , g , a- , b ].  Redefining X indirectly changes the
definition for SCALE.  "Redefining" here merely means
changing the expansionString associated with an existing
name.

     The TRACE command described earlier may be used to show
the full, current expansion of an expression.  To display an
expanded expression without evaluating it, use EXPAND:

-----

  mod12 > trace scale

  TRACE 1 / 0 > [ g , b , d , f ] u t8 [ c , e , g ]
        023578b      t11   7-32

  mod12 > expand scale
  [ g , b , d , f ] u t8 [ c , e , g ]

  mod12 > macro "x" t9 C-min

  mod12 > expand x
  t9 [ c , e- , g ]

  mod12 > expand scale
  [ g , b , d , f ] u t9 [ c , e- , g ]

-----

     All current macro names can be displayed along with
their expansionStrings by using the MACRO LIST form, whose
syntax is:

           MACRO LIST < scope > < patternString >

The scope and patternString arguments are optional.  If
patternString is not supplied, all macros whose names start
with letters are listed:

-----














                                       mod12 User Guide - 74

  mod12 >  macro list
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]
  macro "g-dom7" [ g , b , d , f ]
  macro "scale" [ g , b , d , f ] u x
  macro "x" t9 [ c , e- , g ]

-----

If patternString is specified, it must appear in quotes.
MACRO LIST will then show only those macros whose names
begin with the sequence of characters in patternString:

-----

  mod12 > macro list "c-m"
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]

-----

     Using MACRO LIST with WRITE saves the current macros to
a file, which may later be reloaded into mod12.  This
command saves our macros to "macro.sav" in the current
directory or folder:

-----

  mod12 > write "macro.sav" macro list

-----

If we were to EXIT mod12 now and then start a new session,
the macros would be restored with this command:

-----

  mod12 > read "macro.sav"

-----

     The optional scope argument to MACRO LIST is absent in
the examples above, and so only macros in the current scope
which match the optional patternString are listed there.
Scoping is described later in this guide (or type HELP
LOCAL).  If the optional scope argument is supplied, only
macros in the specified scope which match the optional
patternString are listed.  For example, several system
macros are stored at scoping level -2:

-----














                                       mod12 User Guide - 75

  mod12 > macro list -2
  macro "auto-string"
  macro "comment-size"
  macro "compact-on"
  macro "quiet-on"

-----

In order to show system macros with reserved names, include
a patternString argument beginning with a question mark:

-----

  mod12 > macro list -2 "?"
  macro "?end-of-file"
  macro "?prm2-on"
  macro "?trace-on"

-----

     A single macro in the current scope may be deleted --
"undefined" -- by entering MACRO OFF, followed by the
macro's name in quotes:

-----

  mod12 > macro off "scale"

  mod12 > macro list
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]
  macro "g-dom7" [ g , b , d , f ]
  macro "x" t9 [ c , e- , g ]

  mod12 > macro off "x"

  mod12 > macro list
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]
  macro "g-dom7" [ g , b , d , f ]

-----

     All macros in the current scope may be removed with the
MACRO CLEAR command:

-----

  mod12 > macro clear

  mod12 > macro list














                                       mod12 User Guide - 76

-----


Building Macros and Assigning User Input

     The simple MACRO definition form does not offer much
control over the interpretation of expansionString.  Assume
for the next example that the macro definitions of the
preceding section have been restored.  After listing those
definitions, SCALE is redefined, using the same
expansionString as in its original definition:

-----

  mod12 > macro list
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]
  macro "g-dom7" [ g , b , d , f ]
  macro "scale" [ g , b , d , f ] u x
  macro "x" t9 [ c , e- , g ]

  mod12 > macro "scale" [ g , b , d , f ] u x

  mod12 > macro list "scale"
  macro "scale" [ g , b , d , f ] u t9 [ c , e- , g ]

-----

When SCALE was originally defined, X was undefined, and the
reference to X in SCALE's expansionString remained
unexpanded.  Here, however, X is defined, so the reference
to X is now expanded before assigning expansionString in the
redefinition of SCALE.  No matter how X is redefined under
this state of affairs, SCALE's interpretation remains fixed:

-----

  mod12 > scale
        024579b      t11   7-35

  mod12 > macro "x" { 012 345 678 9ab }

  mod12 > scale
        024579b      t11   7-35

-----

     The original definition, which allowed SCALE's mutable
interpretation, looked like this:

-----














                                       mod12 User Guide - 77

  mod12 > display     mac "g-dom7"     " u x"
  [ g , b , d , f ] u x

-----

Another form of the MACRO command, MACRO BUILD, uses the
same formatting options as DISPLAY to construct an
expansionString.  Here, the DISPLAY string just demonstrated
is used as an argument to MACRO BUILD, with the result that
SCALE's interpretation once again depends upon the current
definition of X:

-----

  mod12 > macro build "scale"     mac "g-dom7"     " u x"

  mod12 > macro list "scale"
  macro "scale" [ g , b , d , f ] u x

  mod12 > scale
        0123456789ab t0   12-1

  mod12 > macro "x" t9 c-min

  mod12 > scale
        024579b      t11   7-35

-----

     The syntax of MACRO BUILD is

             MACRO BUILD "nameToken" formatList

where nameToken is the target macro's name, which must be in
quotes, and formatString is an arbitrary number of format
specifications.  (For details on the format specifications,
refer to the section on DISPLAY earlier in this guide, or
type HELP DISPLAY.)  This MACRO form first constructs an
expansionString according to the format specifications, then
normalizes it, and finally assigns it as the expansion of
the named macro.  (See the section above on "Getting
Started" for information on normalization, or type HELP
I/O.)

     MACRO BUILD is helpful is many scripting contexts.  For
example, sometimes a macro is used as an accumulator to
"grow" integers, sets, or test expressions.  The first
command below initializes "accum" to zero, adds one to it
three times, and then displays the resultant expansion.  The
second command follows the same steps, but uses the MACRO
BUILD form, rather than the simple definition form:














                                       mod12 User Guide - 78

-----

  mod12 > seq : macro "accum" 0          \
              : macro "accum" accum + 1  \
              : macro "accum" accum + 1  \
              : macro "accum" accum + 1  \
              : display nl mac "accum" nl

  0 + 1 + 1 + 1

  mod12 > seq : macro "accum" 0               \
              : macro build "accum" accum + 1 \
              : macro build "accum" accum + 1 \
              : macro build "accum" accum + 1 \
              : display nl mac "accum" nl

  3

-----

In the first command, expansionString has a purely lexical
interpretation; mod12 treats it only as a string of
characters.  In the second command, MACRO BUILD recognizes
the presence of an integer expression in the formatList, and
reduces it accordingly.  Accumulators structured like
"accum" in the first command unnecessarily drain memory
resources, may be inefficient (depending on how often they
are accessed), and may lead to unexpected evaluations due to
operator priority problems (judiciously applied parentheses
can avoid the problems, however).  These concerns disappear
when MACRO BUILD is used.

     MACRO BUILD, like the MACRO INPUT form to be described
shortly, has another benefit: it opens a "back door" into
mod12's parser, providing a means for changing the current
semicolon comment in a nested command structure.  Type HELP
COMMENT for details and an example.

     Gaining access to console or file input within a mod12
script requires that the input first be assigned to a macro.
Two forms of the MACRO command are available for this
purpose.  The MACRO INPUT form has the following syntax:

           MACRO INPUT "nameToken" < userPrompt >

where nameToken is the target macro's name, which must be in
quotes, and the optional userPrompt is a DISPLAY
expressionList.  This form DISPLAY's userPrompt (if
specified) to the current output, READ's a logical line from
the current input source, normalizes the line, and finally
assigns the normalized line as the expansion of the named
macro.  (Refer to the section above on DISPLAY for details













                                       mod12 User Guide - 79

about formatting userPrompt, or type HELP DISPLAY.  For
information about the current input and output, refer to the
section above on READ and WRITE, or type HELP READ and HELP
WRITE.)

     Current input and output in the next example is set (by
default) to the console, where the FOR command of lines 1
through 5 loops twice.  Line 2 defines "s" to a set entered
by the user; line 3 defines "xfrm" to an operator entered by
the user; and lines 4 and 5 display the expansions of those
macros, along with some additional information.  Everything
after line 5 is script output or input.  All characters
following ">>" on those lines are user input entered at the
console:

-----

  mod12 > for int 1 2                                                      /* 1 */ \
            seq : macro input "s" nl "Please enter a set >> "              /* 2 */ \
                : macro input "xfrm" "Now please enter an operator >> "    /* 3 */ \
                : display mac "xfrm" " " mac "s" " = { " pcs xfrm s        /* 4 */ \
                          " } ( i.e., " tni xfrm s " " name xfrm s " )" nl /* 5 */

  Please enter a set >> [a,b-,c#,c,b]   ; subject, bart. mus. str. perc. cel.
  Now please enter an operator >> t7    ; what's the real answer?
  t7 [ a , b- , c# , c , b ] = { 45678 } ( i.e., t4 5-1 )

  Please enter a set >> t4 5-1          ; real answer, ibid.
  Now please enter an operator >> t -7  ; what's the subject again?
  t - 7 t4 5-1 = { 019ab } ( i.e., t9 5-1 )

-----

For an example illustrating macro input taken from a file,
see the definition of LOAD in the file "PREDEF.MAC" (type
HELP PREDEF for more information).

     MACRO LITERALINPUT behaves almost the same as MACRO
INPUT, but with a critical difference.  Its syntax is:

       MACRO LITERALINPUT "nameToken" < userPrompt >

where nameToken is the target macro's name, which must be in
quotes, and the optional userPrompt is a DISPLAY
expressionList.  This form DISPLAY's userPrompt (if
specified) to the current output, reads a string of
characters terminating with a newline or end-of-file from
the current input, and assigns that string as an expansion
to the named macro.  mod12's parser is bypassed entirely in
this form, and the expansion is not normalized.

     MACRO LITERALINPUT is most useful for displaying the
unprocessed contents of a file.  For example, the next












                                       mod12 User Guide - 80

command displays lines 300 through 310 from a version of the
file "mod12.hlp."  The expansion of "oneLine" (defined in
line 4 of the command and displayed in line 6) is not
normalized; some unquoted text is capitalized, and more than
a single whitespace character appears between sentences:

-----

  mod12 > read "mod12.hlp"                                                   /* 1 */ \
            seq > display nl "\\\\\\ Lines 300 - 310 of mod12.hlp \\\\\\" nl /* 2 */ \
                > for int 1 310                                              /* 3 */ \
                    seq < macro literalinput "oneLine"                       /* 4 */ \
                        < for {} intgt ?i0 299                               /* 5 */ \
                            display mac "oneLine"                            /* 6 */ \

  \\\\\\ Lines 300 - 310 of mod12.hlp \\\\\\
  the new topic are then displayed.  Once you have quit the new topic by
  entering Q, another prompt asks whether to return to the screen from which you
  jumped (press ENTER), or to quit the help facility altogether (enter the
  letter Q).

  For example, a number of general interest topics are listed on the screens of
  the TOPICS topic.  Typing TOPICS at the prompt below will jump to that list.
  From there, you can jump to each of the listed topics, or to any topic you
  wish.  Those topics in turn refer to still other topics, which refer to still
  others, and so forth.  You can leapfrog indefinitely through the help system
  in this manner, jumping from any topic to any other.  So long as you
  \\\\\\ File dump ends here \\\\\\\\\\\\\\\

-----

     Even if an expansion assigned through MACRO
LITERALINPUT appears syntactically correct, it will usually
be rejected by mod12 unless it passes through the
normalization process.  The next example prototypes the germ
of a nested interpreter.  The interpreter displays a "mod12'
>" prompt, takes a line of user input, and then evaluates
it.  The first formulation fails; mod12 rejects CMD's
expansion at line 2 because it is not normalized.  The
second version succeeds, since CMD's expansion is eventually
normalized there in the redefinition through MACRO BUILD at
line 4.  Had MACRO INPUT been used instead of MACRO
LITERALINPUT, line 4 would not have been necessary:

-----

  mod12 > seq : macro literalinput "cmd" nl "mod12' > "  /* 1 */ \
              : cmd                                      /* 2 */

  mod12' > tally univ cd 3

  ERROR > Extra input: tally univ cd 3













                                       mod12 User Guide - 81


  mod12 > seq : macro literalinput "cmd" nl "mod12' > "  /* 3 */ \
              : macro build "cmd" mac "cmd"              /* 4 */ \
              : cmd                                      /* 5 */

  mod12' > tally univ cd 3
  TALLY > total tallied: 220
   3-1   :   12      3-2   :   24      3-3   :   24      3-4   :   24
   3-5   :   24      3-6   :   12      3-7   :   24      3-8   :   24
   3-9   :   12      3-10  :   12      3-11  :   24      3-12  :    4

-----


Blocking Macro Expansion with Fence

     In most cases, macro references in a mod12 command are
expanded immediately before the command is evaluated.  Three
exceptions are:

       - HELP < token >.  If token is a macro, it is not
         expanded, since that would preclude getting help on
         predefined macros.

       - SEQ delimChar < promptStringList >.  Macro
         references in any text following the token SEQ are
         not expanded when the SEQ command itself is
         evaluated.  Instead, expansions are carried out one
         at a time, as SEQ submits each promptString in turn
         to mod12 for evaluation.

       - LOCAL < macDef/s > < promptString >.  Macro
         references in macDef/s are never expanded.  Those
         in promptString are expanded only when LOCAL
         submits promptString to mod12 for evaluation.
         LOCAL is described below, or type HELP LOCAL for
         details.

     It is sometimes desirable to defer macro expansion in
other commands, too.  For example, this command is intended
to display the interval vectors of {012357} and {0134689},
along with the absolute degree of difference between the
interval class contents of those sets.  The difference is
stored in a macro accumulator named "ivdif," which is
initialized to zero in line 1, and presumably increased in
line 4.  A glance at the display reveals that IVDIF is not
set appropriately:

-----

  mod12 > seq * macro "ivdif" 0                                  /* 1 */ \
              * for univ cd 2 and pr                             /* 2 */ \













                                       mod12 User Guide - 82

                  macro build "ivdif"                            /* 3 */ \
                    ivdif + abs emb ?u0 6-9 - emb ?u0 7-32       /* 4 */ \
              * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl /* 5 */
  342231
  335442
  ivdif = 1

-----

     The single FOR command of lines 2 through 4 is
evaluated only once.  Immediately prior to that evaluation,
the unquoted reference to IVDIF in line 4 is replaced with
zero, IVDIF's initial expansion established in line 1.
Next, when the FOR command begins execution, each pass
through the loop again submits lines 3 and 4 for evaluation,
once for each prime dyad.  The integer expression ABS EMB
?U0 6-9 - EMB ?U0 7-32 in line 4 calculates the difference
between respective interval vector entries.  Because of the
premature expansion of IVDIF, that expression is simply
added to zero in line 4.  Although the result is assigned to
"ivdif" at lines 3 and 4, it is discarded in each subsequent
redefinition of "ivdif" as the loop progresses, since what
appears as a reference to IVDIF in line 4 has already been
replaced by zero when lines 2 through 4 were first
evaluated.  The final value of IVDIF is thus equal only to
the difference in interval class 6 content.  (If this
description is confusing, try entering the above command
with TRACE; TRACE is described above, or type HELP TRACE.)

     What is needed here is a way to block the expansion of
IVDIF in line 4 during the single evaluation of the entire
FOR command at lines 3 through 5.  The FENCE command is used
for this purpose.  Its syntax is:

                   FENCE < promptString >

where promptString is any valid mod12 command.  All FENCE
does is submit promptString for evaluation.  The value of
FENCE is that macro expansion in promptString is deferred
until FENCE itself submits promptString.

     Here, the previous example is fixed by inserting a
FENCE at the beginning of line 3.  Now, the unquoted
reference to IVDIF behaves as expected, and is expanded only
during loop processing:

-----

  mod12 > seq * macro "ivdif" 0                                  /* 1 */ \
              * for univ cd 2 and pr                             /* 2 */ \
                  fence macro build "ivdif"                      /* 3 */ \
                    ivdif + abs emb ?u0 6-9 - emb ?u0 7-32       /* 4 */ \













                                       mod12 User Guide - 83

              * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl /* 5 */
  342231
  335442
  ivdif = 8

-----

     Because FENCE's promptString argument must be a
command, FENCE also serves a typecasting function.  Type
HELP TYPECAST for more information.


Scoping and LOCAL

     The number of currently defined macros can become
unwieldy unless you conscientiously delete all macros which
are no longer needed.  For example, assuming only the macro
definitions used for illustration in the preceding two
sections, here is what MACRO LIST shows:

-----

  macro "accum" 3
  macro "c-maj" [ c , e , g ]
  macro "c-min" [ c , e- , g ]
  macro "cmd" tally univ cd 3
  macro "g-dom7" [ g , b , d , f ]
  macro "ivdif" 8
  macro "oneline" in this manner, jumping from any topic to any other.  So long as
   you

  macro "s" t4 5-1
  macro "scale" [ g , b , d , f ] u x
  macro "x" t9 [ c , e- , g ]
  macro "xfrm" t - 7

-----

     Apart from the wasted memory resources represented
here, unneeded macro definitions may also lead to logical
problems.  For example, assume that the IVDIF script is to
be submitted again, but this time we neglect to initialize
"ivdif" to zero.  If "ivdif" were undefined, mod12 would
report an error, alerting us to the fact that IVDIF was not
properly initialized.  That is the behavior we would want.
However, given the current state of the macro system, we get
an incorrect result rather than an error message:

-----

  mod12 > seq * /* IVDIF's initialization should have gone here */ /* 1 */  \
              * for univ cd 2 and pr                               /* 2 */  \













                                       mod12 User Guide - 84

                  fence macro build "ivdif"                        /* 3 */  \
                    ivdif + abs emb ?u0 6-9 - emb ?u0 7-32         /* 4 */  \
              * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl   /* 5 */
  342231
  335442
  ivdif = 16

-----

     Macros created through the MACRO command remain defined
until explicitly deleted with MACRO OFF or MACRO CLEAR.
They are "global" macros, because they are (by default)
accessible in all mod12 contexts.  Very often, it is
desirable to have temporary, "local" macros instead, which
are accessible only in limited contexts, and which
"disappear" when they are no longer needed.

     The LOCAL command is used for this purpose.  It creates
a temporary environment with optional, local macros, submits
a promptString to mod12 for evaluation within that
environment, and then deletes the temporary environment.
LOCAL's syntax is:

         LOCAL    < macDefList >   < promptString >


where the (optional) promptString is any mod12 command.
Macros in promptString are not expanded until LOCAL submits
promptString to mod12 for evaluation.  Each element in the
optional macDefList has the form:

                   "macName" < initSpec >

where macName is a quoted macro name, and the optional
initSpec specifies how the local macro named by macName is
initialized.  If initSpec is absent, the local macro named
by macName is defined to null in the temporary environment
set up by LOCAL.  Otherwise, that macro is defined according
to the format of initSpec.  Possible formats for initSpec
are described below.

     As a quick illustration of LOCAL, here is the correct
version of the IVDIF script again, now appearing as a LOCAL
promptString.  Before running the script, all global macros
are deleted with MACRO CLEAR.  The LOCAL command first
establishes "ivdif" as a local macro (initialized to null,
since initSpec is absent), and then submits the script as
its promptString:

-----

  mod12 > macro clear













                                       mod12 User Guide - 85


  mod12 > macro list ; nothing there now

  mod12 > local "ivdif"                                             /* 1 */ \
             seq * macro "ivdif" 0                                  /* 2 */ \
                 * for univ cd 2 and pr                             /* 3 */ \
                     fence macro build "ivdif"                      /* 4 */ \
                       ivdif + abs emb ?u0 6-9 - emb ?u0 7-32       /* 5 */ \
                 * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl /* 6 */
  342231
  335442
  ivdif = 8

  mod12 > macro list ; still nothing there

-----

Once processing of lines 1 through 6 is complete, the local
macro "ivdif" no longer exists.  The memory it occupied is
reclaimed, and its expansion can never be accessed again.

     Local macros have another valuable property, which is
that they can "shadow" global macros with the same name.
The IVDIF script will serve as an example again, with the
twist this time being that "ivdif" is defined globally as
well.  The first entry below creates the global definition;
the second invokes the same DISPLAY command found in line 6
of the script, but with the global IVDIF referenced; the
third runs the script itself, whose DISPLAY in line 6
references the local IVDIF; and the fourth entry repeats the
second, demonstrating that the global definition remains
unchanged:

-----

  mod12 > macro "ivdif" "** THIS IS THE GLOBAL DEFINITION OF IVDIF **"

  mod12 > display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif ; cf. line 6 below
  342231
  335442
  ivdif = ** THIS IS THE GLOBAL DEFINITION OF IVDIF **

  mod12 > local "ivdif"                                            /* 1 */ \
            seq * macro "ivdif" 0                                  /* 2 */ \
                * for univ cd 2 and pr                             /* 3 */ \
                    fence macro build "ivdif"                      /* 4 */ \
                      ivdif + abs emb ?u0 6-9 - emb ?u0 7-32       /* 5 */ \
                * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl /* 6 */
  342231
  335442
  ivdif = 8














                                       mod12 User Guide - 86

  mod12 > display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif ; cf. line 6 above
  342231
  335442
  ivdif = ** THIS IS THE GLOBAL DEFINITION OF IVDIF **

-----

All quoted and unquoted references to IVDIF in lines 1
through 6 of the script pertain only to the local version of
IVDIF.  Just as the local IVDIF is inaccessible outside of
lines 1 through 6, the global IVDIF is inaccessible within
those lines, since the global name is shadowed there by the
local name.

     Local macros are possible because mod12 uses a
"scoping" hierarchy to guide the interpretation of macro
references.  Immediately before evaluating a LOCAL command,
mod12 creates a new scoping level which is one greater than
the level at which the LOCAL command was submitted.  Any
macro then defined by the LOCAL command exists in the new
scope.  Once that LOCAL command has finished, mod12 destroys
the new scoping level, and restores the original one.

     This dynamic layering of scoping levels supports
mod12's macro resolution strategy.  When mod12 encounters
any macro reference MR at any scoping level SL, it first
tries to match MR against the names of all macros existing
at level SL.  If a match is found, its expansion replaces
MR.  Otherwise, mod12 tries again at level SL - 1.  If a
match is found there, that match's expansion replaces MR.
Otherwise, mod12 tries again at level SL - 2, and so forth,
until either a match is found, or all available scoping
levels have been exhausted (in the latter case, no expansion
is attempted).

     User macros defined through the MACRO command exist at
scoping level 0; the predefined macros automatically read
into mod12 at the start of each session exist at level -1
(type HELP PREDEF for details); and system macros, such as
?prm2-on and comment-size, exist at level -2 (type HELP
SYSMACS for details).  Unless shadowed, they are all
accessible in any context, since zero is the least possible
scoping level seen by the user once a mod12 session is
underway.  LOCAL commands are nestable, either directly or
through the CALL command described below, so the upper limit
on scoping levels is restricted only by available memory
resources.  Regardless of the particular value of the
current scoping level, however, mod12's interpretation of
macro references is always based on the strategy outlined
above.  (You can use TRACE to identify scoping levels; see
the section on TRACE above, or type HELP TRACE.)














                                       mod12 User Guide - 87

     LOCAL additionally affects macro interpretation by
temporarily resetting the current FOR nesting level.  (See
the sections above on FOR, or type HELP FOR.)  The lowest
FOR nesting level in a LOCAL command is always zero, even if
the LOCAL command itself was invoked within the context of
an enframing FOR command.  mod12's strategy for interpreting
the special FOR macros -- ?U0, ?D0, ?I0, etc. -- is simple:
FOR macros are accessible only in the scope in which they
were created.

     For example, lines 2, 4, 6, and 7 in the following
command all display the current expansion of ?U0.  At line
2, that expansion is the one created by the single-pcset
form of FOR at line 1.  No expansion is available for
display at line 4 because ?U0 is undefined there, the FOR
nesting level having been reset by the enframing LOCAL at
line 3 (which, incidentally, does not define any new
macros).  Another single-pcset FOR is then invoked within
that LOCAL's promptString at line 5, and the new ?U0's
expansion is displayed at line 6.  By line 7, the LOCAL
command has finished processing, so its temporary
environment is replaced by the original.  Line 7 therefore
references the same ?U0 as was referenced at line 2:

-----

  mod12 > for cmp {02468a}                                         /* 1 */ \
            seq : display nl "line 2: ?u0 = " mac "?u0"            /* 2 */ \
                : local                                            /* 3 */ \
                    seq ' display nl "line 4: ?u0 = " mac "?u0"    /* 4 */ \
                        ' for cmp {0134679a}                       /* 5 */ \
                            display nl "line 6: ?u0 = " mac "?u0"  /* 6 */ \
                : display nl "line 7: ?u0 = " mac "?u0"            /* 7 */

  line 2: ?u0 = {13579b}
  line 4: ?u0 =
  line 6: ?u0 = {258b}
  line 7: ?u0 = {13579b}

-----

     None of the LOCAL commands in this section's examples
have initialized their temporary macros to anything other
than null.  That is because most of the initSpec formats
advertised earlier in LOCAL's syntax are used in conjunction
with CALL, which is described in the next section.  One
initSpec format does not depend on CALL, however.
Specifically, any expression in parentheses following a
"macName" in LOCAL's macDef list is immediately assigned
(without parentheses) as the expansion of that macName.  So,
for example, our IVDIF script can now be coded as follows:














                                       mod12 User Guide - 88

-----

  mod12 > local "ivdif" ( 0 ) /* now LOCAL does the initializing */ /* 1 */ \
            seq * for univ cd 2 and pr                              /* 3 */ \
                    fence macro build "ivdif"                       /* 4 */ \
                      ivdif + abs emb ?u0 6-9 - emb ?u0 7-32        /* 5 */ \
                * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl  /* 6 */
  342231
  335442
  ivdif = 8

-----


CALL'ed Macro Procedures

     We have run the IVDIF script several times through its
various incarnations, so it seems worthwhile now to define
it as a macro named, let us say, "vector_difference."  That
way, rather than manually entering the script, or loading it
from a text file with READ, we need only type
VECTOR_DIFFERENCE for each subsequent run:

-----

  mod12 > macro "vector_difference"                                  \
            local "ivdif" ( 0 )                                      \
              seq * for univ cd 2 and pr                             \
                      fence macro build "ivdif"                      \
                        ivdif + abs emb ?u0 6-9 - emb ?u0 7-32       \
                  * display iv 6-9 nl iv 7-32 nl "ivdif = " ivdif nl

  mod12 > vector_difference ; this will run the (former) ivdif script
  342231
  335442
  ivdif = 8

-----

     VECTOR_DIFFERENCE would be much more useful if it could
display the vector difference of two arbitrary sets.  This
can also be accomplished through macros.  First, the two
references to Forte name 6-9 in the script are replaced by a
macro reference, e.g., SET1; and the two references to Forte
name 7-32 are replaced by a different macro reference, e.g.,
SET2.  Then, each time before running VECTOR_DIFFERENCE,
global macros SET1 and SET2 are defined to the particular
sets we are interested in.

-----

  mod12 > macro "vector_difference"                                   \













                                       mod12 User Guide - 89

            local "ivdif" ( 0 )                                       \
              seq * for univ cd 2 and pr                              \
                      fence macro build "ivdif"                       \
                        ivdif + abs emb ?u0 SET1 - emb ?u0 SET2       \
                  * display iv SET1 nl iv SET2 nl "ivdif = " ivdif nl

  mod12 > macro "set1" 3-1

  mod12 > macro "set2" 3-2

  mod12 > vector_difference ; shows ivdif for scs 3-1 and 3-2
  210000
  111000
  ivdif = 2

  mod12 > seq : macro "set1" [0,1,4,5,8,9] : macro "set2" [1,3,5,7,9,11]

  mod12 > vector_difference ; now shows ivdif for scs 6-20 and 6-35
  303630
  060603
  ivdif = 18

-----

     Apart from the inconvenience of redefining one or both
of SET1 and SET2 each time we run the script, this strategy
requires two global macros in addition to VECTOR_DIFFERENCE.
Conflicts could arise if we had other utility macros
currently defined which also relied on SET1 and SET2 as
globals.  For example, one of those other macros might
redefine SET1 in the course of its execution, perhaps
leading to unexpected results when subsequently running
VECTOR_DIFFERENCE.  What is needed here is a new way to
inform VECTOR_DIFFERENCE about the sets we are interested
in, this time without having to define those sets as macros.

     The CALL command addresses this need.  Its syntax is

            CALL "locMacName" < parameterList >

where locMacName is the quoted name of a macro, which must
expand to a LOCAL command, and parameterList is a list of
parameters passed to the named macro.  CALL retrieves the
expansion of locMacName and submits it for evaluation along
with parameterList.  But before submitting its own
promptString, the invoked LOCAL command first parses
parameterList according to its LOCAL initSpec formats,
assigning each parameter to a local macro.

     For example, one LOCAL initSpec format is SET, which
causes LOCAL to read a pc set expression off of the
parameter list supplied by CALL.  We can now redefine
VECTOR_DIFFERENCE as desired, and invoke it through CALL:












                                       mod12 User Guide - 90


-----

  mod12 > macro "vector_difference"                                    /* 1 */ \
            local "ivdif" ( 0 ) "SET1" set "SET2" set                  /* 2 */ \
              seq * for univ cd 2 and pr                               /* 3 */ \
                      fence macro build "ivdif"                        /* 4 */ \
                        ivdif + abs emb ?u0 SET1 - emb ?u0 SET2        /* 5 */ \
                  * display iv SET1 nl iv SET2 nl "ivdif = " ivdif nl  /* 6 */

  mod12 > call   "vector_difference"   4-28   8-28
  004002
  448444
  ivdif = 22

  mod12 > call   "vector_difference"   [c,d-,e-] u [f,g-]   zset cmp 7-z12
  222121
  222121
  ivdif = 0

-----

The LOCAL command beginning at line 2 now defines three
local macros: IVDIF, initialized as before through immediate
assignment to 0; SET1, initialized to the first set on the
CALL-supplied parameter list; and SET2, initialized to the
second set on the CALL-supplied parameter list.  In the
first CALL, SET1 is initialized to {0369}, and SET2 is
initialized to {0134679a}; in the second, SET1 is
initialized to {01356}, and SET2 is initialized to {01247}

     CALL only passes the parameterList to LOCAL; it is
LOCAL's responsibility to parse the list appropriately.
Reviewing the syntax for LOCAL,

         LOCAL    < macDefList >   < promptString >

our interest now is in macDefList, which is the list of
local macro definitions.  LOCAL carries out macro
definitions in the order in which they appear in macDefList,
and stops only when macDefList is exhausted.  Each element
of macDefList has the form:

                   "macName" < initSpec >

As described in the previous section, if initSpec is
missing, the macro named by "macName" is initialized to
null; and if initSpec is an expression enclosed in
parentheses, the macro named by "macName" is initialized to
that expression.  Otherwise, initSpec may be a parameter-
parsing token which matches a value at the head of the
parameter list supplied by CALL.  If the match succeeds, the













                                       mod12 User Guide - 91

macro named by "macName" is defined to that value, and the
list supplied by CALL is advanced to the next parameter; if
the match fails, the macro named by "macName" is defined to
null, and the parameter list is not advanced.  The
parameter-matching initSpec tokens are:

       - EXP    matches a parenthesized expression in the
                parameter list; parentheses are not included
                in the assignment

       - INT    matches an integer expression (refer to the
                section on integer expressions earlier in
                this guide, or type HELP INTEGERS)

       - OP     matches a user-defined pcset operator (refer
                to the section on pc set operators earlier
                in this guide, or type HELP OPERATORS)

       - QUSTR  matches a quoted string; the quotes are
                included in the assignment

       - RANGE  matches a database range (refer to the
                section on RECORD earlier in this guide, or
                type HELP RANGE)

       - REM    matches whatever remains of the parameter
                list

       - SET    matches a pc set expression (refer to the
                section on pc set expressions earlier in
                this guide, or type HELP PCSET)

       - TEST   matches a test expression (refer to the
                section on test expressions earlier in this
                guide, or type HELP TESTS)

       - TOK    matches an unquoted string starting with a
                letter or question mark

(There is one more initSpec format, IMPOP, which is
described in the next section of this guide.)

     The VECTOR_DIFFERENCE script is redefined below to
demonstrate the INT initSpec format.  The redefined script
will display, not only differences between interval class
vectors, but also differences between "trichord vectors,"
"tetrachord vectors," and so forth.  Displaying the vectors
themselves would require only an extra line or so of code,
but since many of those vectors (e.g., the 50-place
"hexachord vectors") would be too wide for our console
screen, vector displays are left out of the redefinition.
Only three changes are required: adding the local macro













                                       mod12 User Guide - 92

"CARD," initialized through an INT initSpec at line 2;
replacing the literal integer "2" with a reference to CARD
in line 3; and removing the IV tokens from the DISPLAY at
line 6.  Although not required, the "ivdif" accumulator has
been renamed to reflect its new meaning.  VECTOR_DIFFERENCE
is CALL'ed with three arguments now, the cardinality of the
vector sets preceding the SET1 and SET2 arguments:

-----

  mod12 > macro "vector_difference"                             /* 1 */ \
            local "dif" ( 0 ) "CARD" int "SET1" set "SET2" set  /* 2 */ \
              seq * for univ cd CARD and pr                     /* 3 */ \
                      fence macro build "dif"                   /* 4 */ \
                        dif + abs emb ?u0 SET1 - emb ?u0 SET2   /* 5 */ \
                  * display "dif = " dif nl                     /* 6 */

  mod12 > call   "vector_difference"     2        4-28    8-28
  dif = 22

  mod12 > call   "vector_difference"     2 + 1    4-28    8-28
  dif = 52

  mod12 > call "vector_difference" 5 {01234} [0,1,2,3,5] ; should differ by two pentads
  dif = 2

  mod12 > call "vector_difference" 5 [c,c#,e] [d,e,g#,a#] ; neither includes any pentad
  dif = 0

  mod12 > call "vector_difference" 6 {} 12-1 ; should equal the number of all hexachords
  dif = 924

  mod12 > display tally univ cd 6 ; checking that last one...
  924

-----

     VECTOR_DIFFERENCE could be further generalized by
replacing the "hardwired" cardinality test of line 3 with an
arbitrary, user-supplied test expression, USERTEST.  A TEST
initSpec format in line 2 pulls the test expression off the
CALL-supplied parameter list.  We are still comparing
embedding counts of set-class types, but the constraints on
those types are now wide open:

-----

  mod12 > macro "vector_difference"                                  /* 1 */ \
            local "dif" ( 0 ) "USERTEST" test "SET1" set "SET2" set  /* 2 */ \
              seq * for univ pr and USERTEST                         /* 3 */ \
                      fence macro build "dif"                        /* 4 */ \
                        dif + abs emb ?u0 SET1 - emb ?u0 SET2        /* 5 */ \













                                       mod12 User Guide - 93

                  * display "dif = " dif nl                          /* 6 */

  mod12 > call "vector_difference"    cd 2    6-34    6-30   \
          /*     plain old interval vector comparison       */
  dif = 8

  mod12 > call "vector_difference"  sc 2-1 or sc 2-3 or sc 2-5   6-34 6-30 \
          /*     the "vectors" now cover only odd interval classes        */
  dif = 3

  mod12 > call "vector_difference"  cdg 1 and asb 7-35   6-34 6-35 \
          /*  now the vectors cover dyadic-plus diatonic subsets  */
  dif = 41

  mod12 > call "vector_difference"  cdg 1 and asb 8-28  6-34 6-35 \
          /*        as above, but now octatonic subsets          */
  dif = 32

-----

Even further generalization is possible, of course, but we
leave off at this point.  Examples of other initSpec formats
may be found by viewing the file "PREDEF.MAC" in a text
editor.  (Type HELP PREDEF for more information on that
file.)

     CALL'ed macros like VECTOR_DIFFERENCE are known as
"procedures," to distinguish them from CALL'ed macro
"functions," described in the next section.  Procedures do
not return values, but are called instead for their side
effects, such as displaying information in the case of
VECTOR_DIFFERENCE.

     It is often handy to have a "wrapper" macro which hides
the explicit CALL of a macro procedure or function.  That
way, the hidden CALL will look like one of mod12's built-in
commands.  Also, wrappers are good places to include
typecasting tokens (type HELP TYPECAST), so that the CALL
will behave as expected in all contexts.  Here, the CALL to
VECTOR_DIFFERENCE is hidden in a macro named "vectdif."  It
is then used with VECTORS in a FOR loop to compare 3-1's
interval vector against those of other inversionally
invariant trichord types:

-----

  mod12 > macro "vectdif" fence call "vector_difference" ; the "wrapper"

  mod12 > for univ cd 3 and pr and isym and not eq 3-1 \
            seq & vectors 3-1 ?u0                      \
                & vectdif cd 2 3-1 ?u0














                                       mod12 User Guide - 94

  SC     TnI   PCS           INTVEC       VTICS
  3-1    t0    012           210000       123210000000
  3-6    t0    024           020100       102030201000
  dif = 4

  SC     TnI   PCS           INTVEC       VTICS
  3-1    t0    012           210000       123210000000
  3-9    t0    027           010020       103010020200
  dif = 4

  SC     TnI   PCS           INTVEC       VTICS
  3-1    t0    012           210000       123210000000
  3-10   t0    036           002001       200200300200
  dif = 6

  SC     TnI   PCS           INTVEC       VTICS
  3-1    t0    012           210000       123210000000
  3-12   t0    048           000300       300030003000
  dif = 6

-----


RETURN'ing Values through Macro Functions

     The values displayed by VECTOR_DIFFERENCE are
inaccessible to other expressions.  What if we wanted to
compare those values, or use them to calculate other values?
To do that, we would need vector differences available for
processing in all appropriate mod12 contexts.  That is to
say, VECTOR_DIFFERENCE would be more generally useful if it
behaved as a function rather than a procedure.

     A macro function is a CALL'ed macro which returns a
value.  All functions return values through the RETURN
command, whose syntax is

                 RETURN < retType retVal >

where the optional retVal is either a set or an integer, and
retType is either of the tokens, SET or INT.

     RETURN immediately stops processing in a CALL'ed macro
procedure or function, returning control to the point where
the CALL was originally issued.  retType and retVal are left
unspecified in procedures; there, RETURN is not required,
but may help in some situations by serving as a procedural
BREAK (type HELP RETURN).  Both retVal and retType must be
specified in functions.  If retVal is a set, retType must
specify that with the token SET; and if retVal is an
integer, retType must be the token INT.














                                       mod12 User Guide - 95

     For example, all that is needed to transform
VECTOR_DIFFERENCE into a function is to include a line
RETURN'ing "dif" as an INT.  There seems little point now in
having VECTOR_DIFFERENCE itself display the value of "dif,"
since that value will be generally available in any context
accepting an integer, including a DISPLAY command.
Consequently, line 6's former DISPLAY command is replaced
with a RETURN in the redefinition below.  As before, we also
define a wrapper to hide the explicit CALL.  The function is
then tested by using it to derive some of Robert Morris's
ASIM values (reviewed in Morris 1987, 106):

-----

  mod12 > macro "vector_difference"                                  /* 1 */ \
            local "dif" ( 0 ) "USERTEST" test "SET1" set "SET2" set  /* 2 */ \
              seq * for univ pr and USERTEST                         /* 3 */ \
                      fence macro build "dif"                        /* 4 */ \
                        dif + abs emb ?u0 SET1 - emb ?u0 SET2        /* 5 */ \
                  * return int dif                                   /* 6 */

  mod12 > macro "vectdif" int call "vector_difference" ; the "wrapper"

  mod12 >                                     /* This command displays ASIM(4-27,X) */ \
  for univ pr and cdg 2 and cdl 6                  /* for each prime X, #X = 3,4,5. */ \
    seq : for {} intgt charsonline 60 display nl /* (... line breaks as needed ...) */ \
        : display name ?u0 tab 6 "0."     /* Display name and ASIM with 4-27, i.e., */ \
            ( 100 * vectdif cd 2 ?u0 [f,b,d#,g#] )     /* 100 * interval vector dif */ \
            /                                                         /* divided by */ \
            6                            /* the number of ic's in the tristan chord */ \
            +                                                               /* plus */ \
            (cd ?u0 * (cd ?u0 - 1)) / 2 tab 12         /* the number of ic's in ?u0 */
  3-1   0.77  3-2   0.55  3-3   0.55  3-4   0.55  3-5   0.55  3-6   0.55
  3-7   0.33  3-8   0.33  3-9   0.55  3-10  0.33  3-11  0.33  3-12  0.77
  4-1   0.66  4-2   0.50  4-3   0.33  4-4   0.33  4-5   0.33  4-6   0.50
  4-7   0.50  4-8   0.50  4-9   0.66  4-10  0.33  4-11  0.33  4-12  0.16
  4-13  0.16  4-14  0.33  4-z15 0.16  4-16  0.33  4-17  0.33  4-18  0.16
  4-19  0.50  4-20  0.50  4-21  0.50  4-22  0.33  4-23  0.50  4-24  0.50
  4-25  0.50  4-26  0.16  4-27  0.0   4-28  0.50  4-z29 0.16  5-1   0.50
  5-2   0.37  5-3   0.37  5-4   0.25  5-5   0.37  5-6   0.37  5-7   0.50
  5-8   0.37  5-9   0.37  5-10  0.25  5-11  0.37  5-z12 0.25  5-13  0.37
  5-14  0.37  5-15  0.50  5-16  0.25  5-z17 0.37  5-z18 0.25  5-19  0.25
  5-20  0.37  5-21  0.50  5-22  0.37  5-23  0.37  5-24  0.37  5-25  0.25
  5-26  0.25  5-27  0.37  5-28  0.25  5-29  0.25  5-30  0.37  5-31  0.25
  5-32  0.25  5-33  0.62  5-34  0.25  5-35  0.37  5-z36 0.25  5-z37 0.37
  5-z38 0.25

-----

     The function "iv_set_" (wrapped as "iv_set") is defined
below to demonstrate a SET return.  IV_SET takes six
integers as arguments, which together are interpreted as an













                                       mod12 User Guide - 96

interval vector.  Line 6 returns the prime set with the
lowest ordinal number whose interval vector matches the
argument.  If there is no such set, the null set is returned
at line 7:

-----

  mod12 > macro "iv_set_"                                                     /* 1 */ \
            local "ic1" int "ic2" int "ic3" int "ic4" int "ic5" int "ic6" int /* 2 */ \
              seq & for univ pr and inc {01} ic1 and inc {02} ic2             /* 3 */ \
                                and inc {03} ic3 and inc {04} ic4             /* 4 */ \
                                and inc {05} ic5 and inc {06} ic6             /* 5 */ \
                      return set ?u0                                          /* 6 */ \
                  & return set {}                                             /* 7 */

  mod12 > macro "iv_set" set call "iv_set_"

  mod12 > iv_set 1 1 1 1 1 1
        0146         t0    4-z15

  mod12 > zset iv_set 1 1 1 1 1 1
        0137         t0    4-z29

  mod12 > zset iv_set 1+4 1+4 1+4 1+4 1+4 1+2   /* "complementary" interval vector */
        01235679     t0    8-z29

  mod12 > iv_set 0 6 0 6 0 3
        02468a       t0    6-35

  mod12 > iv_set 0 6 0 6 0 4                    /* impossible interval vector */
                     t0    0-1

-----

     CALL'ed macro functions may also be used as tests.  Any
nonzero integer or nonnull set returned from such a function
signals success, while a zero or null set return signals
failure.  Test functions often require access to the implied
operand provided by FOR and TALLY, and LOCAL allows for that
through its IMPOP initSpec option.  (LOCAL's initSpec syntax
is described in the preceding two sections, or type HELP
LOCAL).  IMPOP assigns the current implied operand to a
specified local macro.  It has no effect on the parsing of
the CALL-supplied parameter list.

     The next example illustrates a specialized test
function which takes an explicit integer argument TLEV in
addition to the implied operand.  TRICHORD_TRANSPOSE_ TLEV
returns true if and only if the implied operand S can be
partitioned into a trichord T and a nonnull set R such that
the union of R and the TLEV transpose of T is an inverted or
transposed form of S.  For example, TRICHORD_TRANSPOSE_ 4













                                       mod12 User Guide - 97

holds true for {0123}, since that set can be partitioned as
{012} and {3}; the union of {3} and T4( {012} ) is {3456},
which is a transposed form of {0123}.  The implied operand
is named SETARG below, initialized through IMPOP at line 2;
TLEV is initialized through INT on the same line.  The
RETURN of the integer 1 at line 5 signals success; failure
is signaled by the return of zero at line 6.  As before, a
"wrapper" macro is defined as well:

-----

  mod12 > macro "trichord_transpose_"                             /* 1 */ \
            local "SETARG" impop "tlev" int                       /* 2 */ \
              seq : for univ lsb SETARG and cd 3                  /* 3 */ \
                      for (SETARG not ?u0) u t tlev ?u0 sc SETARG /* 4 */ \
                        return int 1                              /* 5 */ \
                  : return int 0                                  /* 6 */

  mod12 > macro "trichord_transpose" test call "trichord_transpose_" ; the wrapper

  mod12 >  show univ pr and cd 4 and trichord_transpose 4
        0123         t0    4-1
        0237         t0    4-14
        0147         t0    4-18
        0148         t0    4-19
        0246         t0    4-21
        0257         t0    4-23
        0248         t0    4-24

-----

     CALL'ed procedures and functions are less efficient
than mod12's built-in commands because of the processing
overhead associated with macro assignment and expansion.
Consequently, care must be taken when user-defined
procedures are used in iterating over large numbers of sets.
In the preceding example, SHOW submits 4,096 sets to the
test expression, PR AND CD 4 AND TRICHORD_TRANSPOSE 4.
Because of the way boolean expressions are evaluated, only
224 of those sets (the primes, including "0-1") are tested
against the subexpression, CD 4 AND TRICHORD_TRANSPOSE 4,
and only 29 of those (the prime tetrachords) cause
TRICHORD_TRANSPOSE 4 to be invoked.  If TRICHORD_TRANSPOSE 4
were moved leftward in the larger test expression -- for
example, TRICHORD_TRANSPOSE 4 AND PR AND CD 4 -- the
preceding example would have yielded the same results, but
also would have required a far greater amount of time.


SCGROUPS: A Sample Script

     This section offers a detailed account of "SCGROUPS," a
sample script which incorporates many mod12 features












                                       mod12 User Guide - 98

outlined in earlier sections.  All of the code described
here is available in the file "sample.scr" included on your
mod12 distribution disk.  Assuming "sample.scr" is in the
current directory or folder, load it with this command:

-----

  mod12 > read "sample.scr"

-----

     SCGROUPS identifies the set classes which would result
if some arbitrary, one-to-one mapping were additionally
included along with transposition and inversion among the
canonical transformations.  For example, the M5
transformation has often been proposed in such a context.
Under M5, each instance of 2-2 maps onto some form of
itself.  The standard Tn/TnI set-class boundaries are
similarly maintained in the cases of 2-3, 2-4, and 2-6.
However, the members of set class 2-1 map onto those of 2-5
under M5, and the members of 2-5 map onto those of 2-1.
Consequently, when M5 is taken as canonical, only five
dyadic set classes exist: 2-1/5, 2-2, 2-3, 2-4, and 2-6.  Of
course, M5 is only one of a great many possible candidate
mappings.  Morris (1982) presents a few other possibilities,
and explores some general principles underlying the study of
such mappings.

     SCGROUPS is a procedure taking two arguments, a set
cardinality and a user-defined operator string, which must
represent a one-to-one mapping.  It displays the Forte names
of sets in the "exotic" set classes of the specified
cardinality under the specified mapping.  For example, the
first entry below rehearses our earlier considerations of
the M5 transform, while the second entry shows the
trichordal set classes arising under Morris's (1982, 116)
AL3 mapping:

-----

  mod12 > scgroups 2 05a3816b4927 ; M5 expressed as a user-defined operator

  -----
  2-1    2-5
  -----
  2-2
  -----
  2-3
  -----
  2-4
  -----
  2-6













                                       mod12 User Guide - 99

  -----

  mod12 > scgroups 3 0b29476583a1 ; Morris's AL3 mapping

  -----
  3-1    3-2    3-7    3-9
  -----
  3-3    3-4    3-11
  -----
  3-5    3-10
  -----
  3-6
  -----
  3-8
  -----
  3-12
  -----

-----

     The relevant portions of "sample.scr" are shown below.
Three macros are defined here.  The main procedure is
SCGROUPS_, defined at lines 1 through 39, and wrapped in
SCGROUPS, the macro defined at line 40.  SCGROUPS-OFF,
defined at lines 41 through 44, is included only for
convenience.  Once you have finished with the sample script,
entering SCGROUPS-OFF by itself removes all traces of the
script from memory.

-----

  macro "scgroups_"                                                        /*  1 */ \
    local "CARD" int "XFRM" op                                             /*  2 */ \
      seq + for {} maceq "CARD" "" or maceq "XFRM" ""                      /*  3 */ \
              break toplevel                                               /*  4 */ \
                display nl "ERROR > Cardinality and a user-defined "       /*  5 */ \
                           "operator string must be specified."            /*  6 */ \
          + for op XFRM 12-1 not eq 12-1                                   /*  7 */ \
              break toplevel                                               /*  8 */ \
                display nl "ERROR > The user-defined operator must "       /*  9 */ \
                           "be a one-to-one mapping."                      /* 10 */ \
          + for 31000 ..                                                   /* 11 */ \
              break 0                                                      /* 12 */ \
                local "USER"                                               /* 13 */ \
                  seq * macro input "USER"                                 /* 14 */ \
                              nl "This program will delete all records "   /* 15 */ \
                              "in the range 31000..32000."                 /* 16 */ \
                              nl "If this is acceptable, enter YES: "      /* 17 */ \
                      * for {} not maceq "USER" "yes"                      /* 18 */ \
                          break toplevel                                   /* 19 */ \
                            display "Program aborted"                      /* 20 */ \
          + delete 31000..                                                 /* 21 */ \













                                      mod12 User Guide - 100

          + display nl                                                     /* 22 */ \
          + for univ pr and cd CARD and not eqdb 31000..                   /* 23 */ \
              seq * quiet on                                               /* 24 */ \
                  * move 31000..32000 31000                                /* 25 */ \
                  * record at 31500 ?u0                                    /* 26 */ \
                  * for 31500..                                            /* 27 */ \
                      for univ sc ?u1                                      /* 28 */ \
                        for pf op XFRM ?u2 not eqdb 31500..                /* 29 */ \
                          record ?u3                                       /* 30 */ \
                  * sort 31500..                                           /* 31 */ \
                  * quiet off                                              /* 32 */ \
                  * display "-----" nl                                     /* 33 */ \
                  * for 31500..                                            /* 34 */ \
                      seq : for {} intgt charsonline 70 display nl         /* 35 */ \
                          : display name ?u1 tab 7                         /* 36 */ \
                  * display nl                                             /* 37 */ \
          + display "-----" nl                                             /* 38 */ \
          + delete 31000..                                                 /* 39 */

  macro "scgroups" fence call "scgroups_" ; the wrapper                    /* 40 */

  macro "scgroups-off"                                                     /* 41 */ \
    seq : macro off "scgroups_"                                            /* 42 */ \
        : macro off "scgroups"                                             /* 43 */ \
        : macro off "scgroups-off"                                         /* 44 */

-----

     Over half of SCGROUPS_ is dedicated to the user
interface, checking arguments and formatting the display.
Most of the "real" work is handled at lines 23 through 37,
but even some of those lines -- for example, lines 24, 31,
and 32 -- reflect interface concerns.  Although not
recommended as a general strategy, you may find it
convenient sometimes to take a different tack, and cut
corners on the interface in "throwaway" scripts intended
exclusively for your own use.

     Lines 3 through 6 check whether the required arguments
are supplied.  Those arguments, pulled off the CALL-supplied
parameter list with the INT and OP initSpec tokens of line
2, are tested through MACEQ at line 3.  Null expansions
there for "CARD" or "XFRM" indicate that the user's
parameter list was syntactically incorrect.  In that case,
the TOPLEVEL BREAK at lines 4 through 6 signals the problem
and aborts the procedure.

     Lines 7 through 10 check whether the user-defined
operator is in fact one-to-one.  If it is not, then some pcs
from the aggregate will be lost under the mapping, and the
test at line 7 will return true.  That in turn will invoke
the TOPLEVEL BREAK at lines 8 through 10, which identifies
the error and aborts the procedure.












                                      mod12 User Guide - 101


     SCGROUPS uses the database range 31000..32000 as a
scratch pad.  Any sets currently stored in that range will
be deleted once SCGROUPS gets underway.  Line 11's FOR
command checks whether any set does in fact currently reside
in that range.  If so, the loop BREAK's at line 12, and the
LOCAL command of lines 13 through 20 gives the user the
option of backing out of the entire procedure.  The MACRO
INPUT command of lines 14 through 17 prompts the user with
that option, and then stores the user's response in "USER."
(Although not necessary, "USER" is defined locally because
its use is restricted to these few lines.)  If the MACEQ
test at line 18 shows that the user answered in the
affirmative, the TOPLEVEL BREAK of line 19 terminates the
procedure after DISPLAY'ing a message at line 20.
Otherwise, control passes to line 21, which deletes any
records in the scratch pad range.

     The main SCGROUP algorithm unfolds at lines 23 through
37.  There, the range 31500.. is treated as a construction
area for building the set-class group under immediate
consideration.  Once that group is complete, 31500.. is
SORT'ed and its contents DISPLAY'ed.  Any record in 31500..
is then MOVE'd down to the range 31000.., which serves as a
storage area for all previously considered sets.  Since any
given cardinality will never represent more than fifty
primes, there is no danger of the storage area spilling over
into the work area.

     The level 0 FOR loop at line 22 supplies "seed" sets
for each set-class group, which then "grow" in the work area
tended by the nested FOR loops of lines 27 through 30.  Any
seed set which passes the test at line 23 is guaranteed to
be a prime (PR) of the appropriate cardinality (CD CARD)
which has not been previously considered and subsequently
stored in the scratch pad area (NOT EQDB 31000..).

     If such a seed set is found, QUIET is first turned on
at line 24 to suppress any unwanted displays during
intermediate processing.  Next, line 25 MOVE's all sets in
the scratch pad, including any recorded in the work area
during a previous pass through the level 0 FOR loop, to
consecutive slots in the lower reaches of the storage area.
This compresses the space in which sets are stored, filling
in the "hole" between work and storage areas with old work
area sets, and effectively clearing the work area for a new
pass.  Line 26 then "plants" the seed set at the first slot
in the work area, putting the next RECORD entry point at
31501.

     The nested FOR loops of lines 27 through 30 consider
new, "second generation" TnI set types exposed when all













                                      mod12 User Guide - 102

transpositions and inversions of the seed set (line 28) are
transformed under the "exotic" mapping (line 29).  We know
the sets are "new" because they have passed the NOT EQDB
31500.. test of line 29, and so have not been previously
considered and stored.  Any such second generation set is
then itself planted in the current work area at the next
available slot (line 30), and its progeny are considered.
If new, "third generation" set types are found among these
progeny, they too are added to the current work area, and
their progeny in turn come under scrutiny.  This process
repeats until no new set types result.

     Some additional explanation is in order regarding the
iteration domain of line 27's level 1 FOR loop.  At first,
only the original seed set is in the work area when that
loop commences, but each new-generation set is added at the
next available slot in the work area as the loop progresses.
Consequently, the set of sets actually iterated over by line
27's level 1 FOR is not necessarily fixed as the loop
begins, but may expand dynamically over the course of the
loop.

     Once all sets in the work area have been considered
along with their progeny, the work area is SORT'ed at line
31.  This step is not necessary, but allows for a prettier
display, since any successive generations there were not
necessarily added in Forte ordinal-number order.  Console
output is then restored at line 32, a visual separator
DISPLAY'ed at line 33, and the sorted contents of the work
area are DISPLAY'ed in the level 1 FOR loop of lines 34
through 36.  Before DISPLAY'ing each set-class type name at
line 36, line 35 checks CHARSONLINE to conditionally include
line breaks.  This step is also not strictly necessary, but
omitting it would leave us at the mercy of the operating
system's screen wraparound logic.

     Control drops down to line 38 when all seed sets of the
specified cardinality are exhausted.  A final separator bar
is DISPLAY'ed there, and then SCGROUPS cleans up after
itself by DELETE'ing the entire scratch pad area at line 39.

     One interesting aspect of SCGROUPS is its use of the
database for nonanalytical purposes.  Other nonalytical uses
are possible, too.  For example, a range in the database
might be set aside as a vector or matrix, and an integer
function could be defined to map array indices onto database
ids.  Treating the database like this opens the way for
considering ordered and partially ordered collections of
pitch classes in mod12.
















                                      mod12 User Guide - 103

ACKNOWLEDGMENT: An Essential Script

-----

  for univ                                                 \
    display nl "{" pcs ?u0 "} was named by "               \
               "ALLEN FORTE"                               \
               "."

-----


Works Cited

       Forte, Allen.  1973.  The Structure of Atonal Music.
               New Haven: Yale University Press.

       -----.  1988.  "Pitch-Class Set Genera and the Origin
               of Modern Harmonic Species." Journal of Music
               Theory 32.2: 187-270.

       Friedmann, Michael L.  1990.  Ear Training for
               Twentieth Century Music.  New Haven: Yale
               University Press.

       Lewin, David.  1987.  Generalized Musical Intervals
               and Transformations.  New Haven: Yale
               University Press.

       Morris, Robert D.  1982.  "Set Groups,
               Complementation, and Mappings among Pitch-
               Class Sets."  Journal of Music Theory 26.1:
               101-144.

       -----.  1987.  Composition with Pitch-Classes.  New
               Haven: Yale University Press.

       Rahn, John.  1980.  Basic Atonal Theory.  New York:
               Longman.



























                                      mod12 User Guide - 104


                        APPENDIX A.

                      Catalog of Tests

     All built-in mod12 tests are listed below along with
brief descriptions.  Type HELP followed by a test name for
details and examples.

       AC      AC setx.  True iff the implied operand is an
               abstract complement of setx.

       ASB     ASB setx.  True iff the implied operand is a
               proper, abstract subset of setx.

       ASP     ASP setx.  True iff the implied operand is a
               proper, abstract superset of setx.

       AZ      AZ.  True iff the implied operand is a z set.

       CD      CD intx.  True iff the implied operand is of
               cardinality intx.

       CDG     CDG intx.  True iff the implied operand is of
               cardinality greater than intx.

       CDL     CDL intx.  True iff the implied operand is of
               cardinality less than intx.

       CM      CM.  True iff the implied operand maps into
               its complement under transposition or
               inversion.

       CMN     CMN setx intx.  True iff the number of
               elements common to the implied operand and
               setx is equal to intx.

       CMNG    CMNG setx intx.  True iff the number of
               elements common to the implied operand and
               setx is greater than intx.

       CMNL    CMNL setx intx.  True iff the number of
               elements common to the implied operand and
               setx is less than intx.

       CMNT    CMNT patternx.  True iff the comment
               associated with the implied operand matches
               the pattern specified by patternx.

       EMB     EMB setx intx.  True iff exactly intx
               transpositions or inversions of the implied
               operand are included in setx.













                                      mod12 User Guide - 105


       EMBG    EMBG setx intx.  True iff more than intx
               transpositions or inversions of the implied
               operand are included in setx.

       EMBL    EMBL setx intx.  True iff less than intx
               transpositions or inversions of the implied
               operand are included in setx.

       EQ      EQ setx.  True iff the implied operand is
               identical to setx.

       EQDB    EQDB rangex.  True iff the implied operand
               set is represented in the database at the
               range rangex.

       GEN     GEN setx.  True iff setx can be exhaustively
               partitioned into subsets belonging to the
               same TnI class as the implied operand.

       GENUS   GENUS intx.  True iff the operand set is
               included within the Forte set-class genus
               specified by intx.

       ICM     ICM.  True iff the implied operand maps into
               its complement under some inversion.

       IDEQ    IDEQ intx.  True iff the implied operand's
               database record id is equal to intx.

       IDGT    IDGT intx.  True iff the implied operand's
               database record id is greater than intx.

       IDLT    IDLT intx.  True iff the implied operand's
               database record id is less than intx.

       IEMB    IEMB setx intx.  True iff exactly intx
               inversions of the implied operand are
               included in setx.

       IEMBG   IEMBG setx intx.  True iff more than intx
               inversions of the implied operand are
               included in setx.

       IEMBL   IEMBL setx intx.  True iff less than intx
               inversions of the implied operand are
               included in setx.

       IINC    IINC setx intx.  True iff exactly intx
               inversions of setx are included in the
               implied operand.














                                      mod12 User Guide - 106

       IINCG   IINCG setx intx.  True iff more than intx
               inversions of setx are included in the
               implied operand.

       IINCL   IINCL setx intx.  True iff less than intx
               inversions of setx are included in the
               implied operand.

       INC     INC setx intx.  True iff exactly intx
               transpositions or inversions of setx are
               included in the implied operand.

       INCG    INCG setx intx.  True iff more than intx
               transpositions or inversions of setx are
               included in the implied operand.

       INCL    INCL setx intx.  True iff less than intx
               transpositions or inversions of setx are
               included in the implied operand.

       INTEQ   INTEQ intx inty.  True iff intx equals inty.

       INTGT   INTGT intx inty.  True iff intx is greater
               than inty.

       INTLT   INTLT intx inty.  True iff intx is less than
               inty.

       INV     INV setx.  True iff some inversion of the
               operand set is identical to setx.

       IPR     IPR.  True iff the implied operand inverts
               into its prime form.

       ISB     ISB setx.  True iff some inversion of the
               implied operand is a proper subset of setx.

       ISP     ISP setx.  True iff some inversion of the
               implied operand is a proper superset of setx.

       ISYM    ISYM.  True iff the implied operand is
               invariant under some inversion.

       ISYMN   ISYMN intx.  True iff the implied operand is
               invariant under T intx I.

       K       K setx.  True iff the implied operand is in
               Forte's K relation with setx.

       KH      KH setx.  True iff the implied operand is in
               Forte's Kh relation with setx.














                                      mod12 User Guide - 107

       LC      LC setx.  True iff the implied operand is the
               literal complement of setx.

       LSB     LSB setx.  True iff the implied operand is a
               literal, proper subset of setx.

       LSP     LSP setx.  True iff the implied operand is a
               literal, proper superset of setx.

       MAC     MAC macName patternx.  True iff some part of
               the expansion of macro macName matches the
               pattern specified by patternx.

       MACEQ   MACEQ macName patternx.  True iff the entire
               expansion of macro macName matches the
               pattern specified by patternx.

       MACGT   MACGT macName patternx.  True iff the entire
               expansion of macro macName is lexically
               greater than the pattern specified by
               patternx.

       MACLT   MACLT macName patternx.  True iff the entire
               expansion of macro macName is lexically less
               than the pattern specified by patternx.

       MCM     MCM.  True iff the implied operand maps into
               its complement under some TnM or TnMI.

       MSYM    MSYM.  True iff the implied operand is
               invariant under some TnM or TnMI.

       MUL     MUL setx.  True iff the implied operand maps
               onto setx under some TnM or TnMI.

       OPSYM   OPSYM userOperator.  True iff the implied
               operand is invariant under the composition of
               some Tn and the user-defined operator
               userOperator.

       OPSYMN  OPSYMN userOperator intx.  True iff the
               implied operand is invariant under the
               composition of T intx and the user-defined
               operator userOperator.

       PART    PART setlistx.  True iff the implied operand
               can be exhaustively partitioned into
               transpositions or inversions of the sets in
               setlistx.

       PR      PR.  True iff the implied operand is a prime
               form according to the current prime table.













                                      mod12 User Guide - 108


       PRTN    PRTN.  True iff the implied operand is a
               prime form in the Tn system (no inversion)
               according to the current prime table.

       R0      R0 setx.  True iff the implied operand is in
               Forte's R0 relation with setx.

       R1      R1 setx.  True iff the implied operand is in
               Forte's R1 relation with setx.

       R2      R2 setx.  True iff the implied operand is in
               Forte's R2 relation with setx.

       RP      RP setx.  True iff the implied operand is in
               Forte's Rp relation with setx.

       SC      SC setx.  True iff the implied operand is in
               the same TnI set class as setx.

       SCDB    SCDB rangex.  True iff some transposition or
               inversion of the implied operand set is
               represented in the database at the range
               rangex.

       TCM     TCM.  True iff the implied operand maps into
               its complement under some transposition.

       TEMB    TEMB setx intx.  True iff exactly intx
               transpositions of the implied operand are
               included in setx.

       TEMBG   TEMBG setx intx.  True iff more than intx
               transpositions of the implied operand are
               included in setx.

       TEMBL   TEMBL setx intx.  True iff less than intx
               transpositions of the implied operand are
               included in setx.

       TGEN    TGEN setx.  True iff setx can be exhaustively
               partitioned into subsets which are
               transpositions of the implied operand.

       TINC    TINC setx intx.  True iff exactly intx
               transpositions of setx are included in the
               implied operand.

       TINCG   TINCG setx intx.  True iff more than intx
               transpositions of setx are included in the
               implied operand.














                                      mod12 User Guide - 109

       TINCL   TINCL setx intx.  True iff less than intx
               transpositions of setx are included in the
               implied operand.

       TPART   TPART setlistx.  True iff the implied operand
               can be exhaustively partitioned into
               transpositions of the sets in setlistx.

       TPR     TPR.  True iff the implied operand is a
               transposition of its prime form.

       TR      TR setx.  True iff the implied operand is a
               transposition of setx.

       TSB     TSB setx.  True iff some transposition of the
               implied operand is a proper subset of setx.

       TSP     TSP setx.  True iff some transposition of the
               implied operand is a proper superset of setx.

       TSYM    TSYM.  True iff the implied operand is
               invariant under some transposition (excluding
               T0).

       TSYMN   TSYMN intx.  True iff the implied operand is
               invariant under T intx.

       UNEQ    UNEQ setx.  True iff the implied operand is
               identical with setx. (Synonymous with EQ.)

       UNGT    UNGT setx.  True iff the implied operand
               follows setx in the FOR UNIV iteration order.

       UNLT    UNLT setx.  True iff the implied operand
               precedes setx in the FOR UNIV iteration
               order.

       Z       Z setx.  True iff the implied operand is in
               the z relationship with setx.


























                                      mod12 User Guide - 110


                        APPENDIX B.

             Catalog of Commands and Procedures

     All mod12 commands and predefined macro procedures are
listed below along with brief descriptions.  Type HELP
PREDEF for general information on predefined macros.

     Immediately following each command or procedure name in
the list is a page number (sometimes more than one) which
refers you to further information in this guide.  Online
help is also available for each command and procedure.  Type
HELP followed by a command or procedure name for more
information.

       AUTO          69.  Macro.  Registers a string for
                     automatic processing whenever a set is
                     entered for identification.

       BREAK         37.  Command.  Aborts processing in FOR
                     loops, SEQ chains, and other contexts.

       CALL          88.  Command.  Invokes macro procedures
                     and functions with optional parameter
                     lists.

       CLIP-COMMENT  15.  Macro.  Adjusts display length for
                     comments.

       CLS           47.  Macro.  Clears the screen by
                     displaying twenty-five newlines.

       COMMON-TONE   20.  Macro.  Displays common-tone
                     vectors.

       COMPACT       14.  Macro.  Turns compact mode on and
                     off, which determines how the pc
                     contents of sets are displayed.

       DELETE        64.  Command.  Deletes records from the
                     database.

       DISPLAY       44.  Command.  Sends formatted text to
                     the current output.

       EMBED         20.  Macro.  Displays embedding
                     information.

       EXIT          4.  Command.  Terminates the current
                     mod12 session.














                                      mod12 User Guide - 111

       EXPAND        73.  Macro.  Displays macro expansions
                     without evaluating them.

       FENCE         82.  Command.  Blocks macro expansion.

       FOR           30, 59.  Command.  Provides general
                     iteration and conditional execution
                     capabilities.

       HELP          4.  Command.  Starts mod12's online
                     help facility.

       IS            22.  Macro.  Applies tests to sets,
                     displaying "yes" for success and "no"
                     for failure.

       LOAD          63.  Macro.  Loads a SAVE'ed file into
                     the current database.

       LOCAL         84, 90.  Command.  Establishes a
                     temporary environment for interpreting
                     macros.

       LOG           50.  Command.  Writes a transcript of
                     the current session to a file.

       MACRO         72, 77.  Command.  Defines, undefines,
                     and lists macros.

       MAP           21.  Macro.  Lists all Tn, TnI, TnM,
                     and TnMI mappings for pairs of sets.

       MOVE          65.  Macro.  Moves records in the
                     database.

       PRM2          14.  Command.  Sets the default prime
                     form table.

       QUIET         47.  Macro.  Turns quiet mode on and
                     off, which suppresses unwanted console
                     displays.

       READ          47.  Command.  Temporarily resets the
                     current, default input source.

       RECORD        52.  Command.  Adds sets to the
                     database, and lists occupied database
                     slots.

       RETURN        94.  Command.  Aborts processing in
                     CALL'ed macro procedures and functions,
                     returning values in the case of
                     functions.












                                      mod12 User Guide - 112


       SAVE          62.  Macro.  Writes the current
                     database to a file.

       SCRATCH       54.  Macro.  Prevents a set from being
                     added to the database when automatic
                     recording is on.

       SEQ           35.  Command.  Executes a sequence of
                     commands in order.

       SHOW          26, 57.  Macro.  Conditionally displays
                     sets from the pc set universe and the
                     database.

       SORT          66.  Command.  Sorts the database in
                     any of four ways.

       SUBSETS       21.  Macro.  Displays names of mutual
                     subsets meeting optional criteria.

       TALLY         28, 57.  Command.  Displays set-class
                     distributions according to arbitrary
                     criteria; also an integer function.

       TRACE         39.  Command.  Provides debugging
                     support.

       VECTORS       20.  Macro.  Displays interval vectors
                     and TnI common-tone vectors.

       WRITE         49.  Command.  Temporarily resets the
                     current, default output destination.



