abs(int8) returns int8?

2020-09-23 Thread marusu
I got a thought that throwing overflow exception is one of the right way. Thanks.

abs(int8) returns int8?

2020-09-23 Thread marusu
Thank you. I understood it is common spec for many languages and explicit casting is required for Nim.

Notification about new replies and @{name} etc

2020-09-23 Thread Araq
As far as I know that is indeed the case. Would be a really nice feature to add to the forum. :-)

abs(int8) returns int8?

2020-09-23 Thread Araq
That problem exists for all integer types, why would `int8` be special.

abs(int8) returns int8?

2020-09-23 Thread cdunn2001
Good question! That's why C, C++, and C# all return the same type as the argument. If you write your own library: proc (int8 x): uint8 = if x > 0: return x else: return (

abs(int8) returns int8?

2020-09-23 Thread leorize
Yep. When that happens, an exception will be thrown at runtime. Below is a small snippet that demonstrates the behaviour. var x: int8 # Set the variable like this so the compiler don't # block the program from compiling. x = -128 echo abs(x) # throw overflow because 1

abs(int8) returns int8?

2020-09-23 Thread marusu
According to the document, abs(int8) returns int8 but in the case of -128, abs(-128)=128 cannot stored into int8, right?

ARC/ORC cpu intensive loop bug?

