Jump to page: 1 2
Thread overview
Is inc function part of the library ?
May 13
Berni44
May 13
kdevel
May 13
kdevel
May 13
drug
May 13

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

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:

int i = 10;
++i;
May 13

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

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

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

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

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

Shouldn't the compiler error it is not pure ?
Or have I a wrong understanding of pure or the compiler.

May 13

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
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
« First   ‹ Prev
1 2