Re: Nodes and counting

Subject: Re: Nodes and counting
From: christo@xxxxxxxxxxxxxxxxxx (Frank Christoph)
Date: Wed, 1 Oct 1997 16:13:31 +0900
> I don't think it's been tested!

Nope, it sure hasn't!  Maybe if OpenDoc had survived, I would have a Scheme
interpreter component integrated with my e-mailer, but that is a dead dream.

Nonetheless, thanks for pointing out my errors.

>  Frank> (define (or-map f #!rest bs)
>  Frank>   (apply or (map f bs))
> 
> You can't apply `or'.

Indeed, it appears you can't.  At least that helps prevent one from running
into the trickiness with short-circuiting and non-termination.

>  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.]

Wow, it never occurred to me that currying a unary function could be
defined to produce a thunk... On second thought, I guess it is obvious
since () is a 0-place product.

>  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.

Of course I just forgot the gi's here.  This should have read:

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

>  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")))

Well, only if you want it to be simple... :)

Maybe I should refrain from `making mountains' from now on (at least in public
:)...

--FC

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


Current Thread