Re: miscellaneous array questions...

2020-07-20 Thread Ali Çehreli via Digitalmars-d-learn

On 7/20/20 8:16 PM, a...@a.com wrote:

>> 3) Lastly, In the following code snippet, is arrayA and arrayB both
>> allocated on the stack?

arrayA is allocated on thread-local storage and lives as long as the 
program is active. I guess a final interaction with it can be in a 
'static ~this()' or a 'shared static ~this()' block.


Note that this is different from e.g. C++: In that language, arrayA 
would be a "global" variable and there would be a single instance of it. 
In D, there will be as many arrayA variables as there are active 
threads. (One thread's modification to its own arrayA is not seen by 
other threads.)


arrayB is allocated on the stack and lives as long as the scope that it 
is defined inside. That scope is main's body in your code.


> And how does their scopes and/or lifetimes
>> differ?
>>
>>  module1 =
>> int[100] arrayA;
>> void main()
>> {
>> int[100] arrayB;
>> // ...
>> }
>>  module1 =

Ali



Re: miscellaneous array questions...

2020-07-20 Thread a--- via Digitalmars-d-learn

On Monday, 20 July 2020 at 22:05:35 UTC, WhatMeWorry wrote:

1) The D Language Reference says:

"There are four kinds of arrays..." with the first example being
"type* Pointers to data"  and "int* p;  etc.

At the risk of sounding overly nitpicky, isn't a pointer to an 
integer simply a pointer to an integer?  How does that pertain 
to an array?



2) "The total size of a static array cannot exceed 16Mb" What 
limits this? And with modern systems of 16GB and 32GB, isn't 
16Mb excessively small?   (an aside: shouldn't that be 16MB in 
the reference instead of 16Mb? that is, Doesn't b = bits and B 
= bytes)



3) Lastly, In the following code snippet, is arrayA and arrayB 
both allocated on the stack? And how does their scopes and/or 
lifetimes differ?


 module1 =
int[100] arrayA;
void main()
{
int[100] arrayB;
// ...
}
 module1 =


1) Pointers can be used as arrays with the [] operator, int* p = 
arrayA.ptr; assert(*(p + 99) == p[99]); should access the same 
element.
http://ddili.org/ders/d.en/pointers.html ("Using pointers with 
the array indexing operator []")
2) I've encountered this problem too, it's arbitrary AFAIK but it 
can be circumvented with dynamic arrays.


Re: How Install and Configure DCD (D Completion Daemon) on Sublime Text?

2020-07-20 Thread aberba via Digitalmars-d-learn

On Monday, 20 July 2020 at 18:08:02 UTC, Marcone wrote:
How Install and Configure DCD (D Completion Daemon) on Sublime 
Text?

I need auto complete for the Dlang in Sublime Text.


Recently tried sublime myself for D since its quite lightweight 
compared to VS code for when I need to write something quick. 
Turns out most of the packages are outdated as everyone moved 
from it to something else...VS Code.


See https://wiki.dlang.org/IDEs if you want alternatives.


Re: std.process - avoid interaction with parent shell

2020-07-20 Thread FreeSlave via Digitalmars-d-learn
On Monday, 20 July 2020 at 20:55:52 UTC, Steven Schveighoffer 
wrote:


I don't want any user interaction. Occasionally, I get a 
repository that no longer exists (404). Then git comes up and 
asks for a username/password. I want it to just fail. 
Apparently git has no option to be non-interactive, it 
supposedly checks stdin to see if it's a tty, and only errors 
if it's not.



-Steve


Try setting GIT_TERMINAL_PROMPT=0 as an environment variable.


miscellaneous array questions...

2020-07-20 Thread WhatMeWorry via Digitalmars-d-learn

1) The D Language Reference says:

"There are four kinds of arrays..." with the first example being
"type* Pointers to data"  and "int* p;  etc.

At the risk of sounding overly nitpicky, isn't a pointer to an 
integer simply a pointer to an integer?  How does that pertain to 
an array?



