Earlier quoted context omitted.
It uses lexical scoping, so it probably would mess up traces.
Late reply, but so does setfenv: > function foo()return function()return a end end > =foo()() nil > a=5 > =foo()() 5 > setfenv(foo,{a=6}) > =foo()() 6
MoonScript, a programmer friendly language that compiles to Lua
161–170 of 171 posts
Re: MoonScript, a programmer friendly language that compiles to Lua
#162Earlier quoted context omitted.
I'd make try/catch an expression, not a statement, like in Lisp -- it'd still be "let x = try {...}...". I agree that 'var' for mutable bindings is a reasonable design. In E it's 'def' for immutable and 'var' for mutable, for instance; and you can also write just 'def x' and then 'bind x := 42' further down (with single-assignment semantics). But though that's nice to have, you can do all right without it; if there w…
I'd use "set" instead of "bind" and be consistent that assignment leverages the vanilla equality operator (since we're already talking about that for "let") but yeah, it sounds like you've been thinking about the same stuff I have. It sounds like you've been pondering the same problems I have. In my case it's because I've been working on a rules-engine for scientists and currently we're using SQL for the rule languag…
Maybe Datalog could make a cleaner base for your project? Just a random thought; bound to be lots more considerations.
Yeah, I have a project right now too where these questions come up -- https://github.com/darius/squeam -- though it's not really ready for anyone.
Re: MoonScript, a programmer friendly language that compiles to Lua
#163Earlier quoted context omitted.
Late reply, but so does setfenv: > function foo()return function()return a end end > =foo()() nil > a=5 > =foo()() 5 > setfenv(foo,{a=6}) > =foo()() 6
Nah I'm talking about the _ENV variable itself being in lexical scope.
Re: MoonScript, a programmer friendly language that compiles to Lua
#164Earlier quoted context omitted.
You have any references to these arguments between the two gods?
Totally not a concrete link, sorry, but - in a video from one of Lua conferences, I've seen Roberto mention in some polite yet clear way that talks with Mike which they had had always come to a standstill on something - at least that's how I recall it. On the other hand, since 2015, Mike was looking to pass luajit development on to someone else - so with this, situation could possibly change in the end. But I'm not s…
Re: MoonScript, a programmer friendly language that compiles to Lua
#165Earlier quoted context omitted.
I forgot to emphasize that I'm particular about syntax. I amended my comment accordingly. I also don't like the global-by-default bit, but maybe my ideal language could be a syntax layer atop Lua?
Metatables are your friend. -- LuaJIT local oldG = _G local newG = setmetatable({}, { __index = oldG, }) setmetatable(oldG, { __index = function(t, k) return rawget(newG, k) end, __newindex = function() error('attempt to assign global variable') end, }) _G = newG If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.
Re: MoonScript, a programmer friendly language that compiles to Lua
#166Earlier quoted context omitted.
Metatables are your friend. -- LuaJIT local oldG = _G local newG = setmetatable({}, { __index = oldG, }) setmetatable(oldG, { __index = function(t, k) return rawget(newG, k) end, __newindex = function() error('attempt to assign global variable') end, }) _G = newG If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.
dfsjifdadisjodjafiosjdafs009dfsja9sdjf09fdas09sdf09j90
Re: MoonScript, a programmer friendly language that compiles to Lua
#167Earlier quoted context omitted.
Metatables are your friend. -- LuaJIT local oldG = _G local newG = setmetatable({}, { __index = oldG, }) setmetatable(oldG, { __index = function(t, k) return rawget(newG, k) end, __newindex = function() error('attempt to assign global variable') end, }) _G = newG If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.
dfsjifdadisjodjafiosjdafs009dfsja9sdjf09fdas09sdf09j90
Re: MoonScript, a programmer friendly language that compiles to Lua
#168Earlier quoted context omitted.
Nah I'm talking about the _ENV variable itself being in lexical scope.
i have no idea what im talking about tho.
> function foo()
>> local a = _ENV
>> local _ENV = a
>> return {a=function() _ENV = {r=6} end, b = function() return r end}
>> end
> r = 5
> x = foo()
> x.b()
> =x.b()
5
> return x.a()
> return x.b()
6
>
vs > function foo()
return {
a = function() return setfenv(2, {r = 6}) end,
b = function() return r end
}
end
> x = foo()
> = x.a()
bad argument #1 to '?' (invalid level)
stack traceback:
[builtin#11]: at 0x0101faf2a0
[C]: at 0x0101f4ea60
> function foo()
function bar()
setfenv(2, {x=6})
end
bar()
return function() return x end
end
> e = foo()
> =e()
6
I hadn't thought of that...Re: MoonScript, a programmer friendly language that compiles to Lua
#169Earlier quoted context omitted.
i have no idea what im talking about tho.
Ooooh, maybe this is relevant: > function foo() >> local a = _ENV >> local _ENV = a >> return {a=function() _ENV = {r=6} end, b = function() return r end} >> end > r = 5 > x = foo() > x.b() > =x.b() 5 > return x.a() > return x.b() 6 > vs > function foo() return { a = function() return setfenv(2, {r = 6}) end, b = function() return r end } end > x = foo() > = x.a() bad argument #1 to '?' (invalid level) stack tracebac…
Re: MoonScript, a programmer friendly language that compiles to Lua
#170Earlier quoted context omitted.
Ooooh, maybe this is relevant: > function foo() >> local a = _ENV >> local _ENV = a >> return {a=function() _ENV = {r=6} end, b = function() return r end} >> end > r = 5 > x = foo() > x.b() > =x.b() 5 > return x.a() > return x.b() 6 > vs > function foo() return { a = function() return setfenv(2, {r = 6}) end, b = function() return r end } end > x = foo() > = x.a() bad argument #1 to '?' (invalid level) stack tracebac…
wat?
With _ENV, it is fully dynamic, and can be changed "at a distance".
Also:
> function foo()
>> local function bar() return a end
>> setfenv(1,{a=4})
>> return bar
>> end
> a = 9
> =foo()()
9