summary refs log tree commit diff stats
path: root/lib/pure/sugar.nim
Commit message (Collapse)AuthorAgeFilesLines
* opensym as node kind + fixed experimental switch (#23892)metagn2024-08-121-1/+1
| | | | | | | | | | | | | | | refs https://github.com/nim-lang/Nim/pull/23873#discussion_r1687995060, fixes #23386, fixes #23385, supersedes #23572 Turns the `nfOpenSym` node flag implemented in #23091 and extended in #23102 and #23873, into a node kind `nkOpenSym` that forms a unary node containing either `nkSym` or `nkOpenSymChoice`. Since this affects macros working on generic proc AST, the node kind is now only generated when the experimental switch `genericsOpenSym` is enabled, and a new node flag `nfDisabledOpenSym` is set to the `nkSym` or `nkOpenSymChoice` when the switch is not enabled so that we can give a warning. Now that the experimental switch has more reasonable semantics, we define `nimHasGenericsOpenSym2`.
* Param match relax (#23033)Ryan McConnell2023-12-151-2/+3
| | | | | | | | | | | #23032 --------- Co-authored-by: Nikolay Nikolov <nickysn@gmail.com> Co-authored-by: Pylgos <43234674+Pylgos@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jason Beetham <beefers331@gmail.com>
* complete std prefixes for stdlib (#22887)ringabout2023-10-301-1/+1
| | | | follow up https://github.com/nim-lang/Nim/pull/22851 follow up https://github.com/nim-lang/Nim/pull/22873
* [sugar] handle HiddenDeref in capture, error at CT if unsupported nnk (#20680)Vindaar2022-11-101-3/+13
| | | | | | | | | | | | * [sugar] handle HiddenDeref in capture, error at CT if unsupported nnk Instead of running into trouble of the `.strVal` access failing, it's better to error at CT. * [tests] remove unnecessary import in test case * improve ident extraction & extend test cases * [tests] improve tests for `capture` of different types & act. check
* Recommend `mapIt` in some cases (#20347)Amjad Ben Hedhili2022-09-191-6/+4
| | | | | * Recommend `mapIt` in some cases * Remove runnableExample
* fixes #18954 (#18955)Andreas Rumpf2021-10-051-2/+2
|
* Documentation only, Sugar arrow and semicolons (#18574)Juan Carlos2021-07-251-0/+4
| | | * Document that sugar arrow do not support semicolon as argument separator
* typo: nonexistant => nonexistent (#17918)Timothee Cour2021-05-021-1/+1
| | | | | * typo: nonexistant => nonexistent * fix test (ordering differs because of https://github.com/nim-lang/Nim/issues/17910)
* CIs: attempt to use csources_v1 (#16282)Andreas Rumpf2021-04-211-1/+1
| | | | | | | | * CIs: attempt to use csources_v1 * also updated the BSDs * also updated azure pipelines * std modules should not itself use the 'std/' import dir... * compiler has to be careful with std/ for v1 booting
* remove {.compileTime.} for procs with NimNode: redundant because of ↵Timothee Cour2021-03-231-1/+1
| | | | tfTriggersCompileTime (#17463)
* fix #13491 #17279 runnableExamples now don't get lost in translation (#17282)Timothee Cour2021-03-091-3/+2
| | | | | * fix #13491 runnableExamples rendering * fix a runnableExamples thanks to this bugfix
* Remove support for named procs with sugar.=> (#17220)konsumlamm2021-03-051-10/+0
| | | | | | * Add docs & tests for named procs with sugar.=> * Remove support for named procs in sugar.=> * Resolve conflict * Fix test
* use `-r:off` for runnableExamples that should compile but not run (#17203)Timothee Cour2021-03-011-2/+2
| | | | | * use -r:off for runnableExamples that should compile but not run * use -r:off in other RT disabled tests
* improve docs for sugar.collect (#17188)Timothee Cour2021-02-261-24/+29
|
* fix #16967 [backport:1.2] (#16976)hlaaftana2021-02-091-1/+1
| | | | | * fix #16967 [backport:1.2] * move test to tsugar
* Sugar tests (#16820)konsumlamm2021-02-021-12/+14
|
* `dumpToString`: improves on `sugar.dump` (#16841)Timothee Cour2021-02-021-3/+32
| | | | | | | * dumpToString * _ * fixup * changelog * address comment: removed the word "Deprecated"
* Sugar improvements (#16802)konsumlamm2021-01-251-66/+63
| | | | | | | | | | | | | | | * Use runnableExamples in sugar Remove unnecessary import * Add trailing newline * Address nits * Remove unneccessary convolution * Change wording Co-authored-by: Clyybber <darkmine956@gmail.com>
* add collect with infered init, refs #16078 fixes #14332 (#16089)Antonis Geralis2020-12-031-34/+66
| | | | * changelog * add testcase, fixes #14332
* fix broken => for typed procs with pragmas (#16190)hlaaftana2020-12-011-9/+6
| | | | | | | * fix broken => for typed procs with pragmas * add more sugar tests * add ending quote
* move rest of tests to testament (#16140)flywind2020-11-271-97/+0
| | | | * move rest of tests to testament * Update tests/stdlib/tsums.nim
* follow #11707(add pragmas examples for =>) (#15863)flywind2020-11-061-0/+10
|
* change non-working example to runnableExamples (#15841)flywind2020-11-051-7/+5
|
* fixes #15594 (#15819)flywind2020-11-021-0/+2
|
* dup docs: add an example with `addQuoted` (#15548)Timothee Cour2020-10-131-0/+5
| | | | | * dup docs: add addQuoted example * fixup
* doc(sugar): added description and examples to dup (#15455)Luis Felipe Manfroni2020-10-051-1/+19
|
* Clean out (#15440)Juan Carlos2020-10-011-4/+0
|
* add `enumerate` macro (#15297)Miran2020-09-221-0/+1
| | | | | | | * add `enumerate` macro * address the comments * put `enumerate` in its own module
* std/with support field assign (#14484)slangmgh2020-08-151-0/+26
| | | | | | | | | | | | | | | | | | | | | * std/with support filed assign * add changelog * add support x.dup.with * add example * revert support x.dup.with; add example * update changelog; fix assignment in parameter * Update changelog.md * add example for assignment in parameter * Remove colon style assign Co-authored-by: Clyybber <darkmine956@gmail.com>
* fixes a collect() bug reported on the forum (#15156) [backport:1.2]Andreas Rumpf2020-08-041-0/+10
|
* Revert "Small typo (#15132)" (#15134)Andreas Rumpf2020-07-311-1/+1
| | | This reverts commit 4bf8d38248f40cc0bf5323843a9ea38c5bcc20a8.
* Small typo (#15132)Oliver Daniel2020-07-311-1/+1
| | | The expected output necessarily cannot match the formatted string.
* Fix sugar.dump: It doesn't work correctly with compile time expression (#14580)Tomohiro2020-06-081-1/+1
|
* => supports pragmas & names (+ changed behavior) (#14200)hlaaftana2020-05-031-33/+59
| | | | | | | | | | * => supports pragmas & names (+ changed behavior) (x, y: int) is now parsed as (x: int, y: int) instead of (x: auto, y: int) inside => and ->. * fix pragma check * fixes, use since & LHS of -> supports pragmas
* move since from inclrtl to std/private/since (#14188)hlaaftana2020-05-021-2/+1
| | | | * move since from inclrtl to std/private/since * move since import in system below for HCR
* Add `hashWangYi1` (#13823)c-blake2020-04-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Unwind just the "pseudorandom probing" (whole hash-code-keyed variable stride double hashing) part of recent sets & tables changes (which has still been causing bugs over a month later (e.g., two days ago https://github.com/nim-lang/Nim/issues/13794) as well as still having several "figure this out" implementation question comments in them (see just diffs of this PR). This topic has been discussed in many places: https://github.com/nim-lang/Nim/issues/13393 https://github.com/nim-lang/Nim/pull/13418 https://github.com/nim-lang/Nim/pull/13440 https://github.com/nim-lang/Nim/issues/13794 Alternative/non-mandatory stronger integer hashes (or vice-versa opt-in identity hashes) are a better solution that is more general (no illusion of one hard-coded sequence solving all problems) while retaining the virtues of linear probing such as cache obliviousness and age-less tables under delete-heavy workloads (still untested after a month of this change). The only real solution for truly adversarial keys is a hash keyed off of data unobservable to attackers. That all fits better with a few families of user-pluggable/define-switchable hashes which can be provided in a separate PR more about `hashes.nim`. This PR carefully preserves the better (but still hard coded!) probing of the `intsets` and other recent fixes like `move` annotations, hash order invariant tests, `intsets.missingOrExcl` fixing, and the move of `rightSize` into `hashcommon.nim`. * Fix `data.len` -> `dataLen` problem. * This is an alternate resolution to https://github.com/nim-lang/Nim/issues/13393 (which arguably could be resolved outside the stdlib). Add version1 of Wang Yi's hash specialized to 8 byte integers. This gives simple help to users having trouble with overly colliding hash(key)s. I.e., A) `import hashes; proc hash(x: myInt): Hash = hashWangYi1(int(x))` in the instantiation context of a `HashSet` or `Table` or B) more globally, compile with `nim c -d:hashWangYi1`. No hash can be all things to all use cases, but this one is A) vetted to scramble well by the SMHasher test suite (a necessarily limited but far more thorough test than prior proposals here), B) only a few ALU ops on many common CPUs, and C) possesses an easy via "grade school multi-digit multiplication" fall back for weaker deployment contexts. Some people might want to stampede ahead unbridled, but my view is that a good plan is to A) include this in the stdlib for a release or three to let people try it on various key sets nim-core could realistically never access/test (maybe mentioning it in the changelog so people actually try it out), B) have them report problems (if any), C) if all seems good, make the stdlib more novice friendly by adding `hashIdentity(x)=x` and changing the default `hash() = hashWangYi1` with some `when defined` rearranging so users can `-d:hashIdentity` if they want the old behavior back. This plan is compatible with any number of competing integer hashes if people want to add them. I would strongly recommend they all *at least* pass the SMHasher suite since the idea here is to become more friendly to novices who do not generally understand hashing failure modes. * Re-organize to work around `when nimvm` limitations; Add some tests; Add a changelog.md entry. * Add less than 64-bit CPU when fork. * Fix decl instead of call typo. * First attempt at fixing range error on 32-bit platforms; Still do the arithmetic in doubled up 64-bit, but truncate the hash to the lower 32-bits, but then still return `uint64` to be the same. So, type correct but truncated hash value. Update `thashes.nim` as well. * A second try at making 32-bit mode CI work. * Use a more systematic identifier convention than Wang Yi's code. * Fix test that was wrong for as long as `toHashSet` used `rightSize` (a very long time, I think). `$a`/`$b` depend on iteration order which varies with table range reduced hash order which varies with range for some `hash()`. With 3 elements, 3!=6 is small and we've just gotten lucky with past experimental `hash()` changes. An alternate fix here would be to not stringify but use the HashSet operators, but it is not clear that doesn't alter the "spirit" of the test. * Fix another stringified test depending upon hash order. * Oops - revert the string-keyed test. * Fix another stringify test depending on hash order. * Add a better than always zero `defined(js)` branch. * It turns out to be easy to just work all in `BigInt` inside JS and thus guarantee the same low order bits of output hashes (for `isSafeInteger` input numbers). Since `hashWangYi1` output bits are equally random in all their bits, this means that tables will be safely scrambled for table sizes up to 2**32 or 4 gigaentries which is probably fine, as long as the integer keys are all < 2**53 (also likely fine). (I'm unsure why the infidelity with C/C++ back ends cut off is 32, not 53 bits.) Since HashSet & Table only use the low order bits, a quick corollary of this is that `$` on most int-keyed sets/tables will be the same in all the various back ends which seems a nice-to-have trait. * These string hash tests fail for me locally. Maybe this is what causes the CI hang for testament pcat collections? * Oops. That failure was from me manually patching string hash in hashes. Revert. * Import more test improvements from https://github.com/nim-lang/Nim/pull/13410 * Fix bug where I swapped order when reverting the test. Ack. * Oh, just accept either order like more and more hash tests. * Iterate in the same order. * `return` inside `emit` made us skip `popFrame` causing weird troubles. * Oops - do Windows branch also. * `nimV1hash` -> multiply-mnemonic, type-scoped `nimIntHash1` (mnemonic resolutions are "1 == identity", 1 for Nim Version 1, 1 for first/simplest/fastest in a series of possibilities. Should be very easy to remember.) * Re-organize `when nimvm` logic to be a strict `when`-`else`. * Merge other changes. * Lift constants to a common area. * Fall back to identity hash when `BigInt` is unavailable. * Increase timeout slightly (probably just real-time perturbation of CI system performance).
* fixes a bug for 'dup' and 'with'; they can now handle nested statement lists ↵Araq2020-03-171-8/+1
| | | | that can result from macros
* added operateOn to sugar.nim to give Nim the chaining mechanism it de… ↵Andreas Rumpf2020-02-261-28/+38
| | | | | | | | (#13092) * implemented the with stdlib module as specified in https://github.com/nim-lang/RFCs/issues/193 * change sugar.outplace to sugar.dup according to https://github.com/nim-lang/RFCs/issues/193 * changelog update
* capture macro now accepts variables of different types (#13356)Clyybber2020-02-151-3/+5
| | | | | | | | | | * Capture macro can now accept variables of different types * Add test * Update examples * Use let instead of var
* Fix capture for object types (#13315)Clyybber2020-02-021-1/+1
| | | | | | * Fix capture for object|tuple|... types * Add test case
* Tiny since cleanup (#13286)Clyybber2020-01-281-116/+116
|
* distinctBase type trait for distinct types (#13031)cooldome2020-01-081-20/+3
|
* fixes #12874 (#12890)Andreas Rumpf2019-12-131-8/+42
| | | | | | * fixes #12874 * fixes introduced regressions
* introduce capture macro (#12712)Judd2019-12-101-0/+26
| | | | capture works for more cases than `closureScope`.
* [backport] Fix style issues in lib/, tools/, and testament/. Fixes #12687. ↵3n-k12019-11-281-1/+1
| | | | (#12754)
* delete list comprehension (#12392)Arne Döring2019-11-221-58/+0
| | | The `lc` macro is now part of `graveyard` repository.
* add collect macro (#12708)b3liever2019-11-221-0/+97
| | | | | | * add collect macro * Add to changelog
* Implemented outplace differently (#12599)Clyybber2019-11-091-0/+45
| | | | | * implemented sugar.outplace; refs #12550 * Different approach, allows for chaining
* Refactor json macro (#12391)Arne Döring2019-10-171-1/+0
| | | | | | | | * closes #12316 * make tjsonmacro work at js target * closes #12289 * closes #11988 * also fixed gdb related stuff
* deprecated list comprehension (#10636)Arne Döring2019-02-131-3/+4
|