Skip to content
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

Small doc improvements for std/with #17556

Merged
merged 1 commit into from
Mar 29, 2021
Merged

Small doc improvements for std/with #17556

merged 1 commit into from
Mar 29, 2021

Conversation

konsumlamm
Copy link
Contributor

Some notes:

  • The since pragma can't be used here (see template/macro pragmas don't work in templates (eg: byaddr, since etc) #15920), at least it has no effect on the generated documentation.
  • Is there any particular reason why with is not part of the sugar module? If not, should this perhaps be reexported by sugar in the future?
  • Currently, the with macro evaluates arg multiple times, should this be changed to only evaluate it once? If not, what are the reasons for this (should be documented imo)?

## 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)

@timotheecour
Copy link
Member

timotheecour commented Mar 29, 2021

Is there any particular reason why with is not part of the sugar module? If not, should this perhaps be reexported by sugar in the future?

IMO we should, in future PR. I'm in favor of splitting large modules (times, os, sugar etc) into smaller ones + re-exporting those in the original large module, which allows granular access when needed (cyclic dependencies etc) or easy access to all symbols by default.

Currently, the with macro evaluates arg multiple times, should this be changed to only evaluate it once? If not, what are the reasons for this (should be documented imo)?

trickier than it seems, but it's possible, using similar implementation as (or reusing) #13750, but that would deserve its own PR. evalOnce takes care of the diffculty of dealing both with lvalues (no copying) and rvalues. (see also #13245 chainEval which IIRC avoided multiple evaluations but did a copy even for lvalues)

@Araq Araq merged commit 9e3960e into nim-lang:devel Mar 29, 2021
@konsumlamm konsumlamm deleted the with branch April 10, 2021 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants