[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Embedding Guile and regexp problems
From: |
Alex Shinn |
Subject: |
Re: Embedding Guile and regexp problems |
Date: |
28 Dec 2001 11:06:26 +0900 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 |
>>>>> "Anthony" == Anthony W Juckel <address@hidden> writes:
Anthony> I've recently begun work on a GNUstep application for which
Anthony> I would like to use guile as an extension/calculation
Anthony> language. Now, I've recently run into a roadblock. I have
Anthony> some scheme code which makes use of regular expressions,
Anthony> and upon running that code, I get an exception, because
Anthony> match:substring and string-match are unbound within my
Anthony> embedded guile environment. Now, I've checked the value of
Anthony> *features* from within this embedded guile, and regex is
Anthony> indeed included, and as this is the only step the
Anthony> documentation cites to using regexp within guile I'm not
Anthony> sure where to proceed from here. Do I need to insert a
Anthony> particular module, or perhaps link my application against a
Anthony> particular library?
(use-modules (ice-9 regex)) ;; catch-22 in this case
;; should probably actually load the module or look at exports instead
;; of defines. can hit dirs multiple times, really should have used ftw
(define find-procedure
(let ((file-rx (make-regexp "\\.scm$"))
(def-rx (make-regexp "^define")))
(lambda (proc)
(letrec ((matches '())
(match-sym (if (symbol? proc) proc (string->symbol proc)))
(find-in-file
(lambda (f)
(let ((p (open-input-file f)))
(let loop ((x (read p)))
(cond ((eof-object? x)
(close p))
(else
(if (pair? x)
(let ((a (car x)) (b (cdr x)))
(if (and (symbol? a)
(regexp-exec
def-rx
(symbol->string a))
(pair? b))
(let ((var (car b)))
(if (pair? var) (set! var (car var)))
(if (eq? match-sym var)
(set! matches (cons (cons var f)
matches)))))))
(loop (read p))))))))
(find-in-dir
(lambda (d)
(let ((p (opendir d)))
(readdir p) ;; .
(readdir p) ;; ..
(let loop ((f (readdir p)))
(cond ((eof-object? f)
(closedir p))
(else
(if (regexp-exec file-rx f)
;; looks like scheme
(catch #t
(lambda () (find-in-file (string-append d "/"
f)))
(lambda args (warn (string-append
"error reading from " f))))
;; recurse dirs
(let ((file (string-append d "/" f)))
(and (access? file R_OK)
(eq? 'directory (stat:type (lstat file)))
(find-in-dir file))))
(loop (readdir p)))))))))
(for-each find-in-dir %load-path)
(reverse matches)))))
;; print the output
(for-each
(lambda (x) (format #t "~A: ~A\n" (car x) (cdr x)))
(find-procedure 'string-match))