lua-users home
lua-l archive

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


on 2/28/08 11:16 AM, Asko Kauppi at askok@dnainternet.net wrote:

> 
> LuaSub gives '-sjacket' for making runtime type checks, and it works
> like this:
> 
> tests/test-jacket.lua:
> 
> local function mydear( t :string_or_table, i :int, j :[int], n :
> [number] )
>    : string, table, [int]
> ...function body with returns...
> end
> 
> 't' is either string or table (checked by 'assert.string_or_table()')
> 'i' is integer ('assert.int()')
> 'j' is an optional integer (nil or fulfilling 'assert.int()')
> 'n' is ...

It's interesting syntactic sugar. Obviously this could be handled by
assertions in the code but sugar might increase the chance that they would
get written.

Are they optional on a compilation and if so how do you switch them on and
off? Maybe if they only applied to functions it wouldn't matter as much.
Maybe a tracing JIT makes their cost drop low enough in practice so as not
to matter. And if optional, one needs to be careful not to have any side
effects in the functions.

But I like the general notion.

Have you taken any of the standard benchmark code and added type assertions
to see what sort of expense they incur?

Mark