Sorry, I just saw this after following a different strategy! For now, I won't be needing this, but thank you for the advice. It might come in handy later if there's more MF work to do.
--Owen On Sun, May 31, 2020 at 5:33 PM Christopher Heckman < [email protected]> wrote: > On Sun, May 31, 2020 at 12:50 AM <[email protected]> wrote: > > > > Date: Sat, 30 May 2020 15:41:31 -0700 > > From: Owen Lamb <[email protected]> > > To: Werner LEMBERG <[email protected]>, [email protected] > > Subject: Metafont optional parameters > > Message-ID: > > <CAHpoxV-+XVN3x5QU6gh0yMkGXp6tSu4t-y7H4QVGSWdx= > [email protected]> > > Content-Type: text/plain; charset="UTF-8" > > > > Hi all, > > > > I'd like to add an optional parameter for smuflcode to fet_beginchar, so > > that I don't have to take two lines redeclaring the variable in every > > glyph. Ideally, it won't have to be optional once every character has it, > > but in the meantime, it would help with testing individual characters' > new > > encodings. > > > > I wasn't able to find whether MF supports optional parameters, only that > > certain built-in functions have them. Does anyone with MF experience know > > if it does, and, if so, how to put one in? > > > > Thanks, > > Owen > > The METAFONTbook shows how to handle a variable number of arguments to > a macro. It gives examples about how to write max() with a variable > number of parameters. > > If you want to allow at least one parameter, then look at Appendix D > (Dirty Tricks), trick #2 (pp. 290-291 in my version): > > vardef max(text t) = > let switch_ = firstset_; > for u = t: switch_ u > u_: u_ := u ;fi endfor > u_ enddef; > > def firstset_ primary u = > setu_ u; let switch_ = if; if false: enddef. > > If you want to allow at least two parameters (but not one), it's a bit > easier; the code is on page 266 of Appendix B (Basic Operations): > > vardef max(expr u)(text t) = % t is a list of numerics, pairs or strings > save u_; set u_ u; for uu = t: if uu > u_: u_ := uu; fi endfor > u_ enddef; > > def setu_ primary u = > if pair u: pair u_ elseif string u: string u_ fi; > u_ = u enddef; > > Any typos are my fault, not DEK's. > > --- Christopher Heckman > >
