-
Notifications
You must be signed in to change notification settings - Fork 4
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
Expressions in place of values #1
Comments
Now I see |
Yeah, that's important. @krux02 had the idea to use backtick as in scala (http://kishorelive.com/2011/11/02/backticks-in-scala/) in his lib, I think that makes sense for gara too: but not only for labels, for various expressions as in your example. of (e: `(f: 2)`): .. would match only a tuple If we do it for variables too, we can even think of removing |
Backticks seem though be a limiting choice. They are used in Nim and may be needed inside expressions, and as they don't have open/close pairs, as parentheses, so either some escaping means will be needed, which is both not pretty and syntax-breaking, or to give up on possibility to use backticks inside, then expressions are both limited and somewhat special-case'ed; in both cases they are not just "Nim expressions", somewhat more special. With Yet problems with backtick and other non-pair delimiters: proc `+`(a, b: int): int = 42 # so users may need "system.`+`" later in code
of (e: `(f: system.`+`(2, 2))`) # breaks! and worse: may be even parsed, but not as expeected,
# making hard to debug
of (e: !{(f: system.`+`(2, 2))}) # no special syntax or special awareness for code inside "!{...}",
# and no problems |
|
I agree it's not perfect, but it seems as a more natural notation compared |
The problem with the other ones is that
|
Something else I can do is
|
Calls and binary expressions seem to be the only other really common cases
Of course one would be always able to use the |
The last point is: I want to be able to support powerful unification: (a: @name, b: @other, c: expression(@name, @other)) should kinda work e.g.
(a: @name, b: @b, c: @name - @b) |
but basically this just requires us to check for |
I think if quotation is supported and with full Nim's syntax allowed inside (
|
I try to use ranges as patterns, and they don't work now: let a = 3
match(a):
of 2..3:
echo 1 While ranges as a much common case would be desired to be used just directly, of !{2..3}: That is it's result is checked not only with |
Yes, all captures should be available in expressions after them.
ranges are going to have first class support too |
|
|
If I correctly understood what you mean, you could use some special syntax then for evaluation,
like
of eval 2 + 2: ...
orof (2 + 2): ...
(even both these syntaces at the same time), still reservingof 2 + 2: ...
for some patterns' syntax.Actually it would be just a special syntax for evaluation, and it could be used inside patterns syntax:
of (2*2) * (3*3): ...
- here2*2
and3*3
are evaluated, and*
between them is for some patterns' syntax applied to their results.The text was updated successfully, but these errors were encountered: