[local] <namelist> = do <block> =<explist> end

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[local] <namelist> = do <block> =<explist> end

Soni "They/Them" L.
Hello!

I'd like a way to do

local v
do v = 3 end

without assigning nil to v.

Can we get expressionblocks?

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Javier Guerra Giraldez
On Tue, Aug 18, 2015 at 12:14 PM, Soni L. <[hidden email]> wrote:
> Can we get expressionblocks?

AKA functions:

local v = (local function() return 3 end)()



--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Dirk Laurie-2
In reply to this post by Soni "They/Them" L.
2015-08-18 19:14 GMT+02:00 Soni L. <[hidden email]>:

> I'd like a way to do
>
> local v
> do v = 3 end
>
> without assigning nil to v.

You can't have that in principle. No name can ever not be
associated to a value. If you don't do

local v=3

(why on earth don't you?) then Lua explicitly supplies the nil.
Otherwise that slot would contain whatever was in it before
(which may be a user's unencrypted password) and all sorts
of security holes open up.

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Soni "They/Them" L.
In reply to this post by Javier Guerra Giraldez


On 18/08/15 02:18 PM, Javier Guerra Giraldez wrote:
> On Tue, Aug 18, 2015 at 12:14 PM, Soni L. <[hidden email]> wrote:
>> Can we get expressionblocks?
> AKA functions:
>
> local v = (local function() return 3 end)()
>
>
>
Basically, but without the GC overhead of creating closures, or the VM
overhead of calling functions.

Alternatively:

do
<block>
export local <namelist> = <explist>
end

Where `export` would create the locals on the outer scope. This is
useful when creating closures without polluting the environment.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Soni "They/Them" L.
In reply to this post by Dirk Laurie-2


On 18/08/15 03:11 PM, Dirk Laurie wrote:

> 2015-08-18 19:14 GMT+02:00 Soni L. <[hidden email]>:
>
>> I'd like a way to do
>>
>> local v
>> do v = 3 end
>>
>> without assigning nil to v.
> You can't have that in principle. No name can ever not be
> associated to a value. If you don't do
>
> local v=3
>
> (why on earth don't you?) then Lua explicitly supplies the nil.
> Otherwise that slot would contain whatever was in it before
> (which may be a user's unencrypted password) and all sorts
> of security holes open up.
>
The basic idea /is/ to do local v=3, but also run some code inbetween.

local v = (function() return 3 end)() lets you run code inbetween, but
"v" doesn't get assigned nil: it gets assigned whatever the function
returns.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Sean Conner
In reply to this post by Soni "They/Them" L.
It was thus said that the Great Soni L. once stated:

> Hello!
>
> I'd like a way to do
>
> local v
> do v = 3 end
>
> without assigning nil to v.
>
> Can we get expressionblocks?

  What, exactly, is wrong with

        local v
        do
          v = 3
        end -- ?

  It works, even with additional local variables:

        local a,b,c
        do
          a = 1
          b = 2
          c = a * somefunc(b) + someotherthing()
        end

  I use this pattern quite often in Lua.

  -spc (What, exactly, are you doing that require all these proposals you
        make?)

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Soni "They/Them" L.


On 18/08/15 04:54 PM, Sean Conner wrote:

> It was thus said that the Great Soni L. once stated:
>> Hello!
>>
>> I'd like a way to do
>>
>> local v
>> do v = 3 end
>>
>> without assigning nil to v.
>>
>> Can we get expressionblocks?
>    What, exactly, is wrong with
>
> local v
> do
>  v = 3
> end -- ?
>
>    It works, even with additional local variables:
>
> local a,b,c
> do
>  a = 1
>  b = 2
>  c = a * somefunc(b) + someotherthing()
> end
>
>    I use this pattern quite often in Lua.
>
>    -spc (What, exactly, are you doing that require all these proposals you
> make?)
>
Time-sensitive stuff.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Dirk Laurie-2
2015-08-18 21:56 GMT+02:00 Soni L. <[hidden email]>:
> On 18/08/15 04:54 PM, Sean Conner wrote:
>>    -spc (What, exactly, are you doing that require all these proposals you
>>         make?)
>>
> Time-sensitive stuff.

You will be saving one VM instruction, i.e. LOADNIL. That is hardly
time-consuming: only the type field of the value in the register is changed.

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Duncan Cross
In reply to this post by Soni "They/Them" L.
On Tue, Aug 18, 2015 at 8:56 PM, Soni L. <[hidden email]> wrote:
>>    -spc (What, exactly, are you doing that require all these proposals you
>>         make?)
> Time-sensitive stuff.

So you intend to significantly speed up the execution of your Lua code
through a prolific campaign of new syntax proposals? It's not a great
strategy to be honest, for various reasons, but for one thing:
everything is a tradeoff and the things that genuinely cause your code
to run faster, when properly benchmarked, are often surprising and
counterintuitive. Carefully investigating the bottlenecks in the
specific places that your code in particular spends most of its time
in might be a more productive way to get what you want.

-Duncan

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Sean Conner
In reply to this post by Soni "They/Them" L.
It was thus said that the Great Soni L. once stated:
>
> >   -spc (What, exactly, are you doing that require all these proposals you
> > make?)
> >
> Time-sensitive stuff.

  Date parsing?  Micro-optimizations?  "Time-sensitive stuff" is pretty
vague (and have you even bothered with profiling?) [1]

  -spc (Never mind that I'm using Lua in a syslog daemon, and at work with
        parsing SIP messages)

[1] Like here: [2]

        http://lua-users.org/lists/lua-l/2014-08/msg00819.html

[2] Whatever happended to Coroutines?  He never did get back to me about
        the network buffer issue.

Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Rodrigo Azevedo
In reply to this post by Soni "They/Them" L.

+1

How to define the "outer scope" ? (-1)

Em 18/08/2015 16:43, "Soni L." <[hidden email]> escreveu:


On 18/08/15 02:18 PM, Javier Guerra Giraldez wrote:
On Tue, Aug 18, 2015 at 12:14 PM, Soni L. <[hidden email]> wrote:
Can we get expressionblocks?
AKA functions:

local v = (local function() return 3 end)()



Basically, but without the GC overhead of creating closures, or the VM overhead of calling functions.

Alternatively:

do
<block>
export local <namelist> = <explist>
end

Where `export` would create the locals on the outer scope. This is useful when creating closures without polluting the environment.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Soni "They/Them" L.


On 18/08/15 06:08 PM, Rodrigo Azevedo wrote:
>
> +1
>
> How to define the "outer scope" ? (-1)
>
The block you put the do-end in is the outer scope. (Yes, you would have
to use a do-end to be able to use export.)

-- outer scope
do
-- inner scope
export local v = 3
end

or

do
-- outer scope
do
-- inner scope
export local v = 3
end
-- outer scope again
end

> Em 18/08/2015 16:43, "Soni L." <[hidden email]
> <mailto:[hidden email]>> escreveu:
>
>
>
>     On 18/08/15 02:18 PM, Javier Guerra Giraldez wrote:
>
>         On Tue, Aug 18, 2015 at 12:14 PM, Soni L. <[hidden email]
>         <mailto:[hidden email]>> wrote:
>
>             Can we get expressionblocks?
>
>         AKA functions:
>
>         local v = (local function() return 3 end)()
>
>
>
>     Basically, but without the GC overhead of creating closures, or
>     the VM overhead of calling functions.
>
>     Alternatively:
>
>     do
>     <block>
>     export local <namelist> = <explist>
>     end
>
>     Where `export` would create the locals on the outer scope. This is
>     useful when creating closures without polluting the environment.
>
>     --
>     Disclaimer: these emails are public and can be accessed from
>     <TODO: get a non-DHCP IP and put it here>. If you do not agree
>     with this, DO NOT REPLY.
>
>

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: [local] <namelist> = do <block> =<explist> end

Tim Hill
In reply to this post by Soni "They/Them" L.

> On Aug 18, 2015, at 12:56 PM, Soni L. <[hidden email]> wrote:
>
>>
>>   -spc (What, exactly, are you doing that require all these proposals you
>> make?)
>>
> Time-sensitive stuff.
>

If your project is really that time-sensitive you should be coding all or part of it in a more traditional compiled language. No doubt there are 100+ changes that could be made to Lua to make it faster, but then it wouldn’t be Lua any more, it would be a rather bad version of something like C.

We intermix Lua and C in most of our work, and carefully define “dumb but fast” C libraries to do the heavy lifting but leave all policy and business decision logic in Lua. It’s worked well for us.

—Tim