2020-09-23 Thread cdunn2001
@mratsim, in the code you linked, what does this do? proc vec_zero(ret: pointer, num: csize_t) {.importc, exportc, header: srcPath/"vect.h", nodecl.} Run

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread pietroppeter
btw, your example will work if you qualify parameter check > > import sugar, options > > proc find*[T](list: openarray[T], check: (T) -> bool): Option[T] = > for v in list: > if check(v): return v.some > T.none > > ec

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread pietroppeter
> I was wondering if there's a way to query the regex object for the string it > was created from, but I didn't find anything in the re documentation. I do not think it is possible to recover original pattern in `re`, since `Regex` object only contains pointer to pcre objects:

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread sschwarzer
In the first form the `re` is applied after the string literal is already parsed as a "normal" (non-raw) string `\s`. In the second form the string literal is parsed as a raw string `\\s` (see @Hlaaftana 's link). For what it's worth, I was wondering if there's a way to query the regex object f

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread cblake
Python introduced raw string literals back in late 1997. Maybe some other prog.lang had them earlier? Even [the C++11 standard](https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial/) picked them up. Nim's ideas along these lines are not unique (well, maybe more general

how does `nimble develop` work?

2020-09-23 Thread shashlick
I don't agree with that - once a package is in develop mode, the version is treated as #head. It is up to the user to keep it up to date since they are actively developing that package. The package version is irrelevant after that point. Any package that requires that package will get #head unle

how does `nimble develop` work?

2020-09-23 Thread timothee
see , there's a logic error with handling of nimble develop packages nimble build should complain when it requires `X >=N` and X has nimble develop at version < N

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread Hlaaftana
https://nim-lang.org/docs/manual.html#lexical-analysis-generalized-raw-string-literals

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
Also, the current `system.find` is close to `strutils.find` in its signature as well as what `doc/apis.rst` says. You could/maybe should also rename your `find` to `findOption`, `optionFind` or something.

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread Araq
No, that's why we're in version 1 land. We stopped moving stuff around pointlessly. To call your find use the `mymodule.find` syntax or use `import system except find`.

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread alexeypetrushin
Can we consider maybe renaming `find` to `find_index` and moving to `sequtils`? And maybe limit its scope somehow, as currently it's impossible to override it and there are lots of methods that can use `find` name, like: sequence.find((v) => v == 2) db.collection("posts").find(i

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
Also, looks like it was added in Summer 2016 & noted in [the 0.15 release](https://nim-lang.org/blog/2016/09/30/version-0150-released.html).

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
It decidedly _can_ break stdlib/other code instantiated in context (as per my `auto` mention) or create situations of extreme confusion. An example may be defining `==` to mean what `!=` usually does. ;-) There's probably a way in German to create a word meaning "possible but tricky, with hard t

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread cblake
The need for only one backslash in the second case { `split(re"\s")` is the equivalent } is a feature not a bug. Anything can be confusing. :-/

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
Nim is "re-definable" to a very unusual degree. That can confuse some people, yet other people have such re-definability as a high priority. I'm unsure what the manual/doc comment should say..Probably move the "; it must not" to after the "don't call some other module `system`" and soften the ex

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
There is a test for it in `tests/modules/texplicit_system_import.nim`. I haven't looked into the VC/github history as to how reliable it is. If you really hate everything from system you can do this: from system import nil import options proc find*[T](list: system.open

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread Stefan_Salewski
Some years ago I read that we should never import module system directly. Has that been fixed?

stdlib pattern matching feedback

2020-09-23 Thread haxscramper_
Yes. I adapted case object idea from patty and some syntax elements from gara. ast-pattern-matching only supports nim node matching so it is not really applicable in general case of pattern matching.

Notification about new replies and @{name} etc

2020-09-23 Thread Rooibos
Hi, This is a question about the usage of the Nim forum. In the present forum site, is it OK to assume that there is no "automatic notification" system about new replies and @{username} etc (e.g., via registered e-mail or some "signal" on the user icon) at the moment and so I should check threa

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread Stefan_Salewski
> Each module implicitly imports the System module; it must not be listed > explicitly. For me and google the translation seems to be "es darf nicht", that is it is forbidden.

My First Program With Nim! It's a Password Generator!

2020-09-23 Thread mratsim
> The stdlib cannot keep up with crypto Anything less than 10 years old is viewed with suspicion and then you need some extra years to standardize.

Same Regular Expression constructed in slightly different ways produces different results

2020-09-23 Thread alexeypetrushin
This code would produce different results. I guess it's related to how string is escaped, it's confusing. import re echo "a b".split(re("\\s")) echo "a b".split(re"\\s") Run Result @["a", "b"] @["a b"] Run

stdlib pattern matching feedback

2020-09-23 Thread spip
Have you had a look at the syntax proposed by the different [pattern matching modules](https://github.com/nim-lang/Nim/wiki/Curated-Packages#language)?

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread cblake
Try: import system except find Run before your other imports?

stdlib pattern matching feedback

2020-09-23 Thread haxscramper_
I and @alehander42 started working on adding pattern matching in stdlib. Right now we at ideas brainstorming stage - what is needed, syntax, potential escape hatches for user-defined behavior etc. There have been some discussion in RFC on github - [link](https://github.com/nim-lang/RFCs/issues/

Why can't I define custom `find` proc and override one from the system module?

2020-09-23 Thread alexeypetrushin
It conflicts with the built-in `find` in system, how can I override it? import sugar, options proc find*[T](list: openarray[T], check: (T) -> bool): Option[T] = for v in list: if check(v): return v.some T.none echo @[1, 2, 3].find((v) => v == 2)

My First Program With Nim! It's a Password Generator!

2020-09-23 Thread Araq
The stdlib cannot keep up with crypto, or anything else for that matter. :-)

how to create a table of functions ?

2020-09-23 Thread Araq
> Why not a simple case/of ? Because i want to be able to have a help rule in > the nimscript, by listing the keys of the table (i separate list, i could add > a parameter in the case/of , and forget to add it in the help text. Anyway > that would dup things). I'd use a simple case+of plus a ma

how to create a table of functions ?

2020-09-23 Thread jseb
Thank you, it works now ! Here is the complete nimscript. May be it can be helpful for someone else: # appeler avec « nim release shooter » , « nim debug shooter » etc… import tables var target_release="shooter.elf" var debug_release="shooterd.elf" var want_

how to create a table of functions ?

2020-09-23 Thread cblake
Change `proc()` to `proc() {.closure.}` in both the `type` section and at the definition site.

how to create a table of functions ?

2020-09-23 Thread jseb
Hello, The goal is to parse parameters received by a nimscript used for compilation, and then modify accordingly the setup. I use a table for that, with key => parameter and value => lambda proc which modfy the setup. Why not a simple case/of ? Because i want to be able to have a `help` rule i

ARC/ORC cpu intensive loop bug?

2020-09-23 Thread mratsim
Note that I ended wrapping this assembly SHA256 implementation anyway Benchmarks show that it's 15x faster than nimcrypto.sha2 on my machine