GithubHelp home page GithubHelp logo

Comments (4)

greghendershott avatar greghendershott commented on June 12, 2024

racket-mode does automatically set current-load-relative-directory to match the source file, to ensure relative requires work. But I'm not sure it ought to automatically set current-directory, as well. Do you think it should? Am I being dense wondering if doing that would cause problems in other cases? e.g. What if you're testing a utility, that works on data in another dir?


BTW, also it depends where your program is intended to find "foo.rkt":

  1. Whatever the current directory happens to be?

    In that case you may need to change the current working directory. In the racket-mode REPL you can use ,pwd to see what it is, and ,cd to change it.

  2. The same directory as the source file?

    In that case the program really ought to be the following, which will work regardless of the current directory.

    #lang racket
    (require racket/runtime-path)
    (define-runtime-path foo.rkt "foo.rkt")
    (file->string foo.rkt)

from racket-mode.

greghendershott avatar greghendershott commented on June 12, 2024

On IRC zenspider reported the curdir is reset after each run. Maybe this is the same issue.

I think this is because current-directory is a Racket parameter, and parameters are per-thread.

So this program:

(current-directory (find-system-path 'temp-dir))
(printf "Main thread c-d: ~a\n" (current-directory))
(define thd
  (thread 
   (lambda ()
     (current-directory (find-system-path 'home-dir))
     (printf "Other thread c-d: ~a\n" (current-directory)))))
(sync thd)
(printf "Main thread c-d: ~a\n" (current-directory))

prints:

Main thread c-d: /tmp
Other thread c-d: /Users/greg/
#<thread:/tmp/foo.rkt:7:3>
Main thread c-d: /tmp

The thing is, the REPL runs your program on its own thread (and custodian). Therefore when that thread changes current-directory, the value isn't retained, just like in the example above.

I need to think about the best way to handle this.

from racket-mode.

zenspider avatar zenspider commented on June 12, 2024

I suspect this is related. I would expect that the pwd be the same as whatever buffer spawned the process. This would match emacs' other inferior modes.

from racket-mode.

greghendershott avatar greghendershott commented on June 12, 2024

So after mulling this over, and also looking at how DrRacket behaves in this regard, I think the best thing to do is set current-directory (and current-directory-for-user and current-load-relative-directory) to the source file's directory on each Run.

[Note that this doesn't try to do anything about preserving (current-directory) as it may have been typed in the REPL. On the contrary, on the next Run, the directory will be reset back to that for the source file.]

I'll push a commit with that, to close this issue. However if with that change it's still not behaving as you want, please let me know.

from racket-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.