-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loose idea: yet a function call syntax variant #60
Comments
So, you'd have to use a
Presumably you can't use the indent syntax when using an
I like the idea in principle - it would make dsls a lot easier to write - but I anticipate problems.
On a side note: I don't need commas when splitting arrays and hashes over multiple lines? Awesome. |
I think we need a compromise: Special syntax when defining a function, to specifically enable this indent-based usage. Think about it. Most of the time, people won't be using functions in this manner; but having to remember to put
|
That's right, I wanted "lists" to be like natural lists, inspired by livescript/coffeescript/YAML, feels much more intuitive :-) (see #9, ctrl-f search for "List" and "Map" respectively to go directly to the details on the syntax) Hmm, yes, it would really become ridiculous - in all control structures - since it essentially will mean expression-block-starters becomes mandatory in practice (functions are used most all of the time in Onyx, since they often "wrap"/"isolate" values as getters.) You're also absolutely right on the error message - it will be possible to heuristically figure out what the user probably meant in most cases, and hint in the error, but that's not good enough. Specifying behaviour per functions is no-go. The main reason in Onyx for compiling faaaast (as possible.. and we want that) is that lexing and parsing can identify everything (essential) without knowing anything of semantics (like what kind of function, or if it even is one, that a certain symbol represents). For instance C++ mixes lexing, parsing and semantics in a big While the indent upon indent for Which brings me to an idea: since the primary use case for the call syntax is for enabling DSL'ish constructs, they should not be expected in control structures. So, when in a control-structure any indent is interpreted as belonging to the control structure - not the call. It's an exception to the call syntax rule that is very reasonable and expected behaviour in my opinion. Ideas? |
Agreed. DSLs are markup, not conditional expressions. |
I implemented it and it worked smoothly with the current crazy-specs without a hinge. (Better not get to happy until the trolls under the surface has unleashed their ugly fury) Sample code using "Temel" (tested):
=> I must honestly say, when I whipped it up to test indent-calls, I just realized it when the html came out without a snag, I was like "Aaaaaaah yeah, baby!". Didn't expect it to turn out so well so simply. This is the smoothest way of templating html I've seen (ymmv and all that ;-) ) - and it's all compiled to blazing binary code! Fuck node.js B-) Temel is to thank for not having to code poc-functions just to try it. |
How about:
|
Was the above not an example, I would've written it:
Of course you can currently write:
Supporting the same without the comma has the same strings attached as #66 - it can be done, but rules differ depending on if it's a literal or not in that case. Of course with this new perspective of DSL-usage, both are worth thinking about. If you'd like, could you add that to #66? I re-opened it. |
Righty ho. |
Currently you can call a function / method in two ways:
I'm thinking about yet one that I think would work without conflicts with the rest of the syntax (as said, still a loose idea) - using indent:
Now, why on earth why? It would be of benefit for DSL'ish coding. With the indent style, the following arguments will follow literal-array / literal-hash rules: You can use new-lines as separator besides comma.
Let's take a practical example using "temel", half-stolen from https://github.com/f/temel:
(Note: I don't know temal syntax/API, so above is slightly ad-libed regarding title/h2, but the essence holds)
How's that for writing a web app? Rocks the socks of anything else.
How about possible conflicts? Let's try to pre-empt.
Above, if
foo
is not a local variable, it is a call, and then the indentation will apply to the function, not theif
. This can be confusing. But if your functions are named properly: it will not be.The big downside - is that the compiler cannot assume which signature overloads will be available for the function named foo, so it will always treat the indent as "beginning of args" for the function. This means that if
foo
is in fact an arg-less function, and the above was intended asif foo is truthy then 47
- you'd have to be explicit where you didn't have to before:or
or... (any other variation of block starter [reminder to crystalers: block as in block of code])
In these the explicit block starter makes it clear that the indented block belongs to the
if
.Good? Confusing? Gimme your input!
The text was updated successfully, but these errors were encountered: