-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add collect with infered init, refs #16078 fixes #14332 #16089
Conversation
It imports tables and sets, maybe inferring container type should work for seqs only? |
lib/pure/sugar.nim
Outdated
of nnkTableConstr: | ||
result[1] = n[0][0] | ||
result[2] = n[0][1] | ||
if bracketExpr.len == 0: | ||
bracketExpr.add(bindSym"initTable") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: use newSeq
and produce a seq[(K, V)]
Or make it an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, it's not worth it: you can do collect(for i, x in a: (i, x))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that better?
when (NimMajor, NimMinor) >= (1, 5):
bracketExpr.add(bindSym"initTable")
else: error("Table type is not specified")
lib/pure/sugar.nim
Outdated
template adder(res, k, v) = res[k] = v | ||
result[0] = getAst(adder(res, n[0][0], n[0][1])) | ||
of nnkCurly: | ||
result[2] = n[0] | ||
if bracketExpr.len == 0: | ||
bracketExpr.add(bindSym"initHashSet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, use newSeq
and ignore {a}
For now I just used |
@planetis-m Hi! Sorry, I don't quite follow. Take a look at what exactly? What is it you can't reproduce? |
@moigagoo this build failure:
|
So, AFAIU you've modified the behavior of I suggest you try running simple tests like this one with your modified version and see if it runs: https://play.nim-lang.org/#ix=2EYf |
no it wasn't modified I added a second macro, it's hidden under a since(1, 5) let x = collect(newSeq):
for d in data.items:
"bird $1" % [d]
assert x == @["bird bird", "bird word"]
runs fine. @moigagoo if you can Or just run with |
@planetis-m Well I have no idea why it could break ¯_(ツ)_/¯ Try wrapping it in a unittest test macro to replicate the code that is actually being run and that actually fails. Maybe the new version somehow doesn't play well within macros. A few points:
Sorry for not being helpful, and I really hope I don't sound like an asshole. Just protecting my personal time. |
You make good points. However your package is broken, my PR isn't related. Once you get the time, fix it please. Since it's my responsibility for fixing the stlib, its yours to fix your package :) |
I disagree. The tests pass with a PR that has been pushed after yours: https://github.com/nim-lang/Nim/runs/1435997008?check_suite_focus=true#step:11:519 |
Checked the produced ast, PR changed some nimnodes from ident to sym: https://play.nim-lang.org/#ix=2EYD |
Can I move |
This can use a review, thank you! |
… (nim-lang#16089) * changelog * add testcase, fixes nim-lang#14332
… (nim-lang#16089) * changelog * add testcase, fixes nim-lang#14332
… (nim-lang#16089) * changelog * add testcase, fixes nim-lang#14332
Supersedes #16082, refs #16078.
it
is not injected. Reason is, if you writeit[i] = a
then there is no point using collect, is there? :P