[plt-scheme] foreign.ss dll path

From: Daniel Pinto de Mello e Silva (daniel.silva at gmail.com)
Date: Tue Oct 18 05:14:53 EDT 2005

On 10/16/05, Yoav Goldberg <yoav.goldberg at gmail.com> wrote:
> And now for a somewhat unrelated question: (how) can I define
> top-level (actually module level) bindings from within a lambda
> expression?

There are ways (see namespace-variable-value and friends), but could
you provide an example of what you're trying to do?  Skipping the
parse-time bound variable checks can be fun but will probably cause
more headaches (bugs) in the long run.

Daniel


> Yoav
>
> [*] checked on win2000.
>
>
> On 10/15/05, Daniel Pinto de Mello e Silva <daniel.silva at gmail.com> wrote:
> > I think the Scheme current-directory parameter only changes the
> > interpreter's view of what the current working directory is.  To
> > change the working directory of the process and the libraries it
> > loads, try the chdir function from the C runtime.  For Windows, look
> > at
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__chdir.2c_._wchdir.asp
> >
> > For UNIX (POSIX), look at
> >
> > http://www.umbi.umd.edu/cgi-bin/man-cgi?chdir+2
> >
> > You'll also want to import the getcwd function.  For Linux, you don't
> > need to preallocate a buffer, but you do need to specify a maximum
> > path length:
> >
> > http://linux.wku.edu/cgi-bin/man2html?getcwd+3
> >
> > Here's an example:
> >
> > > (require (lib "foreign.ss"))
> > > (unsafe!)
> > > (define rt (ffi-lib #f))
> > > (define chdir (get-ffi-obj "chdir" rt (_fun _string -> _int)))
> > > (define getcwd (get-ffi-obj "getcwd" rt (_fun (_pointer = #f) (_int = 1024) -> _string)))
> > > (getcwd)
> > "/home/dsilva"
> > > (chdir "/tmp")
> > 0
> > > (getcwd)
> > "/tmp"
> > > (current-directory)
> > #<path:/home/dsilva>
> > > (define (with-c-dir path thunk)
> >    (define cwd (getcwd))
> >    (dynamic-wind (lambda () (chdir path))
> >                  thunk
> >                  (lambda () (chdir cwd))))
> > > (with-c-dir "/usr"
> >     (lambda () (printf "Do some work in ~a~n" (getcwd))))
> > Do some work in /usr
> > > (getcwd)
> > "/tmp"
> >
> > Daniel
>


Posted on the users mailing list.