Re: (dsssl) newbie coding question

Subject: Re: (dsssl) newbie coding question
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Tue, 2 Oct 2001 01:52:04 -0500
Quoting Trent Shipley <tcshipley@xxxxxxxxxxxxx>:
> Unfortunately constructs like the below dont work.  Depending on the
> variation that I try the OpenJade parser says there is no current 
> node to provide a context, or the function fails to return a value of
> type style, or it an object having a given id number can't be found. 
> (define p-style-prime
>   (cond ((has-ancestor "NOTE")(note-p-style))
>         (else (standard-p-style))))
   The problem with this (define) has to do with DSSSL's processing
model.  Top-level (define)s, such as this, are evaluated before
document processing begins.  Therefore, there is no "current node" to
examine.  What you want is to create a *procedure* which, upon every
invocation, will evaluate the properties of the current node to
determine which style to use:

     (define (p-style-prime n)
       (cond ((have-ancestor? "NOTE" n) note-p-style)
             (else standard-p-style)))

   Note the parens around "p-style-prime", indicating a procedure
definition, with an argument, "n".  Also, you would not want the
parens around "note-p-style" or "standard-p-style", as these are style
values, not procedures.  You don't want to invoke the style, you just
want to return it.
   Now, the usage would look like:

       (make paragraph
             use: (p-style-prime (current-node))

   Note the parens, again, around "p-style-prime", to invoke it as a
procedure, passing the result of the (current-node) procedure, which,
of course, returns the "current node" (or, "this-node"). :)

> Ideally the cast would be polymorphic so that a call to
> p-style-prime uses the current (nodal) context.  However, a call with
> the form (p-style-prime this-node) would be fine provided someone can
> tell me how to name "this-node".
   Well, we have the latter, above.  Wanna shoot for the former?
Let's use DSSSL's "optional" feature to provide a default for the
argument to our procedure:

     (define (p-style-prime #!optional (n (current-node)))
       (cond ((have-ancestor? "NOTE" n) note-p-style)
             (else standard-p-style)))

   The only change here is declaring that the "n" argument is
"optional", and providing a default for it.  Unless you explicitly
specify a value for "n" in your invocation of (p-style-prime), DSSSL
will automatically supply the result of the (current-node) procedure
as a default value for "n".  Thus, the usage becomes:

       (make paragraph
             use: (p-style-prime)

   I hope this is all clear.  If not, let me know. :)

-Brandon :)

 DSSSList info and archive:

Current Thread