Thank you. Although I was curious in general, at the moment the need is nothing fancier than printing the version in a banner, and not wanting to duplicate the version string. Sounds like I'll go with:
(require "../info.rkt") (displayln (#%info-lookup 'version)) On Thu, Jun 6, 2013 at 7:43 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: > At Mon, 3 Jun 2013 13:57:53 -0400, Greg Hendershott wrote: >> Let's say I have a command-line utility distributed as a package. >> >> package/ >> info.rkt >> collection/ >> main.rkt >> >> package/info.rkt is e.g. >> >> #lang setup/infotab >> (define version "1.1") >> >> In main.rkt, I want to display the version to the user. >> >> From cheating and looking at the expansion of info.rkt, this works: >> >> (require "../info.rkt") >> (displayln (#%info-lookup 'version)) >> >> But that seems too raw. From searching the docs, eventually I found >> `get-info/full`, which I guess would work like this: >> >> (require setup/getinfo racket/runtime-path) >> (define-runtime-path up "..") >> (define lookup (get-info/full up)) >> (and lookup (lookup 'version (const "unknown"))) >> >> Is that the best way? > > A problem with `(define-runtime-path up "..")' is that you'd end up > with a copy of the package directory if you make a executable that > uses the "main.rkt" module. > > Your initial approach, > > (require "../info.rkt") > (displayln (#%info-lookup 'version)) > > seems better to me. I think `setup/infotab' should document that it > makes the module export a `#%info-lookup' function, and then you'd be > on firmer ground to use it directly. > > Using a relative path "../info.rkt" that steps outside a collection > feels wrong, but I don't have a concrete reason or better idea. > > > One more possibility is to get the version of a collection's package, > like this: > > #lang racket/base > (require pkg/lib > setup/getinfo) > > (define (version-of-package-of-collection coll) > (define pkg (path->pkg (collection-path coll))) > (and pkg > (let ([i (get-info/full (pkg-directory pkg))]) > (and i > (i 'version (lambda () #f)))))) > > but I think that's more dynamic and global than you want. > ____________________ Racket Users list: http://lists.racket-lang.org/users