2) "The total size of a static array cannot exceed 16Mb" What 
limits this? And with modern systems of 16GB and 32GB, isn't 16Mb 
excessively small?   (an aside: shouldn't that be 16MB in the 
reference instead of 16Mb? that is, Doesn't b = bits and B = 
bytes)



3) Lastly, In the following code snippet, is arrayA and arrayB 
both allocated on the stack? And how does their scopes and/or 
lifetimes differ?


 module1 =
int[100] arrayA;
void main()
{
int[100] arrayB;
// ...
}
 module1 =



Re: std.process - avoid interaction with parent shell

2020-07-20 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 20 July 2020 at 20:55:52 UTC, Steven Schveighoffer 
wrote:
I tried redirecting /dev/null to stdin when executing my 
application (and I assumed that would pass onto the process 
child), but it still asks. What am I doing wrong?


Generically, I think you want to detach the program from the 
current terminal (as well as doing the above). I think setsid can 
be used for this purpose.


Specifically, checking git's source code, I see that setting the 
environment variable GIT_TERMINAL_PROMPT to 0 will disable 
password prompts.




Re: How spand array for use with functions arguments like tuple?

2020-07-20 Thread Paul Backus via Digitalmars-d-learn

On Monday, 20 July 2020 at 17:59:06 UTC, Marcone wrote:

On Sunday, 19 July 2020 at 23:05:45 UTC, Marcone wrote:

How spand array for use with functions arguments like tuple?


expand*


If the array is a compile-time constant, you can use aliasSeqOf 
[1]. Otherwise, you can't.


[1] http://dpldocs.info/experimental-docs/std.meta.aliasSeqOf.html


Re: std.process - avoid interaction with parent shell

2020-07-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 July 2020 at 21:44:31 UTC, Steven Schveighoffer 
wrote:


I think you might be right. I don't know how it's accessing my 
terminal, but clearly it can keep doing so even without any 
handles open.


Probably /dev/tty


Re: std.process - avoid interaction with parent shell

2020-07-20 Thread Steven Schveighoffer via Digitalmars-d-learn

On 7/20/20 5:24 PM, H. S. Teoh wrote:

On Mon, Jul 20, 2020 at 04:55:52PM -0400, Steven Schveighoffer via 
Digitalmars-d-learn wrote:

I am doing some scripting via D, and using std.process.execute to git
clone things.

I don't want any user interaction. Occasionally, I get a repository
that no longer exists (404). Then git comes up and asks for a
username/password. I want it to just fail. Apparently git has no
option to be non-interactive, it supposedly checks stdin to see if
it's a tty, and only errors if it's not.


Try --no-pager perhaps?  Not sure if that would help, since this isn't
technically a pager that's prompting you.

Another way is to take a look at std.process.execute's implementation. I
believe it's just a wrapper around spawnProcess. What you want is to
adapt that implementation so that it closes stdin before fork-n-exec'ing
git; that should stop any prompts.


I ran the git command from the shell directly with < /dev/null and it 
still can ask for username/password. I don't know if it's possible to 
prevent it.




One thing to be aware of is that it may not necessarily be git itself
that's prompting you; it could be a helper program like a password
manager that creates the prompt. In that case you probably have to find
out what it is, and disable it somehow (usually by overriding some
environment variable that gets passed to the git child process).


I think you might be right. I don't know how it's accessing my terminal, 
but clearly it can keep doing so even without any handles open. I'm even 
using ctrl-D and it continues to come up with prompts and wait for input.


I was able to solve it by backgrounding the process, and then quitting 
the parent shell, then it had no option but to error ;)


I'm still interested in knowing how this works, if anyone knows. 
Searching for things like "how does git access my terminal when I closed 
stdin" doesn't give me much information.


-Steve


Re: std.process - avoid interaction with parent shell

