lua-users home
lua-l archive

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

Last email (hopefully :) ) is on type:

Your approach has been to provide libraries that COULD be monkey patches, but are not. tablex and stringx being primary examples. 

I would love to see such a library for type (typex), especially if it replaced pl.class's system. Imagine a type system which ape'd (monkeys and apes) LPeg's syntax:

If  this_thing == animal + plant + mineral then ...

P = pl.typex.P
my_argument_list = P"string"  * P(1)^1
my_args2 = (P"number" + P(1) / tonumber) * (P"my_object" + my_obj_init_args /my_object._init)

(Any further examples would include back tracing...)

You can imagine how these type patterns might also contain class definitions, such that you could construct objects by calling the type object with the correct arguments (if any). 

Also, imagine applying function types by making types pattern for the arguments and to the return value and then (optionally) wrapping functions/fun tables/coroutines. You could then query the type of the function. Flip a flag to "off" so that this wrapping didn't happen when you weren't testing. For myself, I would do all of my argument checking with this, so anything with a public interface would be wrapped, at least for arguments, if not return values. 

This is a thought that I've been playing with, which is why I state it here. I don't so much feel it be belongs in an x.y release. 

I'll spare you my 4th email, which was going to be on ranges. :)