Open ozra opened 8 years ago
What does a leading #
signify? For example in #happy
? Is it a symbol?
Suggest case
instead of cond
.
I approve of hyphen-case
and indent-based structuring.
@stugol - Yes, that's it! It is referred to as Tag
in Onyx-lingua, however it's the exact same thing. (see #9)
Regarding case|cond|etc. see #13.
[RFC] Syntax Structure
"offside syntax": significant indent and optional end tokens
Structure, indentation and white space is important. If above didn't convince you... Yes, yes, no-one worth their salt writes with such bad style -- granted -- though it did get the point across. I hope!
Onyx is structured via indentation and has optional end tokens to make block ends explicit when wanted. There's experimental pattern matching support for the end-tokens also, making it possible to match up intended block starts even more explicitly. This will likely be dropped from the syntax though.
Details:
my-perfectly-legal-identifier-for-a-fn? 47
) and (my-perfectly-legal-identifier-for-a-fn! 47
, which is not the same asmy-perfectly-regular-identifier-for-a-fn !47
)a-func arg1, arg2
is the same asa-func(arg1, arg2)
, but watch out for:- that called the method through juxtaposition rule - the parentheses instead expressed a grouping (which would syntax error in this case). A reason why thea-func (arg1, arg2)
ident SPACE ...
precedes:a-func (foo == true), (if bar == 47 ? 1 : -1)
.the-method
in a lib, you can use it asthe_method
- if you're hell bent on avoiding fluidly readable identifiers. And vice versa.Here's an example showing off one of the many ways below code can be written and formatted (specially cond/case syntax currently has a shitload of variations to choose from - waiting to be reduced!), including the experimental pattern matching end token extension.
Prior Art
For offside / indentation significance: ISWIM, Python, Haskell, Nim, Cytoc-Cython ;-), LiveScript, CoffeeScript, SugarCpp, F#, etc.
The voluntary
end
tokens look more like Ruby, Lua, Pascal, etc., and - dare I say it - Visual Basic, for the extended semantic matching.Preference and Motivation
I've coded in C, then C++, for a loooong time (well, aside from hoards of other languages and a lot of assembler of course). But already in '99 I had enough with the braces-semicolon syntax. I coded a simple heuristic transpiler called Cython (no relation what so ever to the project with the same name that came 9 years later), obviously inspired by Python lexicography.
I find the indent based structuring superior, after having used both, side by side, for about 15 years. "If it looks right - it is right". Not to mention that studies on the programmer's mind seem to hint at it being a better choice. Lacking only one thing in most languages that leverage it; one very important thing; the possibility of ending blocks explicitly (and doing it for long/complex blocks).
When scopes grow over more than a few lines, or nesting depth grows, those dangling ends become very... loose.
The perfect solution is of course: both!
The recommendation, as I see it, is to absolutely not use end-tokens in constructs that are just a few lines, with no complex nesting - it's just visual clutter. Beyond that it's much clearer to use explicit end-tokens, and you can catch and contain scoping and localize syntax errors much better.
Some References