~technomancy/fennel#85: 
locals are lost in the repl after 2b4b31c6

Commit 2b4b31c6 changed something in the internals, and now locals are not created in the repl properly:

Welcome to Fennel 0.10.1-dev on Lua 5.4!
Use ,help to see available commands.
Try installing readline via luarocks for a better repl experience.
>> (local {: map} (require :lazy-seq))
nil
>> map
nil
>> _ENV
@1{:_ @1{...}
   :__ [@1{...}]
   :___replLocals___ {:_local_1_ {:concat #<function: 0x5588a03bad80>
                                  :cons #<function: 0x5588a036f1c0>
                                  :cycle #<function: 0x5588a056df80>
                                  :doall #<function: 0x5588a0432690>
                                  :dorun #<function: 0x5588a0453030>
                                  :drop #<function: 0x5588a050c1d0>
                                  :every? #<function: 0x5588a04521e0>
                                  :filter #<function: 0x5588a05111d0>
                                  :first #<function: 0x5588a0410f70>
                                  :keep #<function: 0x5588a0481de0>
                                  :lazy-seq* #<function: 0x5588a04c9d70>
                                  :line-seq #<function: 0x5588a054a2f0>
                                  :map #<function: 0x5588a0372280>
                                  :next* #<function: 0x5588a03f1bb0>
                                  :range #<function: 0x5588a049f620>
                                  :realized? #<function: 0x5588a03d23b0>
                                  :repeatedly #<function: 0x5588a0437e40>
                                  :rest #<function: 0x5588a0441d80>
                                  :seq #<function: 0x5588a04147c0>
                                  :seq-pack #<function: 0x5588a03d6810>
                                  :seq-unpack #<function: 0x5588a03d4f30>
                                  :some? #<function: 0x5588a04a2950>
                                  :take #<function: 0x5588a0364090>}
                      :map #<function: 0x5588a0372280>}}

Weirdly enough this happens only for some cases. For example it doesn't happen with literal tables, or some other libraries.

Status
RESOLVED FIXED
Submitter
~andreyorst
Assigned to
No-one
Submitted
a month ago
Updated
27 days ago
Labels
1.0 bug

~andreyorst a month ago

~technomancy, what do we need to fix this?

~technomancy a month ago

First step is to isolate a minimal reproduction, I guess. Need to see why it happens with some tables and not others.

~andreyorst a month ago

For me the minimal repro was to require a file with the following contents:

(fn foo [] :foo)

{: foo}

As per:

Welcome to Fennel 0.10.1-dev on Lua 5.4!
Use ,help to see available commands.
Try installing readline via luarocks for a better repl experience.
>> (local {: foo} (require :bug))
nil
>> foo
nil

I believe that's as minimal as it can get.

Interestingly enough, this doesn't happen if I put {:foo (fn [] :foo)} into that file instead, or if I put (local ns {}) (fn ns.foo [] :foo) ns into that file.

~technomancy a month ago

It looks like the problem is that because we are now preserving the scope table, the first foo and the second foo are distinct from each other, so the second one is compiled to foo0 instead.

I think I have an idea for a fix.

~technomancy a month ago

I ended up rewriting the whole locals-saving implementation to use proper Fennel lists instead of splicing together strings of Lua code: https://git.sr.ht/~technomancy/fennel/commit/bc1e977fd21ad0dcacf93d2f7cd8383553dce31b

There's still one test failure, but it has also gotten rid of the limitation of not being able to activate when there's only one line of Lua output.

Let me know what you think.

~andreyorst a month ago

this branch seems working fine!

~technomancy referenced this from #91 a month ago

~andreyorst referenced this from #91 a month ago

~technomancy 28 days ago

Ahhhh this approach cannot work because it wraps the input code in a let. We can work around this for locals by using debug.getlocal to splice things back into the top level env but when there's an inline macro defined there it won't work at all; the macro is defined in the let scope and there's no way to splice it back into the top-level scope.

~technomancy REPORTED FIXED 27 days ago

I think 20e6b50 fixes this.

Register here or Log in to comment, or comment via email.