Skip to content

Small doc improvements for std/with #17556

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

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/std/with.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
## and https://github.com/nim-lang/RFCs/issues/192 for details leading to this
## particular design.
##
## **Since** version 1.2.
## **Since:** version 1.2.

import macros, private / underscored_calls

macro with*(arg: typed; calls: varargs[untyped]): untyped =
## This macro provides the `chaining`:idx: of function calls.
## This macro provides `chaining`:idx: of function calls.
## It does so by patching every call in `calls` to
## use `arg` as the first argument.
## **This evaluates `arg` multiple times!**
##
## .. caution:: This evaluates `arg` multiple times!
Copy link
Member

@timotheecour timotheecour Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add / integrate an example showing _ and add explain we can use _ in the doc comment (allows cases where we don't replace the "first argument")

  var x = 1
  var y = 100
  with x:
    +=2
    *=10
    y+=_
  assert (x, y) == (30, 130)

runnableExamples:
var x = "yay"
with x:
Expand Down