digitalmars.D.learn - Is inc function part of the library ?
- Alain De Vos (10/10) May 13 2021 I wanted to use the inc function (increment by one) but it is not
- Mike Parker (6/17) May 13 2021 It's not a function. It's an operator:
- Mike Parker (3/7) May 13 2021 In the search bar at the top of the page, enter your search
- Berni44 (3/6) May 13 2021 An alternative to the official documentation is
- Imperatorn (2/13) May 13 2021 Do you mean atomic increment? 🤔
- Alain De Vos (15/15) May 13 2021 Writing an inc function is a fascinating voyage.
- Imperatorn (3/18) May 13 2021 Take a look at
- Alain De Vos (2/2) May 13 2021 Shouldn't the compiler error it is not pure ?
- Adam D. Ruppe (4/5) May 13 2021 pure means it doesn't depend on any mutable info outside its
- kdevel (13/18) May 13 2021 Then D's pure does not match up with WP's definition [1] of pure,
- Adam D. Ruppe (7/9) May 13 2021 Yeah, D's pure is actually useful without being a huge hassle.
- Imperatorn (3/23) May 13 2021 Just fyi:
- kdevel (3/6) May 13 2021 Replied to the wrong post?
- Alain De Vos (3/3) May 13 2021 I have the feeling it is a pragmatic definition of pure. (isClose)
- drug (4/6) May 13 2021 The function is pure. If you call it several times passing the same
I wanted to use the inc function (increment by one) but it is not recognised. So searched google "inc dlang" but that returned nothing informative. Normally I would issue a "grep" in some files to find if a function exists. Is "inc" part as function of the library someonewhere and more important, a practical question, how can I do an extensive search in the library to functions when i know more or less their name , but don't know their exact place as module or package.
May 13 2021
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:I wanted to use the inc function (increment by one) but it is not recognised. So searched google "inc dlang" but that returned nothing informative. Normally I would issue a "grep" in some files to find if a function exists. Is "inc" part as function of the library someonewhere and more important, a practical question, how can I do an extensive search in the library to functions when i know more or less their name , but don't know their exact place as module or package.It's not a function. It's an operator: ```d int i = 10; ++i; ```
May 13 2021
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:important, a practical question, how can I do an extensive search in the library to functions when i know more or less their name , but don't know their exact place as module or package.In the search bar at the top of the page, enter your search term(s), select "Library" from the drop down.
May 13 2021
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:[...] how can I do an extensive search in the library to functions when i know more or less their name , but don't know their exact place as module or package.An alternative to the official documentation is [dpldocs](http://dpldocs.info/experimental-docs/dpldocs.home.html) from Adam. It is inofficial (and sometimes a little bit outdated), but it has a different search algorithm and often points you to places, you may have missed using the official documentation.
May 13 2021
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:I wanted to use the inc function (increment by one) but it is not recognised. So searched google "inc dlang" but that returned nothing informative. Normally I would issue a "grep" in some files to find if a function exists. Is "inc" part as function of the library someonewhere and more important, a practical question, how can I do an extensive search in the library to functions when i know more or less their name , but don't know their exact place as module or package.Do you mean atomic increment? 🤔
May 13 2021
Writing an inc function is a fascinating voyage. A function on module level did not worked because it had no this context. This works: ``` void main(){ ref int inc2(ref int x) return pure nothrow nogc safe{ ++x; return x; } int x=0; inc2(inc2(x)); writeln(x); ``` The thing is i don't find the function pure.
May 13 2021
On Thursday, 13 May 2021 at 12:56:49 UTC, Alain De Vos wrote:Writing an inc function is a fascinating voyage. A function on module level did not worked because it had no this context. This works: ``` void main(){ ref int inc2(ref int x) return pure nothrow nogc safe{ ++x; return x; } int x=0; inc2(inc2(x)); writeln(x); ``` The thing is i don't find the function pure.Take a look at https://dlang.org/phobos/core_atomic.html#.atomicOp
May 13 2021
Shouldn't the compiler error it is not pure ? Or have I a wrong understanding of pure or the compiler.
May 13 2021
On Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:Or have I a wrong understanding of pure or the compiler.pure means it doesn't depend on any mutable info outside its arguments. You are only working on the arguments there so it is ok.
May 13 2021
On Thursday, 13 May 2021 at 13:45:50 UTC, Adam D. Ruppe wrote:On Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:Then D's pure does not match up with WP's definition [1] of pure, at least not 2. The function application has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or input/output streams). WP quotes Bartosz Milewski: 2. A function has no side effects. Calling a function once is the same as calling it twice and discarding the result of the first call. [1] https://en.wikipedia.org/wiki/Pure_functionOr have I a wrong understanding of pure or the compiler.pure means it doesn't depend on any mutable info outside its arguments. You are only working on the arguments there so it is ok.
May 13 2021
On Thursday, 13 May 2021 at 17:48:34 UTC, kdevel wrote:Then D's pure does not match up with WP's definition [1] of pure, at least notYeah, D's pure is actually useful without being a huge hassle. Makes it into a useful building block that can be used inside other scenarios than the purely pure does. If you want immutable, that's a separate thing in D. You can use it on its own, or combine it with D pure to get to the full formal pure definition.
May 13 2021
On Thursday, 13 May 2021 at 17:48:34 UTC, kdevel wrote:On Thursday, 13 May 2021 at 13:45:50 UTC, Adam D. Ruppe wrote:Just fyi: https://dlang.org/articles/safed.htmlOn Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:Then D's pure does not match up with WP's definition [1] of pure, at least not 2. The function application has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or input/output streams). WP quotes Bartosz Milewski: 2. A function has no side effects. Calling a function once is the same as calling it twice and discarding the result of the first call. [1] https://en.wikipedia.org/wiki/Pure_function[...]pure means it doesn't depend on any mutable info outside its arguments. You are only working on the arguments there so it is ok.
May 13 2021
On Thursday, 13 May 2021 at 21:41:48 UTC, Imperatorn wrote: [...]Replied to the wrong post?[1] https://en.wikipedia.org/wiki/Pure_functionJust fyi: https://dlang.org/articles/safed.html
May 13 2021
I have the feeling it is a pragmatic definition of pure. (isClose) Although a compiler message , which does not even be a warning, is always a nice to have.
May 13 2021
13.05.2021 16:30, Alain De Vos пишет:Shouldn't the compiler error it is not pure ? Or have I a wrong understanding of pure or the compiler.The function is pure. If you call it several times passing the same argument it will return the same result. https://run.dlang.io/is/futqjP
May 13 2021