clever-lang / clever

Clever programming language
Other
47 stars 16 forks source link

Other syntax for anonymous function definition #230

Open muriloadriano opened 11 years ago

muriloadriano commented 11 years ago

For simplicity one might want to have a simplified way to write its anonymous functions. Consider the each method. Currently we would have to write something like:

arr.each(function(x) { println(x * x); });

It would be nice if we were able to write less. My proposal is something like:

arr.each(|x| { println(x * x) });

Notice that the missing ; is intentional. The ; for the last sentence should be optional.

felipensp commented 11 years ago

Well, I do prefer the current syntax. What do you guys think about? @heuripedes @gogo40

gogo40 commented 11 years ago

Yeah, I like |x| !

2013/1/12 Felipe Pena notifications@github.com

Well, I do prefer the current syntax. What do you guys think about? @heuripedes https://github.com/heuripedes @gogo40https://github.com/gogo40

— Reply to this email directly or view it on GitHubhttps://github.com/clever-lang/clever/issues/230#issuecomment-12185947.

Atenciosamente, Péricles Lopes Machado

"Uma verdade claramente compreendida não pode ser escrita com sinceridade."

Marcel Proust

muriloadriano commented 11 years ago

The idea isn't replace the current syntax, but have an alternate syntax.

felipensp commented 11 years ago

Ah, got it. I'm not against alternative syntax at all. :)

heuripedes commented 11 years ago

As convenient as it may look, I do not like the |x| {} syntax for the following reasons:

felipensp commented 11 years ago

It makes sense, Higor. But what do you mean by simplify/shorten the current syntax? What do you suggest?

muriloadriano commented 11 years ago

What if we introduce a new symbol?

var func = $(x, y) { 
    return 'foo' + x + y;
}

arr.each($(x) { println(x * x); });