lua-users home
lua-l archive

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


On Tue, Aug 13, 2013 at 8:18 AM, Jay Carlson <nop@nop.com> wrote:
For Lua, the safest thing is to compile the specs at module load time:
local RFCTime = TimeFormatter"HH:MS:SS TMZ"

Well, TimeFormatter could throw a wobbly if it was passed something that didn't make sense.

Penlight's Date.Format is a step in the right direction:

http://stevedonovan.github.io/Penlight/api/modules/pl.Date.html#Date.Format

But it does not blow up (or even return a proper error) if passed nonsense.  So, work to be done (in particular, the default formatter without an explicit string tries way too much)

I understand the context you're coming from - that there are too many _untyped_ strings floating around with structure which is only checked when they are 'interpreted'.

I do like string interpolation tactics like "$YEAR-$MONTH-$DAY". Some languages allow string interpolation that respects the lexical environment, (so in Moonscript it would be "#{YEAR}-#{MONTH}-#{DAY}") but even without language support (a) these strings can be checked by a suitable formatter constructor and (b) allows for formatting tables.