lua-users home
lua-l archive

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


On Sun, Aug 16, 2009 at 6:42 AM, François
Perrad<francois.perrad@gadz.org> wrote:
> But for declarative DSL, the mandatory use of parenthesis for arguments function
> (except in case of a single string or table) is a big limitation.

A single character difference is "big"?

> As example, consider the 2 following versions of the same code
> (which come from my current work on <http://github.com/fperrad/lua-Coat/>
> and it is not really a DSL
> and David Manura already send me some good suggestions in pure Lua)
>        -- "classic" Lua
>        class 'Point'
>
>        has( 'x', { is = 'rw', isa = 'number', default = 0 } )

What about

class{"Point",
  x = { is = 'rw', isa = 'number', default = 0 },
  -- ... or
  x = property{0, is="rw", isa="number")

or

class.Point{
  x = property{0, is="rw", isa="number")
  -- isa should default to type(default), is should default to rw
  ...
}

> A seasoned Lua developper could make abstraction of extra parenthesis.
> But a DSL user cannot because usually he doesn't known Lua.

Maybe in general, but in this particular case, why would a non-lua
programmer be creating lua classes? Aren't classes abstractions that
are only useful to programmers?

>        has( 'x', { is = 'rw', isa = 'number', default = 0 } )
>        has 'x' => { is = 'rw', isa = 'number', default = 0 }

I don't believe that a non programmer, someone unfamiliar with lua and
ruby, would find
either of these more or less cryptic than the other. You've removed
two parentheses,
and replaced them with a new thingy "=>" that would be just as
completely meaningless
to the non-programmer. Perhaps this non-programmer is actually a
programmer familiar
with some other language than lua, and his expectations come from that language?

>        has 'x' => { is = 'rw', isa = 'number', default = 0 }

Even this would seem to be clearer to me:

   has{"x", is = 'rw', isa = 'number', default = 0}


> This patch is not backward compatible with Lua,
> for example it breaks the following code :
>        printf("Hello %s from %s\n", os.getenv "USER", _VERSION)
> it must be rewritten :
>        printf("Hello %s from %s\n", os.getenv("USER"), _VERSION)

> I hope that Lua will become the best choice for building DSL.

I think you will find that in a language where functions are first
class, that implicit
method calls don't work, the syntax becomes ambiguous or horridly
unpredictable, as in the above.

It works in ruby, but the price is that there are no functions, just
methods, and methods
are not first class, you need to manipulate them as objects
(BoundMethod or UnboundMethod objects). Different language, different
choices.

Anyway, if you have such specific desires for the syntax of your DSL,
why not use lpeg to build a real DSL?

Cheers,
Sam