2020-07-20 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 20, 2020 at 04:55:52PM -0400, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> I am doing some scripting via D, and using std.process.execute to git
> clone things.
> 
> I don't want any user interaction. Occasionally, I get a repository
> that no longer exists (404). Then git comes up and asks for a
> username/password. I want it to just fail. Apparently git has no
> option to be non-interactive, it supposedly checks stdin to see if
> it's a tty, and only errors if it's not.

Try --no-pager perhaps?  Not sure if that would help, since this isn't
technically a pager that's prompting you.

Another way is to take a look at std.process.execute's implementation. I
believe it's just a wrapper around spawnProcess. What you want is to
adapt that implementation so that it closes stdin before fork-n-exec'ing
git; that should stop any prompts.

One thing to be aware of is that it may not necessarily be git itself
that's prompting you; it could be a helper program like a password
manager that creates the prompt. In that case you probably have to find
out what it is, and disable it somehow (usually by overriding some
environment variable that gets passed to the git child process).


T

-- 
Ph.D. = Permanent head Damage


std.process - avoid interaction with parent shell

2020-07-20 Thread Steven Schveighoffer via Digitalmars-d-learn
I am doing some scripting via D, and using std.process.execute to git 
clone things.


I don't want any user interaction. Occasionally, I get a repository that 
no longer exists (404). Then git comes up and asks for a 
username/password. I want it to just fail. Apparently git has no option 
to be non-interactive, it supposedly checks stdin to see if it's a tty, 
and only errors if it's not.


I tried redirecting /dev/null to stdin when executing my application 
(and I assumed that would pass onto the process child), but it still 
asks. What am I doing wrong?


e.g.:

myapp < /dev/null
Username for 'https://github.com':
Program pauses, waits for my input.

-Steve


Re: What would be the advantage of using D to port some games?

2020-07-20 Thread Laurent Tréguier via Digitalmars-d-learn

On Monday, 20 July 2020 at 19:49:52 UTC, RegeleIONESCU wrote:

Hello!

I was wondering why some game related packages/libraries are 
not being developed anymore or are kind of paused. Fore example 
the last version of derelict-sdl2 is an alpha from May 2018. 
Lack of people to develop it, to take care of it or is kind of 
language focus shift?


The derelict-* packages are being superseded by bindbc-* packages 
as far as I know, so bindbc-sdl is probably what you want now: 
https://code.dlang.org/packages/bindbc-sdl


Re: What would be the advantage of using D to port some games?

2020-07-20 Thread RegeleIONESCU via Digitalmars-d-learn

On Wednesday, 24 June 2020 at 21:14:35 UTC, matheus wrote:

On Wednesday, 24 June 2020 at 19:46:55 UTC, IGotD- wrote:

.


Hello!

I was wondering why some game related packages/libraries are not 
being developed anymore or are kind of paused. Fore example the 
last version of derelict-sdl2 is an alpha from May 2018. Lack of 
people to develop it, to take care of it or is kind of language 
focus shift?


Accurately serializing and deserializing a SysTime in binary format

2020-07-20 Thread Ecstatic Coder via Digitalmars-d-learn
I'm currently implementing a small open source backup tool (dub), 
and therefore I need to accurately store the file modification 
SysTime in binary format, so that I can later load this SysTime 
from the snapshot file to compare it with the current file 
modification SysTime.


Having unfortunately not understood how to do this from the 
SysTime documentation, in despair, I've tried to directly 
serialize the 16 bytes of the SysTime value. This worked fine 
until I call the ".toISOString()" on the deserialized SysTime, 
which inevitably crashes the executable ;)


Anyway, that's not really want I intended to do, as in practice a 
"ulong" already has enough  resolution for that purpose.


So sorry for my ignorance, but I would definitely need some help 
on how to :
- convert a file modification SysTime to a serializable number, 
for instance the number of hectonanoseconds since 1/1/1970 in UTC;
- convert that number back into a SysTime that I can compare to 
the modification SysTime of the same file.


Eric



How Install and Configure DCD (D Completion Daemon) on Sublime Text?

2020-07-20 Thread Marcone via Digitalmars-d-learn
How Install and Configure DCD (D Completion Daemon) on Sublime 
Text?

