From: Julian Graham <joolean@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: bug-guile <bug-guile@gnu.org>
Subject: Re: find-versioned-module bugs
Date: Thu, 17 Jun 2010 08:58:16 -0400 [thread overview]
Message-ID: <AANLkTincWHb4B_SJzTOu8Jt4Q3bSnPjNlrzoBqEkKLzc@mail.gmail.com> (raw)
In-Reply-To: <m3631kkav0.fsf@pobox.com>
[-- Attachment #1: Type: text/plain, Size: 481 bytes --]
Hey Andy,
> I don't know, all that code is tricky. How about having
> find-versioned-module return a tail instead of a full path, then pass
> that tail to primitive-load-path? It will cause some slight duplication
> of effort but it will find the .go correctly.
Sure! Find attached an implementation of `find-versioned-module' that
does precisely that -- although it looks like we've gone in a slightly
different direction since this email was written... ;-)
Regards,
Julian
[-- Attachment #2: find-versioned-module.scm --]
[-- Type: text/x-scheme, Size: 3586 bytes --]
(define (find-versioned-module dir-hint name version-ref roots)
(define (subdir-pair-less pair1 pair2)
(define (numlist-less lst1 lst2)
(or (null? lst2)
(and (not (null? lst1))
(cond ((> (car lst1) (car lst2)) #t)
((< (car lst1) (car lst2)) #f)
(else (numlist-less (cdr lst1) (cdr lst2)))))))
(not (numlist-less (car pair2) (car pair1))))
(define (match-version-and-file pair)
(and (version-matches? version-ref (car pair))
(let ((filenames
(filter (lambda (file-pair)
(let* ((file (in-vicinity (car file-pair)
(cdr file-pair)))
(s (false-if-exception (stat file))))
(and s (eq? (stat:type s) 'regular))))
(map (lambda (ext)
(cons (cadr pair)
(in-vicinity (cddr pair)
(string-append name ext))))
%load-extensions))))
(and (not (null? filenames))
(cons (car pair) (car filenames))))))
(define (match-version-recursive root-pairs leaf-pairs)
(define (filter-subdirs root-pairs ret)
(define (filter-subdir root-pair dstrm subdir-pairs)
(let ((entry (readdir dstrm)))
(if (eof-object? entry)
subdir-pairs
(let* ((subdir (in-vicinity (cddr root-pair) entry))
(dir (in-vicinity (cadr root-pair) subdir))
(num (string->number entry))
(num (and num (exact? num)
(append (car root-pair) (list num)))))
(if (and num (eq? (stat:type (stat dir)) 'directory))
(filter-subdir root-pair dstrm
(cons (cons num (cons (cadr root-pair)
subdir))
subdir-pairs))
(filter-subdir root-pair dstrm subdir-pairs))))))
(or (and (null? root-pairs) ret)
(let* ((rp (car root-pairs))
(dir (in-vicinity (cadr rp) (cddr rp)))
(dstrm (false-if-exception (opendir dir))))
(if dstrm
(let ((subdir-pairs (filter-subdir rp dstrm '())))
(closedir dstrm)
(filter-subdirs (cdr root-pairs)
(or (and (null? subdir-pairs) ret)
(append ret subdir-pairs))))
(filter-subdirs (cdr root-pairs) ret)))))
(or (and (null? root-pairs) leaf-pairs)
(let ((matching-subdir-pairs (filter-subdirs root-pairs '())))
(match-version-recursive
matching-subdir-pairs
(append leaf-pairs (filter pair? (map match-version-and-file
matching-subdir-pairs)))))))
(define (make-root-pair root) (cons '() (cons root dir-hint)))
(let* ((root-pairs (map make-root-pair roots))
(matches (if (null? version-ref)
(filter pair? (map match-version-and-file root-pairs))
'()))
(matches (append matches (match-version-recursive root-pairs '()))))
(and (null? matches) (error "No matching modules found."))
(cddar (sort matches subdir-pair-less))))
next prev parent reply other threads:[~2010-06-17 12:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 7:11 find-versioned-module bugs Andy Wingo
2010-06-09 12:40 ` Julian Graham
2010-06-10 4:25 ` Julian Graham
2010-06-10 12:23 ` Andy Wingo
2010-06-10 14:02 ` Julian Graham
2010-06-10 14:49 ` Andy Wingo
2010-06-14 22:53 ` Andy Wingo
2010-06-15 5:02 ` Julian Graham
2010-06-15 7:34 ` Andy Wingo
2010-06-17 12:58 ` Julian Graham [this message]
2010-06-18 8:28 ` Andy Wingo
2010-06-15 23:12 ` Ludovic Courtès
2010-06-16 7:23 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTincWHb4B_SJzTOu8Jt4Q3bSnPjNlrzoBqEkKLzc@mail.gmail.com \
--to=joolean@gmail.com \
--cc=bug-guile@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).