That took way too long to run down. But run it down I did. It works as intended, even if it’s… verbose.
Refactoring
I talked in my last post about some refactoring I wanted to do.
Polyhedron Tables Have Instructions [DONE]
This was a simple matter of some search and replace. A little funky, but not hard.
&&polypanD4
|1 @addEntry{ppDeityDomain}{1}{1}\
@addEntry{ppDeityDomain}{1}{5}\
@addEntry{ppDeityDomain}{1}{6}\
@addEntry{ppDeityDomain}{1}{7}
|1 @addEntry{ppDeityDomain}{1}{2}\
@addEntry{ppDeityDomain}{1}{5}\
@addEntry{ppDeityDomain}{1}{6}\
@addEntry{ppDeityDomain}{1}{8}
When I iterate through this pantheon (done elsewhere), as I process each pantheon entry it adds to another table. After the first entry is processed, I have a table that looks (nominally) like
&ppDeityDomain
|1 1
|1 5
|1 6
|1 7
I later iterate through this table to find out what domains I need to process.
Building Trappings
The simplest form of this is printing the list of domains. The (current) instruction for printing a deity is
|1 $polypan\t&toadSmallGodName, &polypanEpithet\n\
\tDomains: `=ppDeityDomain{0}`@iter\
{&ppDomainList{&ppDeityDomain{%{$ppDeityDomain+1}}}}
{@weight{ppDeityDomain}}{, }\n\
\n
(I learned the line continuation is more powerful than I’d thought… breaking these things down makes them so much more readable.)
The main bit of this snippet is iterating through ppDeityDomain
, looking up the domain indexes, and printing out the matching names.
Yes, this is more wordy than I like. @foreach
is coming soon.
A better example of building up trappings has to do with epithets. I have a generic set of base words used in generating epithets, and each domain can add to that set.
&&loadEpithets
|1 `=ppDeityDomain{0}`\
@iter{\
&ppDomainEpithets{&ppDeityDomain{%{$ppDeityDomain+1}}}\
}\
{@weight{ppDeityDomain}}
This goes through the deity’s domains, and applies the epithet components appropriate for each domain.
I expect this will be a generic ‘load all my stuff’ function, and get renamed. &loadDomainTrappings
or the like, then add more stuff in the @iter{}
.
Generate Trapping Details and Store
I haven’t done quite this yet, but I’m close. Tonight I was trying to focus on getting the table manipulation and iteration right.
I did do something quite similar, though. I have 35 domains and I wanted to have instructions for loading domain epithet components. For the first pass I wrote it out by hand — well, one template and lots of find and replace. I started to draft a Perl script to maintain this stuff, then realized I can use the @addResolved
function.
`=ppDomainList{0}`\
@iter{\
`=work{&ppDomainList{%{$ppDomainList+1}}}`\
@addResolved{ppDomainIndexes}{1}{$ppDomainList}\
`=work{&ppDomainList{$ppDomainList}}`\
@addResolved{ppDomainEpithets}{1}{\
\@appendTable{epithetActor}{ppActor$work}\
\@appendTable{epithetActs}{ppActs$work}\
\@appendTable{epithetActing}{ppActing$work}\
\@appendTable{epithetAction}{ppAction$work}\
}\
}{@weight{ppDomainList}}
This is not as complex as it looks. I iterate through the domain list, then build a up a table that has instructions for building epithet tables.
- Initialize my domain table iterator.
- Walk through the list
- Capture the name of the domain, with no output.
- Add the domain index to
&ppDomainIndexes
(used when shuffling domains). - Add an entry to
&ppDomainEpithets
, with instructions appending domain-specific tables to the epithet tables. These take advantage of mixed-resolution syntax. I can have each entry contain domain-specific text (the domain name) and be instructions for later resolution.
I can add similar instructions for artifact names, special locations, place names, and so on, in the same manner.
New Changes
As is common, working on something and stretching its abilities prompts more ideas.
Line Continuation
For some reason (old school laziness?) I had decided to use a line continuation character (trailing backslash). This is proving to be a hindering pain. Considering the markers I use for the various line types, I’m thinking of getting rid of this. If the line is not marked as a new table or entry (etc.), treat it as a continuation of the previous line.
Better Error Messaging
This tool is really resilient. Unless you do something dumb like causing infinite recursion it’s unlikely to crash. It will give weird results if there are syntax errors, though… but maybe you meant to do what you wrote!
@foreach{table}
Table manipulations allow me to (ab)use tables as arrays. I find I’m often iterating through the entries of a table/array. It would be nice to just say “foreach entry” and let it roll. And more concise and less error-prone.
This one’s going in. I expect it will look like
@foreach{ppDeityDomain}{`&ppDomainEpithets{$$ppDeityDomain}`}
That is, for each domain the deity has, apply the ppDomainEpithets
table at the value of the current ppDeityDomain
entry. I haven’t decided how to express that. The current idiom would be &ppDeityDomain{$ppDeityDomain}
, but this comes up so often I think it is worth abbreviating. As shown above, the leading candidate is a ‘$$’ operator.
Closing Comments
This is not quite a general-purpose text engine, but it’s getting pretty powerful. I can now do things with it I never imagined when I wrote it (almost 30 years ago…).
There is still room for improvement. I’m finding things I can do, but not easily. Still, I can do them, and that counts for quite a bit.