Emacs: reloading `require` lines
fosskers opened this issue · 9 comments
I'm getting more used to fennel-mode
and enjoying myself, so thank you.
I've noticed that executing C-c C-e
(lisp-eval-defun) on a require
line only "works" the first time. That is, if the underlying library changes and I reeval the require
line, autocomplete doesn't show new functions, nor are they usable when I attempt to use them within the file. Here is a quick example:
(local t (require :transducers))
(fn sum-1 [tensor]
"Sum the elements of a Rank-1 tensor."
(t.transduce t.pass t.add tensor))
(sum-1 [1 2 3])
I had added add
on-the-fly when I noticed +
isn't a function in Fennel, but upon reevaluating the entire buffer, I found that it was claiming that add
didn't exist. Indeed it was being passed to t.transduce
as nil
, in the Lua way.
Any thoughts about what might be happening here? Cheers!
P.S. I would have opened this issue within the fennel-mode
repo, but couldn't figure out how. 🙏
Try M-x fennel-reload
or C-c C-k
.
I had tried that, but it doesn't seem to work either. In executing sum-1
manually in the REPL or via C-c C-e
directly in the buffer (which I'm more oft to do), it is convinced that t.add
doesn't exist.
Did you reload the module that you added the function to, or the module that's calling the one that changed?
If it's the first one, it could be a bug. Can you provide a repro case? Also try reloading with ,reload transducers
in the repl; it should be the same thing as M-x fennel-reload
.
I think that the library with the function added was never actually loaded into the REPL - I guess it had only been done so transitively via the require
call to it. Let me reproduce this and get back to you.
I think that the library with the function added was never actually loaded into the REPL - I guess it had only been done so transitively via the require call to it.
There's no difference between these two situations; if a module is loaded transitively or directly it behaves the same either way.
Okay, there seem to be multiple things happening here.
Setup
- Have a symlink to https://github.com/fosskers/transducers.fnl/blob/master/transducers.fnl in the local testing directory.
- Add the following to a testing file:
(local t (require :transducers))
(fn sum-1 [tensor]
"Sum the elements of a Rank-1 tensor."
(t.transduce t.pass t.add tensor))
(sum-1 [1 2 3])
{:sum-1 sum-1}
- Comment out the
add
export within the transducers file.
This is the starting setup for both scenarios below. I completely restart Emacs between each scenario to ensure a clean slate.
Scenario 1: The REPL
- Open testing file.
- C-c C-k
- Completion does not work for
t
symbol. - Bind this module to a local in the REPL.
- Call sum-1 in REPL; fails, since t.add doesn't exist yet.
- Open transducers buffer and export
add
. - C-c C-k once again in testing file.
- Can call sum-1 in REPL without needing to rebind the local (convenient!)
- But, error in REPL implying t.add is nil.
Scenario 2: The Buffer
This is more often how I work with Lisps; local one-liners that I execute for testing without typing things in the REPL manually.
- Open testing file.
- Attempt C-c C-e on local one-liner for testing.
- It fails: sum-1 is not loaded.
- C-c C-e on sum-1: it fails, transducers hasn't been loaded.
- C-c C-e on
require
line, then sum-1 again. - C-c C-e on the one-liner: fails,
add
isn't exported yet. - Open transducers buffer and export
add
. - C-c C-e on the
require
doesn't overwrite what the Lisp process already holds;add
continues not to exist.
Lines of Inquiry
- Could the symlink have anything to do with it?
- How come the REPL (the Lisp process?) seems to get in different states between
C-c C-k
and individualC-c C-e
calls? (re: completions)
Also try reloading with
,reload transducers
in the repl;
This works, by the way (for Scenario 2).
In scenario 1, you said you're only reloading the testing file. You need to reload the file that changed in order to have the changes reflected in the repl.
In scenario 2 it sounds like you're trying to run code that refers to things that haven't been loaded yet. Re-running require
has no effect; you have to reload in order to get the new changes in a module to show.
Thanks. After playing around more last night, I think the proper mental model (and the one you're hinting at) is to use a single REPL session across multiple Fennel projects (if they're interdependent), and make sure everything is C-c C-k
'd properly.
I'll close this for now, cheers.