language change: change how the experimental dot operators work
This commit is contained in:
parent
416a322efb
commit
33814cf63e
5 changed files with 25 additions and 19 deletions
|
|
@ -17,8 +17,8 @@ or dynamic file formats such as JSON or XML.
|
|||
When Nim encounters an expression that cannot be resolved by the
|
||||
standard overload resolution rules, the current scope will be searched
|
||||
for a dot operator that can be matched against a re-written form of
|
||||
the expression, where the unknown field or proc name is converted to
|
||||
an additional static string parameter:
|
||||
the expression, where the unknown field or proc name is passed to
|
||||
an ``untyped`` parameter:
|
||||
|
||||
.. code-block:: nim
|
||||
a.b # becomes `.`(a, "b")
|
||||
|
|
@ -28,7 +28,7 @@ The matched dot operators can be symbols of any callable kind (procs,
|
|||
templates and macros), depending on the desired effect:
|
||||
|
||||
.. code-block:: nim
|
||||
proc `.` (js: PJsonNode, field: string): JSON = js[field]
|
||||
template `.` (js: PJsonNode, field: untyped): JSON = js[astToStr(field)]
|
||||
|
||||
var js = parseJson("{ x: 1, y: 2}")
|
||||
echo js.x # outputs 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue