lua-users home
lua-l archive

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


On Mon, 19 Apr 2010 03:53:51 -0400
Henk Boom <henk@henk.ca> wrote:

> 2010/4/19 spir ☣ <denis.spir@gmail.com>:
> > On Mon, 19 Apr 2010 01:05:58 -0400
> > Henk Boom <henk@henk.ca> wrote:
> >> One controversial alternative: instead of using '!' use '\n'.
> >>
> >>     henk
> >
> > Are you joking? Anyway...
> > * How can one chain calls, eg having the result of a query be the argument of a command?
> >    console.write list.sort!!
> >  (same issue for having a query result nearly anywhere in a compound expression)
> > * In a rather extreme variant of my project, there cannot be any complex expression, so one would write the above in two steps.
> 
> Sorry, I misunderstood '!' as being a statement separator.

I just needed a func call "terminator". First to allow having them embedded in more complex expressions, and second to avoid the need for a placeholder in case of no arg at all.

> Looking at the example of
> 
> console.write list.sort!!
> 
> Which of the following does it represent? How would you write the other?
> 
> console.write(list.sort())
> console.write(list.sort)()

The former, since the pattern "obj.method arg!" means that whatever is between the method name and '!' is the arg. The latter (I also considered), meaning the method itself is the result of computation, is rare and can more readably be written in 2 steps.

> With the following:
> a b!
> a b!
> 
> would it turn into:
> 
> a(b)
> a(b)
> 
> or would it be more like "a b! a b!" which more intuitively becomes:
> 
> a(b)(a(b))

No, the semantics really follows the syntax stupidly, there is no trick on the language side. Meaning the former holds: 2 statements.
In fact, I  think that to have the equivalent of a(b)(a(b)), you miss a final '!': there are 2 nested calls and a global one, so you should write it "a b! a b!!". If the parser would allow called methods to be denoted as expressions, it would then interpret the first call as the expression of a method object.
But the style of the language tries to favor simple expressions; here we need at least one first step to get and name the actual method to be called. Imagine actual methods are stored in an array. In Lua you can write:
    t[i](x)
In my case you need
    m = t#i
    m(x)!

> ---
> Haskell uses the implicit-function-call syntax you're writing, and it
> gets around a lot of these problems by being purely functional, which
> has the side effects that:
> 
> - there is no difference between a function which takes no arguments
> and a regular value (i.e. no difference between "function () return 1
> end" and "1")
> - there are no statements, only expressions

In my language, the contrary holds: there are only statements. This may explain why I can follow such a pattern. (*)


> Also, the fact that all Haskell functions are "actually" of arity 1 helps :)

The same for me.

> I think OCaml also has a similar syntax too, but I don't know enough
> about it to be able to say anything useful.

Don't know anything about OCaml.

>     henk

Denis

(*) Actually, there is a special detail: like in many functional languages, a stand-alone expression denotes the return value of a *query* method:
   Number.cube : query(n)
       n*n*n
   Number.factorial : query(n)
       if <=(n 1)
           1
       else
           m : -(n 1)
           m.factorial!
(note the '!' ending the definition of factorial! ;-)
But it's actually a kind of "return" statement. Simply, there is no need for a keyword; and this choice offers a direct syntax for anonymous funcs if needed, eg:
   cubes : numbers.map formula(n) n*n*n!
I guess this is light enough for making functional fans happy... [I like the word "formula" here. Formula are inline and single-expression (and usually anonymous) queries.]
________________________________

vit esse estrany ☣

spir.wikidot.com