lua-users home
lua-l archive

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



On 2015-07-29 21:23, Dibyendu Majumdar wrote:

> Hi,
> 
> Ravi allows local declarations and function parameters to have
> optional type annotations. This obviously makes any code using such
> annotations incompatible with Lua.
> 
> It would be nice if Lua had a mode where it ignores any tokens between
> a variables name and the comma or equal sign. That is:
> 
> local i: integer = 0
> 
> In the special mode Lua would ignore everything after 'i' upto the
> '=' sign. Similarly:
> 
> function (a: integer, b: integer)

Some silly idea, why not doing it the other way around and use existing
lua compatible syntax for ravi.

 local i__integer = 0
 function (a__integer, b__integer)

I know, we all hate hungarian notation, its overly verbose and failed
in various ways how it is proposed/used in C/C++.  

By using this in lua, the overly verbosity will remain. But it 'could'
shine in some other ways which are impossible in C/C++ where the actual
type definition and the variable name are not enforced to relate to
each other. Things will become even more interesting when custom types
(interface, prototypes, classes or whatever) come into play.

I am not thinking/proposing this as only way for type declarations, I
am well aware that many people will dislike it. But maybe it could be
an optional alternative or at least give some thoughts about a
different view of types in a dynamic language. 

	Christian

> 
> Here the text ': integer' would be ignored.
> 
> Ravi does not support annotating function return types - but I guess a
> similar enhancement would allow optional return type annotation for
> functions, but in this case making the parser determine what is to be
> ignored is not easy as the syntax of the declaration would need to be
> known.
> 
> A solution that does not dictate a specific type annotation syntax is
> preferable as there is no standard way of defining types; and Ravi's
> approach does not always match the approach taken by others.
> 
> This enhancement would allow Ravi programs to be run in Lua as Lua
> programs.
> 
> Thanks and Regards
> 
> Dibyendu
>