lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


With pcall couldn't you implement the defer functions in Go ?

This is pseudo code somewhere between _javascript_ and Lua...

var deferable = function()
{
  return function()
  {
    var error, results = pcall( arguments[0] )
    if(!error) return results;
    for( var i=1; i<arguments.length; i++ )
      arguments[i]( error, results )
  }
}

var f = deferable(
  function(){ throw("oops") },
  function(){ alert("cleaning up") },
  function(error, msg )
  { 
    if(error==200)
       throw( "maybe you still want to blow up anyway" )
  }
)

f()

On Fri, Sep 9, 2011 at 5:57 PM, Hisham <hisham.hm@gmail.com> wrote:
On Fri, Sep 9, 2011 at 5:37 AM, Taj Khattra <taj.khattra@gmail.com> wrote:
> On Thu, Sep 8, 2011 at 11:03 PM, steve donovan
> <steve.j.donovan@gmail.com> wrote:
>> This page in fact makes the assertion:
>>
>> "Lua took multiple assignment and multiple returns from function calls
>> from CLU."
>>
>> But this is a [citation needed] ;)
>
> R. Ierusalimschy, L. H. de Figueiredo, W. Celes,
> The evolution of Lua,
> Proceedings of ACM HOPL III (2007) 2-1–2-26.
> (http://www.lua.org/doc/hopl.pdf)
>
> section "4. Birth":
>    ...
>    From CLU we took multiple assignment and multiple returns from
> function calls.
>    We regarded multiple returns as a simpler alternative to reference
> parameters used
>    in Pascal and Modula and to in-out parameters used in Ada; we also
> wanted to avoid
>    explicit pointers (used in C).

Excellent! There we go, then:

http://en.wikipedia.org/wiki/CLU_%28programming_language%29#References

--
-- Hisham
http://hisham.hm/ - http://colorbleed.com.br/