RE: SOLUTION FOR : How can I add a new children in a node??

Subject: RE: SOLUTION FOR : How can I add a new children in a node??
From: "Frank A. Christoph" <christo@xxxxxxxxxxxxxxxxxx>
Date: Mon, 4 Oct 1999 18:46:31 +0900
I wrote

 (define (pc) (process-children))

mostly because I wanted to avoid the issue of higher-order functions, but
partly because I have developed a phobia against treating primitives in a
Scheme implementation as if they were normal higher-order functions. For
example,

 (define and sequential-and)

doesn't work, and you can't pass 'and' to another function.

In this case, though, there was no need to be so cautious on my part. (I
checked.)

WRT rebinding, T. Kurt Bond is right about both Scheme's behavior.
Personally, I don't play the "overloading game" so I don't pay it much mind,
but in Scheme you will notice that the following transcript shows that
Scheme resolves the definition of a top-level symbol dynamically, not
lexically:

 > (define (f) (+ 1 1))
 > (define + -)
 > (f)
 0

In DSSSL, too, there is a similar behavior (8.4) for primitives:

  The built-in definition of a variable may be replaced by a top-level
definition. The replacement
  definition shall be used for all references to that variable, even those
that occur in process
  specification parts preceding the part that contains the first top-level
definition.

So I could redefine the operation associated with uses of +, retroactively;
for example, in a later stylesheet module. Does the same hold for
process-children, i.e., does it qualify as a "built-in"? At the start of 8.5
it says, "This section describes the expression language's built-in
procedures," which seems to imply that there are no others. If that is so,
then process-children cannot be rebound, since it's not a built-in. OTOH, it
sure seems like a built-in to me, so maybe this ought to be clarified. There
is a place in clause 12 where it says that an <expression> in a
<style-language-body> should be interpreted as a
<style-language-expression>, but this says nothing about the nature of
built-ins...

(Personally, I think this rebinding behavior is pretty odd when you add it
to DSSSL's other unusual binding rule: that top-level rebindings of
_non_-primitives have no effect, i.e., only the first definition is
significant.)

What Brandon wrote about "storing the definition environment" is true about
lambda-calculus, but Scheme and DSSSL are not quite lambda-calculus.

--FC

Brandon Ibach wrote:
> Quoting T. Kurt Bond <tkb@xxxxxxxxxxxxxxxxxxx>:
> > Brandon Ibach writes:
> > > > (define pc process-children)
> > > >
> > >    Yes.  This would bind "pc" to the same procedure object that
> > > "process-children" is bound to.  The other form would, theoretically,
> > > bind "pc" to a new, zero-argument, procedure object which simply calls
> > > the procedure to which "process-children" is bound at the time of the
> > > definition.  I would think that a smart Scheme implementation would
> > > render these two the same, but I'm not positive.
> >
> > Actually,
> >
> >     (define (pc) (process-children))
> >
> > will bind pc to a new, zero-argument procedure as you suggested, but
> > when called it will actually call the procedure that
> > "process-children" is bound to when "pc" is called.  (This is probably
> > less of a difference in DSSSL than in Scheme, since DSSSL lacks the
> > imperative features of Scheme.)
> >
>    I'm fairly sure my take was correct (having gone back now and
> checked the relevant portions of the DSSSL spec), but let me know if
> I've missed something.  By definition:
> 	(define (pc) (process-children))      becomes
> 	(define pc (lambda () (process-children)))
>    Lambda effectively "stores" the definition environment, recreating
> it when the procedure is called, changing it only by extending it with
> bindings for the arguments.  Thus, when the procedure is executed,
> "process-children" will be bound to whatever it was bound to at the
> time of the definition, even if it has been redefined to something
> else in the interim.
>    This raises an interesting question.  Is it possible to create a
> procedure that will call on the *current* environment, rather than its
> stored one?  For instance, in Postscript, I can do:
> 	/pc { process-children } bind def
> which would behave like lambda, in that it would replace all of the
> symbols in the procedure with their bound values (via the bind call)
> before binding the procedure to the "pc" symbol (via the def).  Or, I
> could do the same thing, without the bind, to have the symbol resolved
> at execution time.


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread