Closed KPCCoiL closed 4 months ago
Yes, you can see here where the repl locals-saving code specifically skips anything which came from a gensym: https://git.sr.ht/~technomancy/fennel/tree/main/item/src/fennel/repl.fnl#L41
The vast majority of locals that come from gensym should not be saved by the repl. I agree it's annoying that this causes the problem you've described, but I don't know how to distinguish between gensyms like this vs the ones which are noise from macroexpansion, destructuring, etc. Turning on locals-saving for all gensyms is probably not the right solution.
My initial inclination is just to advise against using gensyms in a case where you want this, but I don't have enough context to know the whole story.
Thanks for your response. It's okay if it is intentional, and I'm closing this.
I was just playing around with fennel macros and trying to make something like
(module) ; => (local _1_ {})
(local foo 10)
(export foo) ; => (tset _1_ "foo" foo)
(exports) ; => _1_
Actually, I realized similar functionality can be achieved without this sort of gensym
s:
(module
(export foo)
(local foo 10))
; => (do (local foo 10) {:foo foo})
I doubt if this is advised in the spirit of fennel though.
I see what you mean. Yes, you could build that out, and it would work fine right until you try to do it from the repl. But it's better to use the Lua module system since it's much more transparent. There's only so much we can do to work around Lua's limitations with scope and chunks.
Suppose I have
foo.fnl
:and
bar.fnl
:fennel bar.fnl
printsas expected.
However, when I try it in the REPL, calling
initialize
sets_1_
tonil
, not 10. Weirdly, if Iinitialize
twice, it becomes 10.The issue does not arise if you replace
(gensym)
infoo.fnl
by(sym :test)
(hence the title).