Re: Nodes and counting

Subject: Re: Nodes and counting
From: Dave Love <d.love@xxxxxxxx>
Date: 30 Sep 1997 20:11:01 +0100
>>>>> "Frank" == Frank Christoph <christo@xxxxxxxxxxxxxxxxxx> writes:

 Frank> At the risk of making a mountain out of a molehill, how about this:

I don't think it's been tested!

 Frank> (define (or-map f #!rest bs)
 Frank>   (apply or (map f bs))

You can't apply `or'.

 Frank> (define (curry f x) ; N.B., arity(f) > 1
 Frank>    (lambda (!#rest xs) (apply f (cons x xs))))

[It's better to avoid consing and write `(apply f x xs)' and,
actually, f could be unary.]

 Frank> (define (gid=? x #!optional str)
 Frank>  (cond
 Frank>    ((and (node-list? x) (string? str))
 Frank>       (string=? x str))
 Frank>    ((string? x)
 Frank>       (string=? (current-node) x))
 Frank>    (else
 Frank>       (error "gid=?: expected (gid=? [<node>] <string>)"))))

The args to `string=?' are clearly wrong there.

 Frank> Here's a slightly shorter version, but I don't think Jade
 Frank> implements node-list-some?. (Of course, you can always
 Frank> implement it yourself.  There's a sample in the standard.):

 Frank> (let ((pred (lambda (n) (or-map (curry gid=? n) "child2" "child3")))
 Frank>     (if (node-list-some? pred (follow (current-node))) 0em 2em))

Could the predicate be just this?
  (lambda (snl) (member (gi snl) '("CHILD2" "CHILD3")))

 Frank> Remember, you have to be careful with or-map.  
 Frank> In a lazy language it's an occasionally useful combinator, 
 Frank> but in DSSSL the #!rest arguments will all get evaluated no
 Frank> matter what they are.  Compare:

 Frank> (define (undef) (undef))
 Frank> (define (id x) x)

 Frank> (or #t (undefined)) ==> #t
 Frank> (or-map id #t (undefined)) ==> <doesn't terminate>

 Frank> As long as you apply or-map only to constants you won't run
 Frank> into any trouble, though.

This is surely nothing to do with the particular function that's given
the bogus argument!  It does, though, explain why you can't apply `or'
-- it's a special form.


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


Current Thread