[Bug #20482] [DOC] Clarify about pattern maching guard clause

Guard clauses can only be used in `case` pattern matching statements,
not in `=>`/`in` operators.
This commit is contained in:
Nobuyoshi Nakada 2024-05-12 16:23:00 +09:00
parent 5695c5df95
commit b911d2222f
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

View File

@ -422,7 +422,8 @@ These core and library classes implement deconstruction:
== Guard clauses
+if+ can be used to attach an additional condition (guard clause) when the pattern matches. This condition may use bound variables:
+if+ can be used to attach an additional condition (guard clause) when the pattern matches in +case+/+in+ expressions.
This condition may use bound variables:
case [1, 2]
in a, b if b == a*2
@ -450,6 +451,11 @@ These core and library classes implement deconstruction:
end
#=> "matched"
Note that <code>=></code> and +in+ operator can not have a guard clause.
The following examples is parsed as a standalone expression with modifier +if+.
[1, 2] in a, b if b == a*2
== Appendix A. Pattern syntax
Approximate syntax is: