[racket] comments requested from users of SXML and PLT xexprs

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Wed Dec 22 22:11:15 EST 2010

Eli Barzilay wrote at 12/22/2010 08:04 PM:
> 6 minutes ago, Neil Van Dyke wrote:
>> Thanks for your comments, Eli.  I am still wavering on whether to do the permissive thing.  And I am also looking at whether Typed Scheme and/or "html-template" make the permissiveness less useful than before.
> Well, the problems that I ran into wouldn't have been different if there was a type system around -- changing a function still means changing call sites, etc.

Well, it seems that TR can tell the difference between ``(p "foo")'' 
(i.e., element) and ``((p "foo") ((p "bar"))'' (i.e., content) at the 
borders it guards.

Where those borders occur, I think depends on things like how much tools 
like "html-template" do for the programmer, and where else the 
programmer puts those borders.  Of course, I can still imagine likely 
cases in which splicing errors can occur within procedures.

BTW, initially, I am *not* trying to match all of SXML with TR rules, 
but instead just match objects like strings and the first two pairs of 
each list.  Once that's good, then I can measure the performance change 
when matching entire lists and their trees, and see if there's a problem 
and what I can do about it.

>> Permissiveness sure does make some things harder to implement and more computationally expensive.
> Why is it harder?  My experience so far is that the cost in terms of implementation complexity is very minor.


(xexp-char-ref-value '(& copy)) ;;==> copy
(xexp-char-ref-value '(& () ((() () (() copy) (()))) ())) ;;==> copy

(: xexp-char-ref-value (XexpNamedCharRef -> Symbol))
(define (xexp-char-ref-value char-ref)
  (or (let: loop-find-symbol : (U Symbol False)
            ((lst : Any (cdr char-ref)))
         ((null? lst) #f)
         ((pair? lst)
          (let ((head (car lst)))
            (cond ((symbol? head)
                   (%assert-only-xexp-extraneous-lists (cdr lst))
                  ((pair? head)
                   (cond ((loop-find-symbol head)
                          => (lambda (found)
                               (%assert-only-xexp-extraneous-lists (cdr 
                               (%assert-only-xexp-extraneous-lists (cdr 
                         ((loop-find-symbol (cdr head))
                          => (lambda (found)
                               (%assert-only-xexp-extraneous-lists (cdr 
                         (else (loop-find-symbol (cdr lst)))))
                  ((null? head) (loop-find-symbol (cdr lst)))
                  (else (raise-invalid-xexp-error
                         #:expected     "char-ref body"
                         #:invalid-xexp head
                         #:context-xexp char-ref)))))
         (else (raise-invalid-xexp-error
                #:expected     "proper list in char-ref body"
                #:invalid-xexp lst
                #:context-xexp char-ref))))
      (raise-invalid-xexp-error 'xexp-char-ref-value
                                #:expected     "char-ref"
                                #:invalid-xexp char-ref)))

>   (define (bp . body) (apply p style: "text-weight: bold;" body))
> it works, but I'd like to be able to use it with:
>   (bp style: "color: blue;" "blah blah")

I see what you mean.  In the case of the "style" attribute in HTML, I 
believe that recommended practice is to instead use CSS rules based on 
element names, "class" attributes, element structures, and possibly "id" 
attributes.  Perhaps in XML processing there are analogous problems, but 
perhaps the solution comes down to a transformation operation or a 
schema change.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101222/a83015ab/attachment.html>

Posted on the users mailing list.