I need auto complete for the Dlang in Sublime Text.


Re: How spand array for use with functions arguments like tuple?

2020-07-20 Thread Marcone via Digitalmars-d-learn

On Sunday, 19 July 2020 at 23:05:45 UTC, Marcone wrote:

How spand array for use with functions arguments like tuple?


expand*


Re: alias restriction??!

2020-07-20 Thread Carl Sturtivant via Digitalmars-d-learn

On Monday, 20 July 2020 at 17:24:56 UTC, Carl Sturtivant wrote:
Well perhaps you do parse a "constant-offset expression" i.e. 
syntactically dotted with constant indexes, like 
name1.name2[constant].name3 and then later there's a semantic 
check that the "constant-offset expression" involves no 
indirections when an offset into the top level object is 
computed. Then it's treated like any other attribute of a 
struct with a known offset.


Perhaps this could also work for a class at the top with 
recursively embedded structs and value arrays.


Re: alias restriction??!

2020-07-20 Thread Carl Sturtivant via Digitalmars-d-learn
On Sunday, 19 July 2020 at 20:46:19 UTC, Steven Schveighoffer 
wrote:

On 7/19/20 4:21 PM, Carl Sturtivant wrote:


Perhaps what's needed is something more that is less than 
allowing aliases for expressions in the wide sense you suggest 
here.


I agree. Something not yet mentioned is that aliases provide 
direct access to the symbols for the purposes of looking at 
attributes -- something that a wrapper function doesn't provide.


The question is: how do you restrict it to explicit data items 
within a specific aggregate without parsing arbitrary 
expressions?


Well perhaps you do parse a "constant-offset expression" i.e. 
syntactically dotted with constant indexes, like 
name1.name2[constant].name3 and then later there's a semantic 
check that the "constant-offset expression" involves no 
indirections when an offset into the top level object is 
computed. Then it's treated like any other attribute of a struct 
with a known offset.


Re: Is there a compiler option to list all functions executed at compile time when compiling a file?

2020-07-20 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 20 July 2020 at 16:01:53 UTC, blizzard wrote:
I am trying to learn D and knowing when code is run at compile 
time would be good for learning what functions can be used 
without thinking much about performance.


No function is ever run at compile time unless you specifically 
request it with some kind of static context, like top-level in a 
module or class declaration, putting the static keyword on the 
variable, passing it to a !() template argument, or using the 
enum keyword.


Is there a compiler option to list all functions executed at compile time when compiling a file?

2020-07-20 Thread blizzard via Digitalmars-d-learn
I am trying to learn D and knowing when code is run at compile 
time would be good for learning what functions can be used 
without thinking much about performance.


Re: Garbage collection

2020-07-20 Thread James Gray via Digitalmars-d-learn

On Tuesday, 30 June 2020 at 06:16:26 UTC, Kagamin wrote:

On Saturday, 27 June 2020 at 14:49:34 UTC, James Gray wrote:
I have produced something which essentially reproduces my 
problem.


What is the problem? Do you have a leak or you want to know how 
GC works?


I have managed to resolve my problem (which was a memory leak). 
My code uses a large data structure similar to a link list and 
the garbage collector was not collecting it. However,
if I set all the "links" between the nodes in the data structure 
to null it is then collected.


Re: Ada-Style Modulo Integer Types

2020-07-20 Thread Per Nordlöw via Digitalmars-d-learn

On Friday, 22 April 2016 at 19:52:46 UTC, Nordlöw wrote:

On Friday, 22 April 2016 at 17:37:44 UTC, Nordlöw wrote:

Have anybody implement Ada-style modulo types

https://en.wikibooks.org/wiki/Ada_Programming/Types/mod


Here's my first try

https://github.com/nordlow/phobos-next/blob/master/src/modulo.d


Now at

https://github.com/nordlow/phobos-next/blob/69e57fb2eed57d7450d746baa30d9f112d76f527/src/nxt/modulo.d