Answer to Exercise 68

| ANSWER TO EXERCISE 68
    Constant MAX_FOOTNOTES 10;
    Array footnotes_seen -> MAX_FOOTNOTES;
    Global footnote_count;
    [ Note n i pn;
        for (i=0:i<footnote_count:i++)
            if (n==footnotes_seen->i) pn=i;
        if (footnote_count==MAX_FOOTNOTES) "** MAX_FOOTNOTES exceeded! **";
        if (pn==0) { pn=footnote_count++; footnotes_seen->pn=n; }
        print " [",pn+1,"]";
    ];
    [ FootnoteSub n;
        if (noun>footnote_count)
            "No footnote [", noun, "] has been mentioned.";
        if (noun==0) "Footnotes count upward from 1.";
        n=footnotes_seen->(noun-1);
        print "[",noun,"]  ";
        switch(n)
        {   0: "This is a footnote.";
            1: "D.G.REG.F.D is inscribed around English coins.";
            2: "~Jackdaws love my big sphinx of quartz~, for example.";
        }
    ];
    Verb "footnote" "note" * number              -> Footnote;
And then you can code, for instance,
        print "Her claim to the throne is in every pocket ", (Note) 1,
           ", her portrait in every wallet.";

Back to the exercise in section 27

Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.