3 ms·
I saw there are no ends in function and class definitions used, are they optional in if and for too?
by k__ 12y ago
I saw there are no ends in function and class definitions used, are they optional in if and for too?
- SnowyOwl 12y agoDo you mean whether Pony requires/allows braces to delimit functions, or class definitions? If so, the answer is no, as they are superfluous.
- k__ 12y agoI saw function and class definitions were delimited by their indentation but if and for used "end". I wanted to know if these "end"s are optional (I can write it like Python) or strictly needed (I have to write it like Ruby).
- a0 12y agoI don't think so. The language is (almost) whitespace insensitive so the only way to know where a certain control statement terminates is by having the `end` token. It is unnecessary on the top-level though, since the top-level expression will end where the next one begins. Which means you probably can't have nested class/function definitions. This technique is not new and is used in OCaml, for example.
- k__ 12y agoAh I see. Didn't no such a mix was common :)
- barrelrider 12y agoThis is correct, classes and functions are not dependent on indentation, they just don't need an end. And yes, there are no nested classes and functions (other than in object literals).