unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* (ice-9 syncase)
@ 2004-10-04 20:18 Andy Wingo
  2004-10-05 19:30 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2004-10-04 20:18 UTC (permalink / raw)


Hey all,

I've been having some problems lately with syncase macros and modules.

Now, a specific problem that completely stumps me. I am getting SSAX to
work with r5rs macros. Part of SSAX's API are a set of macros to create
custom SAX parsers. They don't work, though:

guile> ssax:make-parser
$1 = #<macro! sc-macro>
guile> (ssax:make-parser)
ERROR: invalid syntax (find k-args (DOCTYPE . default) DOCTYPE val . others)
ABORT: (misc-error)

This same code me a more proper error about not putting the right
arguments if I put myself in the (sxml ssax) module first.

This error isn't very informative due to syncase stack cutting.
ssax:make-parser is a macro made by another macro, ssax:define-labeled-
arg-macro, which is also exported, and it starts off like this:

(define-syntax ssax:define-labeled-arg-macro
  (syntax-rules ()
    ((ssax:define-labeled-arg-macro
       labeled-arg-macro-name
       (positional-macro-name
	 (arg-name . arg-def) ...))
      (define-syntax labeled-arg-macro-name
	(syntax-rules ()
	  ((labeled-arg-macro-name . kw-val-pairs)
	    (letrec-syntax
	      ((find 
		 (syntax-rules (arg-name ...)
                 [...]

The interesting thing is that `find' is actually a local syntactic
binding. I could maybe understand if find were a toplevel binding, then
one would expect information about it to be stored in the module
somewhere (apparently on the variable). However, it's not toplevel.
Perhaps this is affected by the note on psyntax.ss:203:

;;; "let-syntax" and "letrec-syntax" are also treated as splicing
;;; constructs, in violation of the R4RS appendix and probably the R5RS
;;; when it comes out.  A consequence, let-syntax and letrec-syntax do
;;; not create local contours, as do let and letrec.  Although the
;;; functionality is greater as it is presently implemented, we will
;;; probably change it to conform to the R4RS/expected R5RS.

However, the `find' symbol is bound to a procedure within (sxml ssax).

I don't know what's going on here. Any ideas? Now I have to do crappy
things like

(use-modules (sxml ssax))
(define-module (sxml ssax))

to use these macros.

Thanks in advance,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: (ice-9 syncase)
  2004-10-04 20:18 (ice-9 syncase) Andy Wingo
@ 2004-10-05 19:30 ` Andy Wingo
  2004-10-18 12:39   ` Marius Vollmer
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2004-10-05 19:30 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]

Sorry to reply to my own message -- I haven't even seen the responses
yet :/

On Mon, 2004-10-04 at 22:18 +0200, Andy Wingo wrote:
> guile> ssax:make-parser
> $1 = #<macro! sc-macro>
> guile> (ssax:make-parser)
> ERROR: invalid syntax (find k-args (DOCTYPE . default) DOCTYPE val . others)
> ABORT: (misc-error)
> 
> This same code me a more proper error about not putting the right
> arguments if I put myself in the (sxml ssax) module first.

It also works if I:

(module-use! (current-module) (resolve-module '(sxml ssax)))

Note that's the module, and not the interface. I tried exporting all
bindings in (sxml ssax), but that's not enough. I suspect it has
something to do with the module eval closure.

In (sxml ssax), I reluctantly put this hack:

(module-use! (module-public-interface (current-module))
             (current-module))

So that users won't have to. I'm not happy, but it's better now.

As an example, I attached a file that parses an openoffice document and
outputs all words that aren't in the dictionary. Useful e.g. if you're
writing a document in multiple languages.

Cheers,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/

[-- Attachment #2: sxw2words --]
[-- Type: text/plain, Size: 2295 bytes --]

#!/usr/bin/guile -s
!#
(use-modules (sxml ssax)
             (os process)
             (ice-9 rdelim)
             (srfi srfi-14))

(or (= (length (program-arguments)) 2)
    (begin
      (display "usage: sxw2words SXW-FILE\n" (current-error-port))
      (exit 1)))

(define sxw-file (cadr (program-arguments)))

(define (get-dict-words)
  (let ((port (open-input-file "/usr/share/dict/words")))
    (let lp ((words '()) (line (read-line port)))
      (if (eof-object? line)
          (sort! (reverse! words) string-ci<?)
          (lp (cons line words) (read-line port))))))

(define (uniq l)
  (let lp ((last-word "") (in l) (out '()))
    (cond ((null? in) (reverse! out))
          ((string-ci=? last-word (car in)) (lp last-word (cdr in) out))
          (else (lp (car in) (cdr in) (cons (car in) out))))))

(define trim-char-set (char-set-complement char-set:letter))
(define (get-sxw-words)
  ((ssax:make-parser
    NEW-LEVEL-SEED 
    (lambda (elem-gi attributes namespaces
                     expected-content seed)
      seed)
    
    FINISH-ELEMENT
    (lambda (elem-gi attributes namespaces parent-seed seed)
      seed)

    CHAR-DATA-HANDLER
    (lambda (string1 string2 seed)
      (let* ((strs (map
                    (lambda (x) (string-trim-both x trim-char-set))
                    (remove!
                     string-null? 
                     (append-map
                      (lambda (x) (string-split x #\space))
                      (string-split string1 #\newline)))))
             (seed (append! strs seed)))
        (if (string-null? string2) seed
            (cons string2 seed)))))
   (cdr (run-with-pipe ; "r" for read-only
         "r" "unzip" "-p" sxw-file "content.xml"))
   '()))

(let lp ((words (uniq (sort! (get-sxw-words) string-ci<?)))
         (dict-words (get-dict-words))
         (out '()))
  (cond
   ((null? words)
    (for-each (lambda (x) (display x) (newline)) (reverse! out)))
   ((string-ci=? (car words) (car dict-words))
    (lp (cdr words) (cdr dict-words) out))
   ((string-ci>? (car words) (car dict-words))
    (lp words (cdr dict-words) out))
   (else
    (lp (cdr words) dict-words (cons (car words) out)))))

;;; arch-tag: 6c2617d3-32a4-4a4d-8914-48c7ee1b5ad8

[-- Attachment #3: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: (ice-9 syncase)
  2004-10-05 19:30 ` Andy Wingo
@ 2004-10-18 12:39   ` Marius Vollmer
  0 siblings, 0 replies; 3+ messages in thread
From: Marius Vollmer @ 2004-10-18 12:39 UTC (permalink / raw)
  Cc: Guile Users

Andy Wingo <wingo@pobox.com> writes:

> So that users won't have to. I'm not happy, but it's better now.

Yeah, I'm sorry that you have so much trouble with (ice-9 syncase).
There is something deeply wrong about how we do syntax-case macros,
and I can't offer no fix right now.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-18 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-04 20:18 (ice-9 syncase) Andy Wingo
2004-10-05 19:30 ` Andy Wingo
2004-10-18 12:39   ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).