[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: another hat in the ring regarding Lua 5.2: static typing
- From: Mark Hamburg <mhamburg@...>
- Date: Thu, 28 Feb 2008 16:11:14 -0800
on 2/28/08 11:16 AM, Asko Kauppi at email@example.com wrote:
> LuaSub gives '-sjacket' for making runtime type checks, and it works
> like this:
> local function mydear( t :string_or_table, i :int, j :[int], n :
> [number] )
> : string, table, [int]
> ...function body with returns...
> '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
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?