[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string parsing/preparation for latex

From: Jon Wilson
Subject: Re: string parsing/preparation for latex
Date: Mon, 14 Nov 2005 19:50:12 -0600
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050324)

Hi Stephen,
Yeah, I guess you're right.  Like I said, I'm new to the whole idea of
macros, and I'm kind of looking for a really good use-case for the
things.  Can you suggest a non-contrived situation in which a macro
would be the best solution?

Stephen Compall wrote:
On Wed, 2005-11-09 at 07:24 -0600, Jon Wilson wrote:

scheme->LaTeX would have to be a macro, then it receives its arguments
before they are evaluated.  Unless of course I'm mistaken about the
nature of macros.  (I'm still relatively new to the idea.)

Yes, but you'd lose more than you'd gain by making it a macro.  Unless
you really wanted to do something crazy like:

(define-syntax scheme->LaTeX
  (syntax-rules (+ /)
    ((_ (+ f1 f2 ... f3))
     (string-append "(" (scheme->LaTeX (+ f1 f2 ...))
                    " + " (scheme->LaTeX f3) ")"))
    ((_ (+ f1))
     (scheme->LaTeX f1))
    ((_ (/ f1 f2 f3 ...))
     (string-append "\frac{" (scheme->LaTeX f1)
                    "}{" (scheme->LaTeX (* f2 f3 ...)) "}"))
    ;;and so on....

Of course that has many drawbacks of its own.  Better to just handle it
in functions, which, for example, wouldn't have the spurious parenthesis
problem of the multiple + argument syntax, and so on.  Not to mention
the added benefit of scheme->LaTeXing forms unknown at load-time without
using eval.

Remember Norvig's first step to writing a macro: Decide if the macro is
really necessary.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]