[plt-scheme] Enhancement: function that returns the name of the current file

From: Eric Hanchrow (offby1 at blarg.net)
Date: Wed Jul 20 13:48:52 EDT 2005

Before I describe my suggestion, let me explain why I want it.

I've got an mzscheme script whose sole purpose in life is to edit a
particular file.  However, the script can't be sure of the name of
that file; instead it has to guess a few names, and try each, editing
the first file that it finds with the given name.  That's because I
want to have this script on lots of different machines, and the target
file can be in different places on different machines.

So my script tries, as one of its guesses, a directory that is a
parent of the directory in which the script itself lives.  The code
looks like this:

        (let ((this-modules-path (???)))
          (find file-exists?
                (map (lambda (dir) (build-path dir "bookmarks.html"))
                     (list
                      (find-system-path 'home-dir)
                      (simplify-path (build-path this-modules-path 'up 'up 'up))))))

The question, then, is what should I substitute for ???.

I couldn't figure it out myself.  But Anton van Straaten suggested
that I use

        (syntax-source (syntax it-doesnt-make-the-slightest-difference-what-you-put-here-as-far-as-I-can-tell))

That, in fact, works perfectly. 

So now here's my request: either add some documentation that mentions
this technique, or, even better, make a little function named
something like this-modules-path, which does the above, and document
_it_.

I assume that syntax-source and syntax are already documented, but
that doesn't help, because I would never have thought to look at that
documentation; it never occurred to me that my problem had anything to
do with syntax.

For what it's worth, Perl has this sort of function in a module called
FindBin (see http://search.cpan.org/~nwclark/perl-5.8.7/lib/FindBin.pm
for an overview; the variable $FindBin::Bin is relevant).

-- 
I shrivel inside each time [Star Wars] is mentioned.
        -- Sir Alec Guinness



Posted on the users mailing list.