Re: DUB mysql-native

2019-10-08 Thread Vino via Digitalmars-d-learn

On Tuesday, 8 October 2019 at 11:26:24 UTC, Daniel Kozak wrote:
On Tue, Oct 8, 2019 at 1:15 PM Daniel Kozak  
wrote:

...
It is known issue, you can not use mysql-native right now with
anything else than libevent

https://github.com/mysql-d/mysql-native/issues/199

Or you can just remove

"subConfigurations": {
"vibe-d:core": "libevent"
},

from ~/.dub/packages/mysql-native-2.3.0/mysql-native/dub.json


https://github.com/mysql-d/mysql-native/commit/ec851956e579bab8d00b1ae89a5344a2babce2e3


Hi Daniel,

   As stated I have removed those line and ran the below command

dub build --force - No issue
dub test - failed with the below error

dub build --force
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.

dub 1.17.0: building configuration "library"...
Serializing composite type BuildRequirements which has no 
serializable fields
Serializing composite type BuildOptions which has no serializable 
fields

taggedalgebraic 0.11.4: building configuration "library"...
eventcore 0.8.46: building configuration "winapi"...
stdx-allocator 2.77.5: building configuration "library"...
vibe-core 1.7.0: building configuration "winapi"...
vibe-d:utils 0.8.6: building configuration "library"...
vibe-d:data 0.8.6: building configuration "library"...
mysql-native 2.3.0: building configuration "library"...
..\..\..\AppData\Local\dub\packages\mysql-native-2.3.0\mysql-native\source\mysql\connection.d(1192,27):
 Deprecation: function std.typecons.Nullable!(PreparedServerInfo).Nullable.get_ 
is deprecated - Implicit conversion with alias Nullable.get this will be 
removed after 2.096. Please use .get explicitly.
..\..\..\AppData\Local\dub\packages\mysql-native-2.3.0\mysql-native\source\mysql\pool.d(115,13):
 Deprecation: constructor 
vibe.core.connectionpool.ConnectionPool!(Connection).ConnectionPool.this is 
deprecated - Use an @safe callback instead
..\..\..\AppData\Local\dub\packages\mysql-native-2.3.0\mysql-native\source\mysql\pool.d(361,27):
 Deprecation: function std.typecons.Nullable!(PreparedInfo).Nullable.get_ is 
deprecated - Implicit conversion with alias Nullable.get this will be removed 
after 2.096. Please use .get explicitly.
..\..\..\AppData\Local\dub\packages\mysql-native-2.3.0\mysql-native\source\mysql\pool.d(378,26):
 Deprecation: function std.typecons.Nullable!(PreparedInfo).Nullable.get_ is 
deprecated - Implicit conversion with alias Nullable.get this will be removed 
after 2.096. Please use .get explicitly.
..\..\..\AppData\Local\dub\packages\mysql-native-2.3.0\mysql-native\source\mysql\protocol\comms.d(418,3):
 Deprecation: foreach: loop index implicitly converted from size_t to ushort
hub ~master: building configuration "application"...
Linking...
Copying files for dub...

dub test
No source files found in configuration 'library'. Falling back to 
"dub -b unittest".
Performing "unittest" build using C:\D\dmd2\windows\bin\dmd.exe 
for x86_64.

dub 1.17.0: target for configuration "library" is up to date.
taggedalgebraic 0.11.4: target for configuration "library" is up 
to date.

eventcore 0.8.46: target for configuration "winapi" is up to date.
stdx-allocator 2.77.5: target for configuration "library" is up 
to date.

vibe-core 1.7.0: target for configuration "winapi" is up to date.
vibe-d:utils 0.8.6: target for configuration "library" is up to 
date.
vibe-d:data 0.8.6: target for configuration "library" is up to 
date.
mysql-native 2.3.0: target for configuration "library" is up to 
date.

hub ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Copying files for dub...
Running .\hub.exe
Program exited with code -1073741515

Error:
The code execution cannot proceed because msvcr100.dll was not 
found. Reinstalling the program  may fix this problem.


Execution HUB/source/app.d
import std.array : array;
import std.variant;
import mysql;
import std.stdio;

void main(string[] args)
{
	auto connectionStr = 
"host=dev.server1.com;port=3910;user=testuser;pwd=#;db=test";

if(args.length > 1)
connectionStr = args[1];
Connection conn = new Connection(connectionStr);
scope(exit) conn.close();

	ResultRange range = conn.query("SELECT host_name FROM 
`devservers`");

Row row = range.front;
Variant host_name = row[0];
writeln(host_name);
}

Code Execution
cd HUB/source
rdmd app.d

app.d(3): Error: module `mysql` is in file 'mysql.d' which cannot 
be read

import path[0] = .
import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", 
"app.d", "-I."]


From,
Vino.B



DUB mysql-native

2019-10-08 Thread Vino via Digitalmars-d-learn

Hi All,

 Please correct me what is wrong as I am not able to build a 
project using dub getting the error "Could not resolve 
configuration for package hub".


dub init HUB
C:\Users\userp\Downloads\testhub>dub init HUB
Package recipe format (sdl/json) [json]:
Name [hub]:
Description [A minimal D application.]:
Author name [userp]:
License [proprietary]:
Copyright string [Copyright © 2019, userp]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in 
'C:\Users\userp\Downloads\testhub\HUB'.

Package successfully created in HUB

cd HUB
dub add dub
Adding dependency dub ~>1.17.0

dub add mysql-native
Adding dependency mysql-native ~>2.3.0

dub build
Fetching libevent 2.0.2+2.0.16 (getting selected version)...
Fetching vibe-core 1.7.0 (getting selected version)...
Fetching taggedalgebraic 0.11.4 (getting selected version)...
Fetching dub 1.17.0 (getting selected version)...
Fetching vibe-d 0.8.6 (getting selected version)...
Fetching memutils 0.4.13 (getting selected version)...
Fetching stdx-allocator 2.77.5 (getting selected version)...
Fetching unit-threaded 0.7.55 (getting selected version)...
Fetching eventcore 0.8.46 (getting selected version)...
Fetching libasync 0.8.4 (getting selected version)...
Fetching mysql-native 2.3.0 (getting selected version)...
Fetching botan-math 1.0.3 (getting selected version)...
Fetching botan 1.12.10 (getting selected version)...
Fetching diet-ng 1.6.0 (getting selected version)...
Fetching openssl 1.1.6+1.0.1g (getting selected version)...
Fetching mir-linux-kernel 1.0.1 (getting selected version)...
Could not resolve configuration for package hub

From,
Vino.B


Deleting a file with extsion *.FIFO in Windows

2018-05-24 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help on how to delete a file which has the 
extension .fifo (.javast.fifo) in Windows.


From,
Vino.B


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 15:16:23 UTC, wjoe wrote:

On Friday, 4 May 2018 at 14:24:36 UTC, Vino wrote:

On Friday, 4 May 2018 at 14:02:24 UTC, Jonathan M Davis wrote:
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn 
wrote:

[...]


Linux does not keep track of the creation time of a file. So, 
it will not work to have a program on Linux ask a file how 
long it's been since the file was created. If you want that 
information, you'll have to store it elsewhere somehow (and 
that generally only works if you created the file in the 
first place).


The modification time of the file is the time that the file 
was last changed (which would be the creation time if it were 
only ever written to once, but in the general case, it has no 
relation to the creation time at all). So, you could use 
std.file.timeLastModified to find out if a file has been 
changed within the last x number of days, but there is no way 
to find out the creation time of a file by asking the 
filesystem.


- Jonathan M Davis


Hi Jonathan,

  Thank you,  i got your point from the other forum topic 
which was raised by me earlier, hence decided to use 
modification time, the request is on how and the best approach 
to port the code from windows to Linux eg program below


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a 
=> a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined 
identifier timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined 
identifier timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B


Unlike NTFS for Windows there's a plethora of different file 
systems available to use for Linux, one of which doesn't even 
support deletion of files. You also have to keep in mind that 
even if the same file system is used, there is no guarantee 
that you have the same set of metadata available for a mount 
point each and every time.
Consider a file system that's mounted with the 'noatime' 
option, for instance, which doesn't log access times.


As far as I understand you are globing files, check times and 
then act upon that.
If I were to port this to Linux, or any other OS for that 
matter, I wouldn't depend on a feature of an OS.
Instead, since you have to look at a file either way to get the 
meta data (which you query with the stat family of functions), 
I would build my own database or cache with that information.
Glob the directory and add files not yet present with the 
current date (and any other meta data you might need).
Then query all the files of interest and do whatever you want 
to do with them and remove the entry.


Downside is you have possibly another dependency. On the plus 
side you could easily query all files older than X days or 
whatever with a single select and batch process them.


Hi Wjoe,

  Thank you very much, but what i am expecting is something like 
OS switch, based of OS type switch the funciton eg:


If OS is windows use the funciton timeCreated else if the OS is 
linux use the function timeLastAccessed in the below example 
program, something similar as stated in the link


https://dlang.org/spec/declaration.html#alias

Eg1:
version (Win32)
{
alias myfoo = win32.foo;
}
version (linux)
{
alias myfoo = linux.bar;
}



auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;


version (Windows) {  alias sTimeStamp = 
std.file.DirEntry.timeCreated;} else version (linux) { alias 
sTimeStamp = std.file.DirEntry.timeLastAccessed; }



dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

From,
Vino.B


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 14:02:24 UTC, Jonathan M Davis wrote:
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn 
wrote:

On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
> What are you actually trying to do with it? These functions 
> are probably the wholly wrong approach.


Hi Adam,

  The existing program in Windows do few task's eg: Delete 
files
older that certain days, and now we are trying to port to 
Linux,
and above was just a example, hence asked the right approach 
for

porting.


Linux does not keep track of the creation time of a file. So, 
it will not work to have a program on Linux ask a file how long 
it's been since the file was created. If you want that 
information, you'll have to store it elsewhere somehow (and 
that generally only works if you created the file in the first 
place).


The modification time of the file is the time that the file was 
last changed (which would be the creation time if it were only 
ever written to once, but in the general case, it has no 
relation to the creation time at all). So, you could use 
std.file.timeLastModified to find out if a file has been 
changed within the last x number of days, but there is no way 
to find out the creation time of a file by asking the 
filesystem.


- Jonathan M Davis


Hi Jonathan,

  Thank you,  i got your point from the other forum topic which 
was raised by me earlier, hence decided to use modification time, 
the request is on how and the best approach to port the code from 
windows to Linux eg program below


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined identifier 
timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined identifier 
timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
What are you actually trying to do with it? These functions are 
probably the wholly wrong approach.


Hi Adam,

 The existing program in Windows do few task's eg: Delete files 
older that certain days, and now we are trying to port to Linux, 
and above was just a example, hence asked the right approach for 
porting.




From,
Vino.B



Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, I have a D program written on Windows 
platform and the program is working as expected, now i am trying 
to port the same program to Linux, my program use the function 
"timeCreated" from std.file for Windows hugely where as in Linux 
we do not have the same function hence planned to use the 
function "timeLastAccessed" from std.file, so what is the best 
approach to port the program. I tried the below code but not 
working, so can you one please guide me on the right method to 
port the program to linux, below is the example code.


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined identifier 
timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined identifier 
timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B




Re: Windows to Linux Porting

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 09:25:28 UTC, Russel Winder wrote:
On Fri, 2018-05-04 at 08:47 +, Vino via Digitalmars-d-learn 
wrote:



[…]
  Was able to resolve the issue, the issue was the letter "L" 
in

version (Linux) where is should be version (linux).


It would have helped if I had read the code first rather than 
jumped to a conclusion.


:-)


Hi Russel,
 No issue, and thank you for your help.

From,
Vino.B




Re: Windows to Linux Porting

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 07:43:39 UTC, Russel Winder wrote:
On Fri, 2018-05-04 at 03:30 +, Vino via Digitalmars-d-learn 
wrote:

[...]


`./nasconfig.txt`

perhaps: Linux uses / (as does Windows in fact) for directory 
separator.



[...]


Hi Russel,

 Was able to resolve the issue, the issue was the letter "L" in 
version (Linux) where is should be version (linux).



From,
Vino.B


Windows to Linux Porting

2018-05-03 Thread Vino via Digitalmars-d-learn

Hi All,

  Request you help on the below code, the below code always state 
the file does not exist even if the file do exist.


Code:

import core.stdc.stdlib: exit;
import std.stdio;
import std.file;
import std.path;

auto osSwitch () {
string ConfigFile;
version (Windows) { ConfigFile = absolutePath(`.\nasconfig.txt`); 
} else version (Linux) { ConfigFile = 
absolutePath(`nasconfig.txt`); }

return ConfigFile;
}
void main () {
auto ConfigFile = osSwitch;
if (!ConfigFile.exists) { writeln("The Configuration File ", 
buildNormalizedPath(ConfigFile), " do to exist, Terminating the 
execution.."); exit(-1);}

else { writeln(ConfigFile); }
}

From,
Vino.B



Re: cannot find -lcurl in Linux

2018-05-03 Thread Vino via Digitalmars-d-learn

On Thursday, 3 May 2018 at 10:22:43 UTC, Vino wrote:

On Thursday, 3 May 2018 at 10:19:55 UTC, Jonathan M Davis wrote:

[...]


Hi Jonathan,

 The below packages are already installed

[...]


Hi Jonathan,

 Installed the package libcurl-devel, that resolved the issue. 
Thank you very much.


From,
Vino.B


Re: cannot find -lcurl in Linux

2018-05-03 Thread Vino via Digitalmars-d-learn

On Thursday, 3 May 2018 at 10:19:55 UTC, Jonathan M Davis wrote:
On Thursday, May 03, 2018 10:10:05 Vino via Digitalmars-d-learn 
wrote:

Hi All,

  Request your help , while compiling a d program in SUSE 
Linux i
am getting the below error, the executable curl is present 
under

the path /usr/bin/

ask:/DScript # dmd -m64 -O -release -inline test.d
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld:
cannot find -lcurl collect2: error: ld returned 1 exit status
Error: linker exited with status 1


-lcurl means that it's linking against the curl library, not 
that it's trying to use the curl executable. It needs 
libcurl.a, and I believe that on OpenSuSE, that means that you 
need to install the development package for curl.


- Jonathan M Davis


Hi Jonathan,

 The below packages are already installed

S  | Name   | Type| Version| Arch   | 
Repository

---++-+++
i+ | curl   | package | 7.37.0-37.8.1  | x86_64 | 
localSLES12-SP2-Updates
i+ | curl   | package | 7.37.0-37.8.1  | x86_64 | 
SLES12-SP2-Updates
i+ | libcurl4   | package | 7.37.0-37.8.1  | x86_64 | 
localSLES12-SP2-Updates
i+ | libcurl4   | package | 7.37.0-37.8.1  | x86_64 | 
SLES12-SP2-Updates
i+ | libcurl4-32bit | package | 7.37.0-37.17.1 | x86_64 | 
SLES12-SP2-Updates
i  | python-pycurl  | package | 7.19.0-16.5| x86_64 | 
localSLES12-SP2-Pool
i  | python-pycurl  | package | 7.19.0-16.5| x86_64 | 
SLES12-SP2-Pool


From,
Vino.B


cannot find -lcurl in Linux

2018-05-03 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help , while compiling a d program in SUSE Linux i 
am getting the below error, the executable curl is present under 
the path /usr/bin/


ask:/DScript # dmd -m64 -O -release -inline test.d
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: 
cannot find -lcurl
collect2: error: ld returned 1 exit status
Error: linker exited with status 1


From,
Vino.B


Re: D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 15:42:38 UTC, Jonathan M Davis wrote:
On Tuesday, May 01, 2018 15:18:12 Vino via Digitalmars-d-learn 
wrote:

On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:
> On 02/05/2018 2:56 AM, Vino wrote:
>> [...]
>
> Does this work?
>
> $ dmd -run foo.d

Hi Rikki,

  No, it is not working, rather getting an error, and the user 
i

executed is the root user. if i compile the program as dmd
 and then execute it as ./ it works
fine, so is rdmd not supported in Linux.

Error:
/tmp/dmd_runqfz3ul: Permission denied


That sounds like your /tmp is mounted with noexec. which won't 
work with rdmd or any other program that expects to be able to 
create a file in /tmp and run it. Presumably, you'll need to 
change the settings in /etc/fstab so that /tmp is not mounted 
with noexec.


- Jonathan M Davis


Hi Jonathan,

  Yes the /tmp is mounted with noexec option , we should not 
change this option as it is a security violation so is there any 
other way we can make it work, it tried setting the tmp env 
variable to a local FS which is mounted with the noexec option 
but it did not work.


From,
Vino.B


Equivalent function of timeCreated for Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, what is the equivalent function of 
timeCreated(Windows) for Linux. Or how do i get the file creation 
date and time in Linux using D.


From,
Vino.B


Re: D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:

On 02/05/2018 2:56 AM, Vino wrote:

Hi All,

  Request your help, trying to execute the below program in 
SUSE Linux but there is no output



Code
#!/usr/bin/env rdmd
import std.stdio;

void main() {
writeln("Test");
}

DMD Version : DMD64 D Compiler v2.079.1
Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm

Execution 1 : rdmd   without this #!/usr/bin/env 
rdmd
Execution 2: ./ with #!/usr/bin/env rdmd + chmod 
777 


Both ways there is on output


From,
Vino.B


Does this work?

$ dmd -run foo.d


Hi Rikki,

 No, it is not working, rather getting an error, and the user i 
executed is the root user. if i compile the program as dmd 
 and then execute it as ./ it works 
fine, so is rdmd not supported in Linux.


Error:
/tmp/dmd_runqfz3ul: Permission denied

From,
Vino.B


D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, trying to execute the below program in SUSE 
Linux but there is no output



Code
#!/usr/bin/env rdmd
import std.stdio;

void main() {
writeln("Test");
}

DMD Version : DMD64 D Compiler v2.079.1
Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm

Execution 1 : rdmd   without this #!/usr/bin/env 
rdmd
Execution 2: ./ with #!/usr/bin/env rdmd + chmod 
777 


Both ways there is on output


From,
Vino.B


Advice on : rmdirRecurse and setAttributes in Windows

2018-04-21 Thread Vino via Digitalmars-d-learn

Hi All,

  The function rmdirRecurse does not work in Windows if the file 
has the READ ONLY permission, so to over come this issue, i have 
written the below function to set the permission on file and 
folder using the function "setAttributes" , so can any one advice 
me whether the below code is fine or what are the other ways to 
achieve the same.



auto aPrivileges(T)(T df)
if(df[0].isDir) {
auto sDir = Array!string(dirEntries(join([`\\?\`, 
df[0]]), SpanMode.depth).filter!(a => a.isDir).map!(a => 
(a.name)));
auto sFile = Array!string(dirEntries(join([`\\?\`, 
df[0]]), SpanMode.depth).filter!(a => a.isFile).map!(a => 
(a.name)));
foreach(sD; parallel(sDir[], 1)) { 
setAttributes(sD.toUTF16, 66); }
foreach(sF; parallel(sFile[], 1)) { 
setAttributes(sF.toUTF16, 666); }

}
else { setAttributes(df[0].toUTF16, 666); }
}

From,
Vino.B


Re: SMTP Mail

2018-04-12 Thread Vino via Digitalmars-d-learn

On Tuesday, 10 April 2018 at 15:18:19 UTC, Adam D. Ruppe wrote:

On Tuesday, 10 April 2018 at 15:10:44 UTC, Vino wrote:
The variable "to" is of type string[] but we need it as 
Array!string

The variable "Subject" but we need it as Array!string.


You'll have to convert them yourself if that is a must, but why 
would you need that?


Hi Adam,

 I tried to replicate your code with what is required for me, and 
was able to successed 90% and stuck, can you please help me.


Using the below code are are able to receive the mail with the 
attachment, but the content of the attachment contains the Body 
text of the mail(Body1") rather than the original text and the 
mail body is empty, not sure where is the issue.


Code:
import std.net.curl;
pragma(lib, "curl");
import std.format;
import std.container.array;
import std.stdio;
import std.path;
import std.file;

struct RelayInfo { string server; }
struct MimeAttachment { string type; string filename; 
const(void)[] content; string id; }


class EmailMessage {

Array!string To, Body, headers;
string From, Subject, msg;

override string toString ()
{
	string T = "%-(%s,  %)".format(To[]); string B = "%-(%s,  
%)".format(Body[]);

headers.insertBack("To: " ~ T);
headers.insertBack("From: " ~ From);
headers.insertBack("Subject: " ~ Subject);
headers.insertBack("MIME-Version: 1.0");
msg.reserve(Body.length + 1024);
foreach(header; headers) { msg ~= header ~ "\r\n"; }
if(msg.length > 0) { msg ~= "\r\n"; msg ~= B; }

return(msg);
}

const(MimeAttachment)[] attachments;

void addAttachment(string Fname, ) {
string mimeType = "text/plain";
string filename = baseName(Fname);
void[] content = read(Fname);
string id = null;

headers.insertBack("Content-Disposition: attachment; 
filename=\""~ filename ~"\"");

headers.insertBack("Content-ID: <" ~ id ~ ">");
headers.insertBack("Content-Type: text/plain; charset=UTF-8; 
file=" ~ filename);

attachments ~= MimeAttachment(mimeType, filename, content, id);
}

void send (RelayInfo mailServer = RelayInfo("smtp://localhost")) {
auto smtp = SMTP(mailServer.server);
string T = "%-(%s,  %)".format(To[]);
smtp.mailTo = T;
smtp.mailFrom = From;
smtp.message = toString;
smtp.perform(); 
}
}

void main () {
string Filename = "D:\\DScript\\Tmailconfig.txt";
auto message = new EmailMessage();
message.To ~= "v...@xxx.com";
message.From = "ser...@hosting.com";
message.Subject = "Test";
message.Body ~= "Body1";
message.addAttachment(Filename));
message.send(RelayInfo("smtp://smtp.awk.sed.com"));
}

From,
Vino.B


Re: SMTP Mail

2018-04-10 Thread Vino via Digitalmars-d-learn

On Tuesday, 10 April 2018 at 13:51:02 UTC, Adam D. Ruppe wrote:

On Tuesday, 10 April 2018 at 11:09:56 UTC, Vino wrote:
 Now the program works, but the attachment does not work as 
expected,


message.addAttachment("text/plain", 
"C:\\Temp\\Test\Test1.txt", "Test");


What did you expect that "Test" argument to do if it was going 
to read the file as the content? I guess I should change the 
documents on this. The way it works is the filename argument is 
just what is seen in the email as a suggestion name for the 
user to download the attachment, and the content argument is 
what is what's inside that attachment.


Since the attachment name just suggests a name, and the user 
decides where to put it, it should NOT have a path name.


So try this instead:


addAttachment("text/plain", "Test1.txt", 
std.file.read("C:\Temp\Test\Test1.txt"));



so the name argument is JUST the name to suggest to the user, 
then the content argument gives the content of your file to 
attach - which here is read from the file on disk via the 
phobos std.file read function.


Hi Adam,

  Thank you very much, the program now works, but i need to make 
some adjustment, if possible can you please help me on this.


The variable "to" is of type string[] but we need it as 
Array!string

The variable "Subject" but we need it as Array!string.

From,
Vino.B




Re: SMTP Mail

2018-04-10 Thread Vino via Digitalmars-d-learn

On Monday, 9 April 2018 at 19:19:53 UTC, Adam D. Ruppe wrote:

On Monday, 9 April 2018 at 15:38:55 UTC, Vino.B wrote:
Thank you very much, I copied your folder arsd under the 
phobes folder in c:\D\... and the program was placed on my 
desktop and tried to execute it from the desktop via rdmd.



I don't think rdmd is seeing the dependency on htmltotext.d. 
Try importing it explicitly from your main:


import arsd.email;
import arsd.htmltotext;

/* the rest of your code */


Just that way rdmd will find it easier.


Hi Adam,

 Now the program works, but the attachment does not work as 
expected,


message.addAttachment("text/plain", "C:\\Temp\\Test\Test1.txt", 
"Test");



It takes the full path as file name eg: If the attachment file 
resides on the path C:\Temp\Test\Test1.txt" the attachment name 
file name that we receive is as "CTempTestTest1.txt" and also it 
does not attached the real file, instead the content of the file 
is "Test"


We Tried the below

message.addAttachment("text/plain", "Test1.txt", 
"C:\\Temp\\Test\Test1.txt");


After the above change the attachment file name is "Test1.txt" 
with the content "C:\Temp\Test\Test1.txt"


The orignal content of the file is "Hi This is Test Attachment".

From,
Vino.B


Re: SMTP Mail

2018-04-09 Thread Vino via Digitalmars-d-learn

On Sunday, 8 April 2018 at 15:45:48 UTC, Vino wrote:

On Friday, 25 August 2017 at 02:13:42 UTC, Adam D. Ruppe wrote:

[...]


Hi Adam,

  I am trying your email.d programming, and i am getting the 
below errors, can you please help me, i just used these 
programs (characterencodings.d, color.d, dom.d, htmltotext.d, 
email.d)


[...]


Hi All,

 Any help is much appreciated.

From,
Vino.B


Re: SMTP Mail

2018-04-08 Thread Vino via Digitalmars-d-learn

On Friday, 25 August 2017 at 02:13:42 UTC, Adam D. Ruppe wrote:

On Tuesday, 22 August 2017 at 12:52:24 UTC, Vino.B wrote:
  Request your help on sending Mails, I am able to receive 
mails with empty body the line "smtp.message ="Example 
Message" doesn't seem to be working and also please let me 
know how do i send a file as a attachment in a email.


The message there needs to be the complete message, including 
headers. The SMTP struct is pretty low-level.


My email.d (plus its dependencies, characterencodings.d, dom.d, 
and htmltotext.d) has the code to form a full message. It isn't 
very documented though.


https://github.com/adamdruppe/arsd


auto message = new EmailMessage();
message.to ~= "some@email";
message.subject = "Subject"
message.setTextBody("hi");
message.send(RelayInfo("smtp://whatever", "user", "pass"));


Hi Adam,

  I am trying your email.d programming, and i am getting the 
below errors, can you please help me, i just used these programs 
(characterencodings.d, color.d, dom.d, htmltotext.d, email.d)


Program
import arsd.email;
void main() {

auto message = new EmailMessage();
message.to ~= "v...@xxx.com";
message.subject = "Test";
message.setHtmlBody("1.Line 12.Line 23.Line 
3");

message.addAttachment("text/txt", "C:\\Temp\\test.log", "Text");
message.send(RelayInfo("smtp://smtp..com"));
}

Error
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\Users\-TSK-X~1\AppData\Local\Temp\6\.rdmd\rdmd-dmail.d-4C543ACF04BF46D1398435D9500B3B70\objs\dmai
l.exe.obj(dmail.exe)
 Error 42: Symbol Undefined 
__D6object__T14__switch_errorZQrFNaNbNiNfAyakZv

C:\Users\-TSK-X~1\AppData\Local\Temp\6\.rdmd\rdmd-dmail.d-4C543ACF04BF46D1398435D9500B3B70\objs\dmai
l.exe.obj(dmail.exe)
 Error 42: Symbol Undefined 
__D4arsd10htmltotext10htmlToTextFAyabiZQg

C:\Users\-TSK-X~1\AppData\Local\Temp\6\.rdmd\rdmd-dmail.d-4C543ACF04BF46D1398435D9500B3B70\objs\dmai
l.exe.obj(dmail.exe)
 Error 42: Symbol Undefined __D4arsd10htmltotext12__ModuleInfoZ
Error: linker exited with status 3

From,
Vino.B


Re: std.datetime.systime: days Deprecation message

2018-04-08 Thread Vino via Digitalmars-d-learn

On Saturday, 7 April 2018 at 18:12:00 UTC, Alex wrote:

On Saturday, 7 April 2018 at 17:25:07 UTC, Vino wrote:

Hi All,

  Request your help on the below Deprecation message.

import std.datetime.systime: Clock, days, SysTime;

void main (int AgeSize) {
int AgeSize = 1
auto ct2 = Clock.currTime(), st2 = ct2 + days(-AgeSize);
}
test.d(30): Deprecation: Symbol core.time.days is not visible 
from module test.d because it is privately imported in module 
systime



From,
Vino.B


As far as I understand it, days are located in core.time.

import core.time : days;


Hi Alex,

  Thank you, that resolved the issue.

From,
Vino.B



std.datetime.systime: days Deprecation message

2018-04-07 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help on the below Deprecation message.

import std.datetime.systime: Clock, days, SysTime;

void main (int AgeSize) {
int AgeSize = 1
auto ct2 = Clock.currTime(), st2 = ct2 + days(-AgeSize);
}
test.d(30): Deprecation: Symbol core.time.days is not visible 
from module test.d because it is privately imported in module 
systime



From,
Vino.B


Calling Windows Command

2018-03-21 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help in calling the windows command to delete all 
file and folders recursively as the D function rmdirRecurse does 
not delete file in the permission of the file is readonly in 
windows 2008 R2


import std.process: execute;
import std.array: empty;
auto RemoveDir () (
auto dFiles = "C:\\Temp\Test1";
auto Step = "run";
if (Step == "run" && !dFiles.empty) {
version(Windows)
 {
  foreach(d; dFiles) {
  execute(["rmdir.exe","-command", "/S /Q", `~d~`]); } } } 
return dFiles;

)

void main () {
writeln(RemoveDir);
}

From,
Vino.N


Re: Thread Function does not executes

2018-03-08 Thread Vino via Digitalmars-d-learn

On Tuesday, 6 March 2018 at 09:01:55 UTC, Vino wrote:

On Monday, 5 March 2018 at 13:50:28 UTC, Vino wrote:

[...]


Hi All,

 On further analysis, as to why the function deleteAgedDir is 
not getting executed, found that if this function finds a 
folder to be deleted then it should delete the 
folder(rmdirRecurse(dirname)), but in this case it does not 
delete the folder if it finds so the return of this function is 
empty, if there are no file to be deleted then this function 
works perfectly but if there is any folder preset to be deleted 
this that folder is not getting deleted, so i am suspecting 
that the issue is with the function rmdirRecurse is not working 
as expected on Windows 2007, so request your help on this 
please.


From,
Vino.B


Hi All,

If I compile the program with 32bit(without passing -64m) then 
everything is working as expected. So can any one explain why the 
program(rmdirRecurse) does not work when compiled with 64 bit.


From,
Vino.B




Re: Thread Function does not executes

2018-03-06 Thread Vino via Digitalmars-d-learn

On Monday, 5 March 2018 at 13:50:28 UTC, Vino wrote:

Hi All,

  Request your help, I have 3 functions such as below, I am 
calling these function using another function ptManage which 
executes these function's in parallel as each of the below 3 
function run's on 10 - 12 different file systems, The issue is 
as below


Issue:

Most of the time the program executes perfectly, some time the 
function 2 is skipped, after analysis further I was able to 
find that if the 1st and 3rd functions(deleteFile, SizeDir) 
completes before the 2nd function(deleteAgedDir) then it skips, 
meaning the program is not waiting for all the thread to be 
completed before exiting the main. so any help on this would be 
much appreciated. Ti does not throw any exception or error the 
program exits' smoothly.


Function:
deleteFile : Delete file after a certain date
deleteAgedDir : Delete folder after a certain date
SizeDir   : Finde Size of folder after a certain date

Ex:
auto deleteFile (string FFs, int AgeSize) { }

auto deleteAgedDir (string FFs, int AgeSize) { }

auto SizeDir (string FFs, int AgeSize) {

auto TP = new TaskPool(TL);
foreach (d; TP.parallel(dFiles[],1)) {
Thread.sleep(5.seconds); TP.finish;
 }
}

void ptManage(T)(T function(string, string, int) coRoutine, 
Array!string Dirlst, int AgeSize) {
alias scRType = typeof(coRoutine(string.init, string.init, 
int.init));

auto PFresult = taskPool.workerLocalStorage!scRType();
ReturnType!coRoutine rData;

foreach (string FFs; parallel(Dirlst[0 .. $],1)) { PFresult.get 
~= coRoutine(FFs.strip, Step, AgeSize); }

foreach(i; PFresult.toRange) { rData ~= i[][]; }
writeln(rData[]);
}

Void main() {

ptManage(, CleanDirlst, AgeSize1);
ptManage(, AgedDirlst, AgeSize2);
ptManage(, AgeSize3);
}   


From,
Vino.B


Hi All,

 On further analysis, as to why the function deleteAgedDir is not 
getting executed, found that if this function finds a folder to 
be deleted then it should delete the 
folder(rmdirRecurse(dirname)), but in this case it does not 
delete the folder if it finds so the return of this function is 
empty, if there are no file to be deleted then this function 
works perfectly but if there is any folder preset to be deleted 
this that folder is not getting deleted, so i am suspecting that 
the issue is with the function rmdirRecurse is not working as 
expected on Windows 2007, so request your help on this please.


From,
Vino.B


Thread Function does not executes

2018-03-05 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, I have 3 functions such as below, I am 
calling these function using another function ptManage which 
executes these function's in parallel as each of the below 3 
function run's on 10 - 12 different file systems, The issue is as 
below


Issue:

Most of the time the program executes perfectly, some time the 
function 2 is skipped, after analysis further I was able to find 
that if the 1st and 3rd functions(deleteFile, SizeDir) completes 
before the 2nd function(deleteAgedDir) then it skips, meaning the 
program is not waiting for all the thread to be completed before 
exiting the main. so any help on this would be much appreciated. 
Ti does not throw any exception or error the program exits' 
smoothly.


Function:
deleteFile : Delete file after a certain date
deleteAgedDir : Delete folder after a certain date
SizeDir   : Finde Size of folder after a certain date

Ex:
auto deleteFile (string FFs, int AgeSize) { }

auto deleteAgedDir (string FFs, int AgeSize) { }

auto SizeDir (string FFs, int AgeSize) {

auto TP = new TaskPool(TL);
foreach (d; TP.parallel(dFiles[],1)) {
Thread.sleep(5.seconds); TP.finish;
 }
}

void ptManage(T)(T function(string, string, int) coRoutine, 
Array!string Dirlst, int AgeSize) {
alias scRType = typeof(coRoutine(string.init, string.init, 
int.init));

auto PFresult = taskPool.workerLocalStorage!scRType();
ReturnType!coRoutine rData;

foreach (string FFs; parallel(Dirlst[0 .. $],1)) { PFresult.get 
~= coRoutine(FFs.strip, Step, AgeSize); }

foreach(i; PFresult.toRange) { rData ~= i[][]; }
writeln(rData[]);
}

Void main() {

ptManage(, CleanDirlst, AgeSize1);
ptManage(, AgedDirlst, AgeSize2);
ptManage(, AgeSize3);
}   


From,
Vino.B


Re: countUntil to print all the index of a given string.

2018-02-25 Thread Vino via Digitalmars-d-learn
On Sunday, 25 February 2018 at 03:41:27 UTC, Jonathan M Davis 
wrote:
On Sunday, February 25, 2018 02:58:33 Seb via 
Digitalmars-d-learn wrote:

[...]


That will help eventually, but it requires a compiler flag, so 
it's really not going to help for code in general right now, 
and the fact that that DIP does nothing to solve the problem of 
how to create exception messages without allocating them on the 
GC heap means that exceptions in general are still frequently 
going to result in allocations unless you jump through several 
hoops to be able to create an exception message that's in a 
static array or malloc-ed or something. So, I don't know how 
much it's going to help in practice outside of code where the 
programmer is absolutely determined to have no GC allocations.



[...]


Yeah. There does tend to be a correlation between @nogc and 
whether a range is lazy, but it's not guaranteed, so I'm 
inclined to think that it's a poor idea to rely on it and that 
it's just ultimately better to look at the documentation or 
even the code.


- Jonathan M Davis


Hi All,

  Sorry, I am not able to see any correlation between the raised 
topic and the conversation that is happening in this forum, could 
any one please explain on of what is going on and how do you 
thing that this conversation is related to the topic raised, if 
not would suggest you to open a new topic.


From,
Vino.B


Re: countUntil to print all the index of a given string.

2018-02-24 Thread Vino via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 08:50:27 UTC, Jonathan M Davis 
wrote:
On Tuesday, February 20, 2018 08:44:37 aberba via 
Digitalmars-d-learn wrote:

On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote:
> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote:
>> [...]
>
> Just thought of a much better/simpler solution for that last 
> case that also doesn't force you to read all data (which 
> might

>
> be impossible when dealing with infinite ranges):
> import std.range;
> import std.algorithm;
>
> a[]
>
>  .enumerate   // get tuples (index,
>
> value)
>
>  .filter!(t => t[1] == "Test2")   // keep only if value 
> ==

>
> "Test2"
>
>  .map!(t => t[0]) // keep only the index
>
> part
>
>  .writeln;
>
> Completely lazy.

How does one detect an operation as lazy or not?  Is the some 
compile-time or runtime check for that?


My guess is by referring to the docs function signature.


You have to read the docs or read the source code, though in 
general, functions that return a range type that wraps the 
original range tend to be lazy, whereas if a function returns 
the original range type or an array, then it's clearly not lazy.


- Jonathan M Davis


Hi All,

 Thank you very much, the provide solution work's for the given 
example, so how can we achieve the same for the below code



import std.stdio;
import std.container;
import std.algorithm;

void main () {
auto a = Array!string("Test1", "Test2", "Test3", "Test1", 
"Test2");

auto b = Array!string("Test1", "Test2", "Test3");

foreach(i; b[]) {
writeln(SList!int(a[].countUntil(i))[]); }
}

Output
[0]
[1]
[2]

Required
[0,3]
[1,4]
[2]

From,
Vino.B


countUntil to print all the index of a given string.

2018-02-18 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help on printing the all index of an array element 
, eg; the below code prints the index of the string "Test2" as 
[1], but the string "Test2" is present 2 times at  index  1 and 
4, so how do I print all the index of a given string.


import std.stdio;
import std.container;
import std.algorithm;

void main () {
auto a = Array!string("Test1", "Test2", "Test3", "Test1", 
"Test2");

writeln(SList!int(a[].countUntil("Test2"))[]);
}

Output
[1]

Expected
[1, 4]

From,
Vino.B


Re: Disk space used and free size of a Network share folder in Windows

2018-02-16 Thread Vino via Digitalmars-d-learn
On Thursday, 15 February 2018 at 20:43:32 UTC, Johan Engelen 
wrote:

On Wednesday, 14 February 2018 at 12:22:09 UTC, Vino wrote:

Hi All,

 Request your help on how to get the disk space used and free 
size of a Network share folder in Windows, tried with getSize 
but it return 0;


See: 
https://github.com/ldc-developers/ldc/blob/f5b05878de6df2ea4a77c37128ad2eae0266b690/driver/cache_pruning.d#L47-L71


and https://issues.dlang.org/show_bug.cgi?id=16487

cheers,
  Johan


Hi All,

  Thank you very much, was able to successfully use the windows 
function.


From,
Vino.B


Re: Disk space used and free size of a Network share folder in Windows

2018-02-14 Thread Vino via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole 
wrote:

On 14/02/2018 12:22 PM, Vino wrote:

Hi All,

  Request your help on how to get the disk space used and free 
size of a Network share folder in Windows, tried with getSize 
but it return 0;


eg: Share Name :\\server1\dir1$

From,
Vino.B


See:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx


Hi Rikki,

   Wouldn't this be easy to use with std.process: execute package 
and calling wmic.exe, the only problem is i am not sure hot to 
get the out put without the headings(Caption  FreeSpace,Size) any 
help on same is much appreciated.


import std.process: execute;
import std.stdio : writeln;

void main () {
version(Windows) {
auto result = execute(["wmic.exe", "logicaldisk", "get", 
"size,freespace,caption"]);

writeln(result.output);
}
}
Output :
Caption  FreeSpaceSize
C:   19702837248  180043665408
H:   85580382208  824633720832

From,
Vino.B


Disk space used and free size of a Network share folder in Windows

2018-02-14 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help on how to get the disk space used and free 
size of a Network share folder in Windows, tried with getSize but 
it return 0;


eg: Share Name :\\server1\dir1$

From,
Vino.B






Re: rmdirRecurse - on NFS file system

2018-02-13 Thread Vino via Digitalmars-d-learn

On Tuesday, 13 February 2018 at 17:01:06 UTC, Seb wrote:

On Tuesday, 13 February 2018 at 16:58:09 UTC, Vino wrote:

On Monday, 12 February 2018 at 06:52:25 UTC, Vino wrote:

[...]


Hi All,

Was able to resolve this issue.


That's great!

BTW I think it would be helpful for future reader who find this 
thread to know how you resolved your problem.


Hi All,

I just modified the below lines of the code,

if (Step == "run" && !dFiles.empty) { dFiles.each!(f => 
rmdirRecurse(f[0])); } return dFiles;



From,
Vino.B




Re: rmdirRecurse - on NFS file system

2018-02-13 Thread Vino via Digitalmars-d-learn

On Monday, 12 February 2018 at 06:52:25 UTC, Vino wrote:

Hi All,

   Request your help, the below code works find on normal File 
system, bu if the file system is a NFS file system the below 
code, is not working


if Step = dryrun( Display Only) : Works for both NFS and normal 
file system.
if Step = run (Delete folder) : Does not work on NFS file 
system but works on normal file system.

No error message.

auto coAgedDirClean (string FFs, string Step, int AgeSize) {
auto cAges = AgeSize
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir && 
!globMatch(a.baseName, "*DND*") && a.timeCreated < 
cAges).map!(a => tuple(a.name, a.timeCreated)));
if (Step == "run") { dFiles.each!(f => f[0].rmdirRecurse); } 
return dFiles;

}

From,
Vino.B


Hi All,

Was able to resolve this issue.



rmdirRecurse - on NFS file system

2018-02-11 Thread Vino via Digitalmars-d-learn

Hi All,

   Request your help, the below code works find on normal File 
system, bu if the file system is a NFS file system the below 
code, is not working


if Step = dryrun( Display Only) : Works for both NFS and normal 
file system.
if Step = run (Delete folder) : Does not work on NFS file system 
but works on normal file system.

No error message.

auto coAgedDirClean (string FFs, string Step, int AgeSize) {
auto cAges = AgeSize
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, 
"*DND*") && a.timeCreated < cAges).map!(a => tuple(a.name, 
a.timeCreated)));
if (Step == "run") { dFiles.each!(f => f[0].rmdirRecurse); } 
return dFiles;

}

From,
Vino.B


Re: Adjacent item in a array

2018-02-11 Thread Vino via Digitalmars-d-learn

On Saturday, 3 February 2018 at 22:58:04 UTC, Vino wrote:

On Saturday, 3 February 2018 at 19:28:01 UTC, Seb wrote:

On Saturday, 3 February 2018 at 19:13:05 UTC, Vino wrote:

[...]


2.079 [1, 2] will ship with slide:

---
auto arr = ["T1", "T2", "T3", "T4", "T5"];
arr.slide(2).each!writeln;
---

[...]


Hi Seb;

  Thank you very much.

From,
Vino.B


Hi Seb,

 Was going through the change log of version v2.079, and it has 
most of the function that I require, so hope the release date of 
v2.079 would be 1st/March, correct me if i am wrong.


From,
Vino.B


String to binary conversation

2018-02-05 Thread Vino via Digitalmars-d-learn

Hi All,

Request your help on how to convert a string to binary,eg "test" 
to 01110100 01100101 01110011 01110100.


From,
Vino.B


Array element Replace

2018-02-03 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, on hot to replace an element(a[2]) in an 
array with the element(a[3])


Eg,

auto a = Array!string("T1","T2","T3");
writeln(D1.replace(a[2], a[3]));


From,
Vino.B


Re: Adjacent item in a array

2018-02-03 Thread Vino via Digitalmars-d-learn

On Saturday, 3 February 2018 at 19:28:01 UTC, Seb wrote:

On Saturday, 3 February 2018 at 19:13:05 UTC, Vino wrote:

[...]


2.079 [1, 2] will ship with slide:

---
auto arr = ["T1", "T2", "T3", "T4", "T5"];
arr.slide(2).each!writeln;
---

[...]


Hi Seb;

  Thank you very much.

From,
Vino.B


Re: Adjacent item in a array

2018-02-03 Thread Vino via Digitalmars-d-learn

On Saturday, 3 February 2018 at 19:19:00 UTC, Adam D. Ruppe wrote:

On Saturday, 3 February 2018 at 19:13:05 UTC, Vino wrote:

 Request you help on printing an array in below,


Try looping through the array printing the current item 
followed by the item after the current item. Foreach with index 
may be helpful. Consider what happens on the last element.


Hi Ruppe,

 I have tired it , it prints as expected but getting range 
violation when it reaches the last element


foreach(j, k; D1[].enumerate(1))
writeln(k,D1[j]);

From,
Vino.B


Adjacent item in a array

2018-02-03 Thread Vino via Digitalmars-d-learn

Hi All,

 Request you help on printing an array in below,

Eg:

Array ("T1", "T2", "T3", "T4", "T5")

Output required as below

T1,T2
T2,T3
T3,T4
T4,T5


From,
Vino.B


Re: Storing struct in a array

2018-01-10 Thread Vino via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 19:05:48 UTC, thedeemon wrote:

On Tuesday, 9 January 2018 at 18:09:58 UTC, Vino wrote:
 It is possible to store struct in a array ans use the same 
in csvReader


Sure, you can just pass the type of your struct to csvReader:



Array!T1 T1s;
reader(fName, T1s); // pass the array Type as a function 
parameter


First you write a template function that takes an array of some 
generic type and fills it with records from CSV file:


void readData(DataType)(string fname, ref Array!DataType arr) {
foreach (record; fname.readText.csvReader!DataType('\t')) {
arr ~= record;
}
}

Then you can use it in your main program with different types:

struct S1 { string name; string value; int other; }
struct S2 { int a; string b; }

void main () {
...
if (someCondition) {
Array!S1 arr1;
readData("data1.csv", arr1);
} else {
Array!S2 arr2;
readData("data2.csv", arr2);
}
}

A little advice. Kindly pause and spend an evening reading this 
book:

http://ddili.org/ders/d.en/

Currently your code pieces look like a soup produced by someone 
who still confuses variables and types, and lacks basic 
programming skills. Read the book, don't rush with writing 
broken code.


Hi Deemon,

 I agree that my code is broken code and I am a Newbie in the 
world of programming, the confusion begin when i started writing 
the second module, and now i was able to find the issue, and the 
real requirement. The requirement is as below.


Program: The below program works.
auto reader(MyStruct) (File fname, auto ref MyStruct st) {
alias ColumnTypes = AliasSeq!(MyStruct);
foreach (record; 
fname.byLineCopy().joiner("\n").csvReader!(Tuple!ColumnTypes)(null)) {

writeln(record[0], record[1], record[2]);
}

void main () {
auto fname = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\Table2.csv");

auto Table = baseName(stripExtension(fname));
struct S1 { string Name; string Country; int Age; }
S1 Table1s;
reader(File(fname), join([Table, "1s"]));
}

The requirement is as below
The function reader should store the data in column wise Array 
and return the same.


Array!has to be taken from the header data as the CSV file has header 
Name, Country, Age using records.header)

e.g
Array!string Name; (records.header[0]);
Array!string Country;(records.header[1]);
Array!string Age;(records.header[2]);

and return the above arrays

From,
Vino.B





Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 17:41:10 UTC, Vino wrote:

On Tuesday, 9 January 2018 at 17:00:05 UTC, thedeemon wrote:

On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote:

Hi All,

 It is possible to store struct in a array ans use the same 
in csvReader


Sure, you can just pass the type of your struct to csvReader:

struct Layout { string name; int value; double other; }

auto readArrayOfStructs(string fname) {
Array!Layout res;
foreach(record; fname.readText.csvReader!Layout('\t')) {
res ~= record;
}
return res;
}


Hi Deemon,

  Thank you, and sorry for the confusion, the requirement is as 
below


auto reader(T) (Array!T T1s, T fname) {
auto uFile = File(fName, "r");
foreach (record; 
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!T1s)) // 
receive the type and fetch the record

writeln(record);
}

void main () {
auto fName = 
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\Table1.csv";

struct T1 { string Name; string Country; int Age; }
Array!T1 T1s;
reader(fName, T1s); // pass the array Type as a function 
parameter

}


From,
Vino.B


Details

For example let say we have 3 struct
auto read(T) (T Filename, T ArrayType) {
T ArrayType res;
foreach (record; 
Filename.byLineCopy().joiner("\n").csvReader!(T)(Tuple!ArrayType))

foreach(i, T; ColumnTypes) { res[i].insert(record[i]); }
}
return res;
}

void main () {

struct S1 { }
struct S2 { }
struct S3 { }

Get user input(UI)
if(UI == S1) {
Array!S1 T1;
writeln(read(File1, Array Type));
}

From,
Vino.B




Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 17:00:05 UTC, thedeemon wrote:

On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote:

Hi All,

 It is possible to store struct in a array ans use the same in 
csvReader


Sure, you can just pass the type of your struct to csvReader:

struct Layout { string name; int value; double other; }

auto readArrayOfStructs(string fname) {
Array!Layout res;
foreach(record; fname.readText.csvReader!Layout('\t')) {
res ~= record;
}
return res;
}


Hi Deemon,

  Thank you, and sorry for the confusion, the requirement is as 
below


auto reader(T) (Array!T T1s, T fname) {
auto uFile = File(fName, "r");
foreach (record; 
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!T1s)) // receive 
the type and fetch the record

writeln(record);
}

void main () {
auto fName = 
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\Table1.csv";

struct T1 { string Name; string Country; int Age; }
Array!T1 T1s;
reader(fName, T1s); // pass the array Type as a function parameter
}


From,
Vino.B



Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote:

Hi All,

 It is possible to store struct in a array ans use the same in 
csvReader e.g.


import std.stdio;
import std.container.array;

void main () {
Array!string a;
struct Layout { string name; int value; double other; }

a.insert(Layout);
auto record =  
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!a[0]))

foreach (record; records)
{
writeln(record.name);
writeln(record.value);
writeln(record.other);
}

From,
Vino.B


Hi All,

 Was able to find on hot to store a struct in an array, but not 
able to use that array in csvReader


Program:
import std.algorithm: joiner;
import std.container.array;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;

void main () {
auto fName = 
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\Table1.csv";

auto uFile = File(fName, "r");
struct T1 { string Name; string Country; int Age; }
Array!T1 T1s;
foreach (record; 
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!T1s))

writeln(record);
}

Error:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(523): 
Error: template instance parseSpecs!(T1s) cannot use local 'T1s' 
as parameter to non-global template

 parseSpecs(Specs...)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(635): 
Error: CTFE failed because of previous errors in injectNamedFields
ArrayStruct.d(12): Error: template instance 
ArrayStruct.main.Tuple!(T1s) error instantiating

Failed: ["dmd", "-v", "-o-", "ArrayStruct.d", "-I."]

From,
Vino.B


Re: Creating Struct for an output of a program.

2018-01-09 Thread Vino via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 12:50:04 UTC, Mengu wrote:

On Tuesday, 9 January 2018 at 07:57:19 UTC, Vino wrote:

[...]


if S2 consists of data for Layout struct, then you can simply 
do:


auto S2 = S1.map!(a => Layout(a[0], a[1], a[2]));

which will give you a range of Layout.


Hi,

 We want the Layout struct to be created from the output of S1, 
in the above the Layout is a example of the struct structure that 
we needed.


From,
Vino.B


Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn

Hi All,

 It is possible to store struct in a array ans use the same in 
csvReader e.g.


import std.stdio;
import std.container.array;

void main () {
Array!string a;
struct Layout { string name; int value; double other; }

a.insert(Layout);
auto record =  
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!a[0]))

foreach (record; records)
{
writeln(record.name);
writeln(record.value);
writeln(record.other);
}

From,
Vino.B


Creating Struct for an output of a program.

2018-01-09 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help on how to create a struct with the output of 
the below program.


Program:
import std.algorithm: all, map, filter;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.container.array;
import std.string: split, strip;
import std.uni: isWhite, toLower;
import std.range: chunks;

void main () {
Array!string TableData, StructureData;
auto Meta = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\meta\\meta.txt", "r");

auto MetaData = Array!(Tuple!(string, string))(Meta.byLineCopy()
.filter!(line => !line.all!isWhite)
.map!(a => a.split(":"))
.map!(a => tuple(a[0].toLower.strip, a[1].toLower.strip)));
foreach (line; MetaData[]) { TableData.insertBack(line[0]); 
StructureData.insertBack(line[1]); }

for(int i = 0; i < TableData[].length; i++ ) {
auto S1 = StructureData[i].split(",").chunks(3);
auto S2 = S1.map!(a => tuple(a[0],a[1],a[2]));
for(int z =0; z < S2.length; z++)
{ writefln("%-8s %;s", S2[z][1] , S2[z][0]); }
}
}

Output:
string name;
string country;
int age;


Need to create as struct using the output

struct Layout {
{
string name;
string country;
int age;

}

From,
Vino.B




Re: Error: variable i cannot be read at compile time

2018-01-08 Thread Vino via Digitalmars-d-learn

On Monday, 8 January 2018 at 08:22:21 UTC, thedeemon wrote:

On Monday, 8 January 2018 at 07:37:31 UTC, Vino wrote:
 I tried to manipulate the writeln's as below but the output 
is not as expected as it prints the data in row wise, where 
as we need it in column wise.


Ah, sorry, now I think I get it.
Your problem is you get output like ["a","b","c"] and instead 
you want

a
b
c

right?

Well, I think you know how to write a loop and output one item 
per line inside this loop.


HI Deemon,

  Yes the output is required as below, and trying the same, but 
still no luck.

a
b
c

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Monday, 8 January 2018 at 05:38:44 UTC, thedeemon wrote:

On Sunday, 7 January 2018 at 17:30:26 UTC, Vino wrote:

 I tried to manipulate the writeln's as below but the output 
is not as expected as it prints the data in row wise, where as 
we need it in column wise.


You've said before you need 6 different files, not some tables.
Also, after the "compression" data columns will have different 
length. How exactly do you want to combine them into a table?


Hi Deemon,

  The output required is like this,

(1) Read a table data form the csv file

John, America,23
John, India, 22
Astro, Canada, 21

2) Sort and remove the duplicates from each column by column

Take a copy of each column and sort and remove the duplicates 
(col.dup) and store the resultant data of each column in seprate 
files like below.


Column 1 ( Store the data to text Datafille1)
Astro
John

Column 2 ( Store the data to text Datafille2)
America
Canada
India

Column 3 ( Store the data to text Datafille3)
21
22
23

Using the function countUntil find the keys for each of the 
column and store the result of each column in another files.


Key for column to text Keyfille1
original column1[].map!(v => Sorted Column1[].countUntil(v)) );

Key for column to text Keyfille2
original column2[].map!(v => Sorted Column2[].countUntil(v)) );

Key for column to text Keyfille3
original column3[].map!(v => Sorted Column3[].countUntil(v)) );


From,
Vino.B







Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Sunday, 7 January 2018 at 17:23:20 UTC, thedeemon wrote:

On Sunday, 7 January 2018 at 12:59:10 UTC, Vino wrote:
 Just noticed that the output writes the data and key as 2 
values , but the requirnment is to write to six files, e.g


That's the part you can implement yourself. Just replace those 
writelns with writing to corresponding files.


HI Deemon,

 I tried to manipulate the writeln's as below but the output is 
not as expected as it prints the data in row wise, where as we 
need it in column wise.


writeln(vk[0][0]);

Baker
America
18

From,
Vino.B


Column wise output

2018-01-07 Thread Vino via Digitalmars-d-learn

HI All,

  Request your help, in the below code the output from main 
(writeln(columns[0][])) function is like ["Miller", "John", 
"Millman", "Zsuwalski"] where as the writeln(col[0]) from the 
function master is as below, so how do i get the output same as 
in main from the function master.


CSV file content
Miller, America, 23
John, Africa, 42

Output from function master
Miller
America
23

alias ColumnTypes = AliasSeq!(string, string, int);

auto readData(string fName) {
auto uFile = File(fName, "r");
Tuple!( staticMap!(Array, ColumnTypes) ) res;
foreach (record; 
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!ColumnTypes)) {

foreach(i, T; ColumnTypes) { res[i].insert(record[i]); }
}
return res;
}

auto master(T)(ref Array!T col) {
writeln(col[0]);  // The output2 is  Miller
  //  America
   //23
}


void main() {
auto fName = 
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv";

auto columns = readData(fName);
writeln(columns[0][]);  // The output1 is ["Miller", "John"]
foreach(i, ColT; ColumnTypes) {
dictcompress(columns[i]);
}
}

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Sunday, 7 January 2018 at 12:09:32 UTC, Vino wrote:

On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:

On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:

[...]


Here's a version with Array, it's very similar:

import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta;
import std.file : readText;
import std.container.array;

[...]


Hi Deemon,

 Thank you very much, moving to second phase.

From,
Vino.B


Hi Deemon,

 Just noticed that the output writes the data and key as 2 values 
, but the requirnment is to write to six files, e.g


Data File 1
["Baker", "John", "Johnson", "Jones", "Miller", "Millers", 
"Millman", "Zsuwalski"]


Key File 1
[4, 1, 6, 7, 0, 4, 3, 4, 2, 1, 6, 5]

Data File 2
["America", "Austrilia", "Canada", "Chile", "China", "India", 
"Japan", "Netherlands"]


Key File 2
[0, 5, 1, 6, 4, 2, 1, 5, 7, 0, 4, 3]

Data File 3
[18, 21, 23, 42, 45]

Key File 3
[2, 3, 1, 4, 4, 2, 0, 1, 3, 3, 3, 2]

From,
Vino.B


Re: Passing Template to Function

2018-01-07 Thread Vino via Digitalmars-d-learn

On Saturday, 6 January 2018 at 15:26:30 UTC, Vino wrote:

Hi All,

 Request you help on the below program as it error out with the 
below error


[...]


Hi All,

 Thank you was able to resolve the issue.

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:

On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:

[...]


Here's a version with Array, it's very similar:

import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta;
import std.file : readText;
import std.container.array;

[...]


Hi Deemon,

 Thank you very much, moving to second phase.

From,
Vino.B


Passing Template to Function

2018-01-06 Thread Vino via Digitalmars-d-learn

Hi All,

 Request you help on the below program as it error out with the 
below error


Error:
UDictCompression.d(31): Error: template UDictCompression.compress 
cannot deduce function from argument types !()(string), 
candidates are:
UDictCompression.d(19):
UDictCompression.compress(T)(Array!T col)


Program:
import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta: AliasSeq;
import std.container.array;

alias ColumnTypes = AliasSeq!(string, string, int);
alias Arr(T) = Array!T;

auto readData() {
auto file = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv", "r");

Arr!(Tuple!ColumnTypes) res;
foreach (record; 
file.byLineCopy.joiner("\n").csvReader!(Tuple!ColumnTypes))

{ res.insertBack(record); } 
return res;
}

auto compress(T)(Array!T col) {
Arr!int ks; Array!T vals;
vals.insertBack(sort(col.dup[]).uniq);
ks.insertBack(col.map!(v => vals.countUntil(v)));
return tuple(vals, ks);
}

void main() {
auto columns = readData[];
foreach(r; columns)
{
foreach(i, ColT; ColumnTypes) {
auto vk = compress(r[i]);
writeln(vk[0][], vk[1][]);
}
}
}

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-06 Thread Vino via Digitalmars-d-learn

On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:

On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of 
tuples


Sorry, I meant tuple of arrays, of course.


Hi Deemon,

 Thank you very much, I tested your code, initially the code 
did not produce the expected output, and found an issue in the 
the key line of code as below, after updating the output was as 
expected. Can you please let me know how to change the array 
from standard array to container array.


auto ks = col.map!(v => col.countUntil(v)).array; // Your 
code(col.countUntil)
auto ks = col.map!(v => vals.countUntil(v)).array; // Changed 
code(vals.countUntil)


From,
Vino.B


Hi Deemon,

Was able to convert 50% of the code to container array and facing 
some issue


import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta: AliasSeq;
import std.container.array;

alias ColumnTypes = AliasSeq!(string, string, int);
alias Arr(T) = Array!T;

auto readData() {
auto file = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv", "r");

Arr!(Tuple!ColumnTypes) res;
foreach (record; 
file.byLineCopy.joiner("\n").csvReader!(Tuple!ColumnTypes))

{ res.insertBack(record); } 
return tuple(res[]);   // replace this line with writeln(res[]); 
gives the expected output

}

auto compress(T)(Array!T col) {
Arr!int ks; Array!T vals;
vals.insertBack(sort(col.dup[]).uniq);
ks.insertBack(col.map!(v => vals.countUntil(v)));
return tuple(vals, ks);
}

void main() {
   auto columns = readData();
   foreach(i, ColT; ColumnTypes) {   //Facing some 
issue at this point

auto vk = compress(columns[i]);
writeln(vk[0][], vk[1][]);
}
}


From,
Vino.B



Re: Error: variable i cannot be read at compile time

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of 
tuples


Sorry, I meant tuple of arrays, of course.


Hi Deemon,

 Thank you very much, I tested your code, initially the code did 
not produce the expected output, and found an issue in the the 
key line of code as below, after updating the output was as 
expected. Can you please let me know how to change the array from 
standard array to container array.


auto ks = col.map!(v => col.countUntil(v)).array; // Your 
code(col.countUntil)
auto ks = col.map!(v => vals.countUntil(v)).array; // Changed 
code(vals.countUntil)


From,
Vino.B


Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn
On Friday, 5 January 2018 at 16:55:50 UTC, Steven Schveighoffer 
wrote:

On 1/5/18 11:39 AM, Vino wrote:


Hi Steve,

  if we add the braces we are getting the Error: undefined 
identifier Datacol


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
 {
     typeof(read()[i]) Datacol;
     Datacol.insertBack(sort(read[i].dup[]).uniq);
     foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

 }
}
 writeln (Datacol[], Keycol[]);
}


That's because writeln is outside the loop that defines Datacol.

Without knowing what you are trying to do, it's hard to further 
help.


-Steve


Hi Steve,

 Thank you very much, was able to resolve the issue after adding 
the writeln within the braces, I am trying to implement a data 
dictionary compressing using D, and had 2 issue and this is one 
of the issue, and the other issue is detailed in the post "Error: 
variable i cannot be read at compile time", which contains the 
details of this program, if possible can you please help on on 
the other issue in the post "Error: variable i cannot be read at 
compile time".


From,
Vino.B




Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn
On Friday, 5 January 2018 at 16:07:49 UTC, Steven Schveighoffer 
wrote:

On 1/5/18 10:56 AM, Vino wrote:
On Friday, 5 January 2018 at 15:28:58 UTC, Jonathan M Davis 
wrote:
On Friday, January 05, 2018 15:22:49 Vino via 
Digitalmars-d-learn wrote:

Hi All,

  Request your help on how to unset or delete an array, in 
the

below example, we get an error "Common  is already defined".

Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


static foreach does not create a new scope (if it did, it 
wouldn't work very well at module or class/struct scope). If 
you declare any variables inside a static foreach, give it an 
extra set of braces.


- Jonathan m Davis


Hi Jonathan,

  Sorry , not able to get you, can you please point our as to 
where we need to added the braces in the below example.


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {

{

typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

}

}
writeln (Datacol[], Keycol[]);
}



-Steve


Hi Steve,

 if we add the braces we are getting the Error: undefined 
identifier Datacol


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
{
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
		foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));}

}
}
writeln (Datacol[], Keycol[]);
}

From,
Vino.B


Re: Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 15:28:58 UTC, Jonathan M Davis wrote:
On Friday, January 05, 2018 15:22:49 Vino via 
Digitalmars-d-learn wrote:

Hi All,

  Request your help on how to unset or delete an array, in the
below example, we get an error "Common  is already defined".

Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


static foreach does not create a new scope (if it did, it 
wouldn't work very well at module or class/struct scope). If 
you declare any variables inside a static foreach, give it an 
extra set of braces.


- Jonathan m Davis


Hi Jonathan,

 Sorry , not able to get you, can you please point our as to 
where we need to added the braces in the below example.


void main () {
Array!int Keycol;
static foreach(i; 0 .. 3) {
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { 
Keycol.insertBack(Datacol[].countUntil(k));} }

writeln (Datacol[], Keycol[]);
}

From,
Vino.B


Array is already defined

2018-01-05 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help on how to unset or delete an array, in the 
below example, we get an error "Common  is already defined".


Auto fn1 () {
Array!string Text;
Array!string Number;
return tuple(Text, Number);
}

Void main () {
static foreach(i; 0 .. 2) {
typeof(fn1()[i]) Common;
writeln(Common[]);
Common.delete or Common.Unset // Something similar like this
}

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 13:09:25 UTC, Vino wrote:

On Friday, 5 January 2018 at 12:47:39 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 12:40:41 UTC, Vino wrote:

What exactly are you trying to do in Master()?

  Please find the full code,


Sorry, I'm asking what problem are you solving, what the 
program should do, what is its idea. Not what code you have 
written.


Hi,

I am trying to implement data dictionary compression, and below 
is the function of the program,


Function read:
This function read a csv file which contains 3 column as and 
stores the value of each column in an array Col1: Array1 
(Ucol1), Col2: Array2 (Ucol2), Col3: Array3(Ucol3) and returns 
the data.


CSV file content:
Miller  America 23
JohnIndia   42
Baker   Australia   21
Zsuwalski   Japan   45
Baker   America 45
Miller  India   23

Function Main
This function receives the data from the function read.
Creates an array based of the function return type – ( 
typeof(read()[i]) Data );
Sorts the data and removes the duplicates and stores the data 
in the above array.
Then using “countUntil” function we can accomplish the data 
dictionary compression.


Result
The above file will be stored as
Data File:
Data-Col1.txt which contains [Baker, John, Miller, Zsuwalski]
Data-Col2.txt which contains [America, Australia , India, Japan]
Data-Col3.txt which contains [21, 23, 42, 45]

Index File:
Index-Col1.txt which contains [2, 1, 0, 3, 0, 2]
Index -Col2.txt which contains [0, 2, 1, 3, 0, 2]
Index -Col3.txt which contains [1, 2, 0, 3, 3, 1]

The program works for a single column.

From,
Vino.B


More Info:

If we change the below line
static foreach(i; 0 .. 1)
Output: ["Baker", "John", "Miller", "Zsuwalski"][2, 1, 0, 3, 0, 2]

static foreach(i; 1 .. 2)
["America", "Austrilia", "India", "Japan"][0, 2, 1, 3, 0, 2])

static foreach(i; 2 .. 3)
[21, 23, 42, 45][1, 2, 0, 3, 3, 1]

Instead of manually chaning the values I used the variable Size 
where the value of the Size if from the read function (read[3] ) 
where read[3] is rSize = record.length;


If I use the variable Size as static foreach(i; 0 .. Size) I am 
getting an error : “Error: variable Size cannot be read at 
compile time”.


From,
Vino.B



Re: Error: variable i cannot be read at compile time

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 12:47:39 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 12:40:41 UTC, Vino wrote:

What exactly are you trying to do in Master()?

  Please find the full code,


Sorry, I'm asking what problem are you solving, what the 
program should do, what is its idea. Not what code you have 
written.


Hi,

I am trying to implement data dictionary compression, and below 
is the function of the program,


Function read:
This function read a csv file which contains 3 column as and 
stores the value of each column in an array Col1: Array1 (Ucol1), 
Col2: Array2 (Ucol2), Col3: Array3(Ucol3) and returns the data.


CSV file content:
Miller  America 23
JohnIndia   42
Baker   Australia   21
Zsuwalski   Japan   45
Baker   America 45
Miller  India   23

Function Main
This function receives the data from the function read.
Creates an array based of the function return type – ( 
typeof(read()[i]) Data );
Sorts the data and removes the duplicates and stores the data in 
the above array.
Then using “countUntil” function we can accomplish the data 
dictionary compression.


Result
The above file will be stored as
Data File:
Data-Col1.txt which contains [Baker, John, Miller, Zsuwalski]
Data-Col2.txt which contains [America, Australia , India, Japan]
Data-Col3.txt which contains [21, 23, 42, 45]

Index File:
Index-Col1.txt which contains [2, 1, 0, 3, 0, 2]
Index -Col2.txt which contains [0, 2, 1, 3, 0, 2]
Index -Col3.txt which contains [1, 2, 0, 3, 3, 1]

The program works for a single column.

From,
Vino.B



Re: Error: variable i cannot be read at compile time

2018-01-05 Thread Vino via Digitalmars-d-learn

On Friday, 5 January 2018 at 12:10:33 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 09:09:00 UTC, Vino wrote:
  Thank you very much, can you suggest the best way around 
this issue.


What exactly are you trying to do in Master()? The code seems 
very broken. Each time you write read[i] is will call read() 
and read the whole file, you're going to read the file so many 
times in this code. I don't think that was the intent.


Hi,

  Please find the full code, the below code will read a 
ColRead.csv file which contains the below entry


Miller  America 23
JohnIndia   42
Baker   Austrilia   21
Zsuwalski   Japan   45
Baker   America 45
Miller  India   23


import std.algorithm: countUntil, joiner, sort, uniq;
import std.container.array;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;

auto read (){
Array!string Ucol1, Ucol2; Array!int Ucol3; int rSize;
auto file = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\ColRead.csv", "r");
foreach (record; 
file.byLineCopy.joiner("\n").csvReader!(Tuple!(string, string, 
int)))
{ Ucol1.insertBack(record[0]); Ucol2.insertBack(record[1]); 
Ucol3.insertBack(record[2]); rSize = record.length; }

return tuple(Ucol1, Ucol2, Ucol3, rSize);
}

void main () {
Array!int Key;
int Size = read[3];
static foreach(i; 0 .. Size) {
typeof(read()[i]) Data;
Data.insertBack(sort(read[0].dup[]).uniq);
foreach(i; read[i]) { Key.insertBack(Data[].countUntil(i)); } }
 }



Re: Error: variable i cannot be read at compile time

2018-01-05 Thread Vino via Digitalmars-d-learn

On Thursday, 4 January 2018 at 18:49:21 UTC, Ali Çehreli wrote:

On 01/04/2018 08:51 AM, Vino wrote:

> auto read () {
[...]
> return tuple(Ucol1, Ucol2, Ucol3, rSize);
> }

read() returns a tuple of values of different types.

> for(int i = 0; i < Size; i++) {
> typeof(read()[i]) Datacol;

typeof is a compile-time expression but there cannot be a 
consistent result to that expression when i is not known at 
compile-time.


You might try using a 'static foreach' but this time Size is 
not a compile-time expression:


static foreach(i; 0 .. Size) {
typeof(read()[i]) Datacol;

Error: variable Size cannot be read at compile time

Ali


Hi Ali,

  Thank you very much, can you suggest the best way around this 
issue.


From,
Vino.B


Error: variable i cannot be read at compile time

2018-01-04 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help on the below error for the below program.

Error:
CReadCol.d(20): Error: variable i cannot be read at compile time
CReadCol.d(21): Error: variable i cannot be read at compile time
CReadCol.d(22): Error: variable i cannot be read at compile time


Program
import std.algorithm: joiner, sort, countUntil, uniq;
import std.container.array;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;

auto read () {
Array!string Ucol1, Ucol2;
Array!int Ucol3;
int rSize;
auto file = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\ColRead.csv", "r");
foreach (record; 
file.byLineCopy.joiner("\n").csvReader!(Tuple!(string, string, 
int)))
{ Ucol1.insertBack(record[0]); Ucol2.insertBack(record[1]); 
Ucol3.insertBack(record[2]); rSize = record.length; }

return tuple(Ucol1, Ucol2, Ucol3, rSize);
}
/***/
auto Master (int Size) {
Array!int Keycol;
for(int i = 0; i < Size; i++) {
typeof(read()[i]) Datacol;
Datacol.insertBack(sort(read[i].dup[]).uniq);
foreach(k; read[i]) { Keycol.insertBack(Datacol[].countUntil(k)); 
} }

return tuple (Datacol[], Keycol[]);
}

void main () {
int Size = read[3];
writeln(Master(Size));
}

From,
Vino.B


Re: Single type of a tuple return type function

2018-01-04 Thread Vino via Digitalmars-d-learn

On Thursday, 4 January 2018 at 16:09:07 UTC, Simen Kjærås wrote:

On Thursday, 4 January 2018 at 15:50:35 UTC, Vino wrote:

[...]


ReturnType!Fn[0] tries to give you the 0th field of the tuple, 
but as the error message indicates, you can't do that without 
an instance. What you want is the *type* of the field, as given 
by typeof:


typeof(ReturnType!Fn[0]) Dcol;

This can be made a bit simpler by noticing that ReturnType is 
unnecessary here:


typeof(Fn()[0]) Dcol;

However, if Fn() takes a bunch of complex parameters, this 
might not actually be simpler.


--
  Simen


HI Simen,

 Thank you very much, your solution was helpful.

From,
Vino.B


Single type of a tuple return type function

2018-01-04 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, on how o find the single type of a tuple 
return type function, eg,


auto Fn (){
Array!string a;
Array!int b;
Array!ulong c;
return tuple(a, b, c);
}

if we use "ReturnType!Fn" it gives us the output as 
(Array!string,Array!int, Array!ulong) but what is need is the 
return type of  each of the value as

a = Array!string; b = Array!int; c = Array!ulong

void main () {
ReturnType!Fn[0] Dcol;  //similar like this line
writeln(Dcol[]);
}

From,
Vino.B


Re: Finding unsafe line of code

2018-01-01 Thread Vino via Digitalmars-d-learn

On Friday, 29 December 2017 at 10:33:16 UTC, Johan Engelen wrote:

On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote:

On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote:


  Let me re-frame the question with an example, as the Dsafe 
the below line of code is considered as unsafe(Pointer 
arithmetic),

...


ini[10] a;
int* p = [0];
for (size_t i=0; i <= 10; i++)
p[i] = ...;

From,
Vino.B


Is this what you're looking for?

https://dlang.org/spec/function.html#safe-functions

Just annotate your functions with @safe (as @system is the 
default).


Or if that's not possible, you can add runtime checks with 
ASan: 
http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html


-Johan


Hi,

  Tried to install LDC on Windows 7, but getting the below errors 
while compiling


Installed s/w
.Net 4.7.1
.Net Core Runtime 2.0.4
.Net SDK 2.1.3
Windows SDK 10.0.16299.15

Environment Variables Set:

NETFXSDKDir = C:\Program Files (x86)\Windows 
Kits\10\Lib\10.0.16299.0\um\x86(System/User)
LDC_VSDIR = C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Community(System)


Error:
C:\Users\bheev1\Desktop\Current\Script\Complied-64>ldc2 
-fsanitize=address -g nscleaner.d

LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'
Error: C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\HostX64\x64\link.exe failed with status: 1181


From,
Vino.B


Re: Finding unsafe line of code

2017-12-29 Thread Vino via Digitalmars-d-learn

On Friday, 29 December 2017 at 09:19:13 UTC, codephantom wrote:

On Friday, 29 December 2017 at 08:21:10 UTC, Vino wrote:

Hi All,

Is there a way to find or test which line of a give code is 
not safe(possible memory corruption).



From,
Vino.B


That question needs to be refined ;-)


Hi,

  Let me re-frame the question with an example, as the Dsafe the 
below line of code is considered as unsafe(Pointer arithmetic), 
so let imagine that we have several similar line of code, how do 
we find such unsafe line, does the compiler check these unsafe 
code and complain while compiling a .d program or do we need to 
pass any compiler arguments to perform these check while 
compiling the code or do we need to manually perform an analysis 
of each line of code and correct the same in case if we find any 
unsafe code.



ini[10] a;
int* p = [0];
for (size_t i=0; i <= 10; i++)
p[i] = ...;

From,
Vino.B


Finding unsafe line of code

2017-12-29 Thread Vino via Digitalmars-d-learn

Hi All,

Is there a way to find or test which line of a give code is not 
safe(possible memory corruption).



From,
Vino.B


Difference in reduce in std and mir

2017-12-26 Thread Vino via Digitalmars-d-learn

Hi All,

What is the difference between std.algorithm.reduce and 
mir.ndslice.algorithm.reduce.




From,
Vino.B


Re: Fold in Parallelism

2017-12-21 Thread Vino via Digitalmars-d-learn

On Friday, 22 December 2017 at 00:18:40 UTC, Seb wrote:

On Friday, 22 December 2017 at 00:12:45 UTC, Vino wrote:
On Thursday, 21 December 2017 at 06:31:52 UTC, Ali Çehreli 
wrote:

[...]


Hi Ali,

Thank you very much, the pull request is in open state, so can 
you please let me know when can we can test the same.


From,
Vino.B


It will take a couple of days for this pull request to reach a 
ready form and to be approved. The best way to help it to move 
forward is to review it yourself or at least vote for it on 
GitHub ;-)
Once merged it will appear on dmd-nightly on the next day, but 
I'm not sure why you depend on his pull request?

Can't you just use the code directly?


Hi Seb,

  I am fine waiting for a couple of days for this pull request to 
reach to teh ready form and approved. Sure will vote on GItHub.


From,
Vino.B


Re: Fold in Parallelism

2017-12-21 Thread Vino via Digitalmars-d-learn

On Thursday, 21 December 2017 at 06:31:52 UTC, Ali Çehreli wrote:

On 12/19/2017 02:32 AM, Vino wrote:

> even though it is a simple code copy+paste

The change was a little more complicated than my naive 
adaptation from std.algorithm.fold. Here is the pull request:


  https://github.com/dlang/phobos/pull/5951

Ali


Hi Ali,

Thank you very much, the pull request is in open state, so can 
you please let me know when can we can test the same.


From,
Vino.B


Re: No of threads

2017-12-21 Thread Vino via Digitalmars-d-learn

On Thursday, 21 December 2017 at 00:32:50 UTC, codephantom wrote:

On Wednesday, 20 December 2017 at 13:41:06 UTC, Vino wrote:


Hi Ali,

 Thank you very much, below are the observations, our program 
is used to calculate the size of the folders, and we don't see 
any improvements in the execution speed from the below test, 
are we missing something. Basically we expected the total 
execution time for the test 2 , as the time taken to calculate 
the size of the biggest folder + few additional mins, the 
biggest folder size is of 604 GB.  Memory usage is just 12 MB, 
whereas the server has 65 GB and hardly 30% - 40% is used at 
any given point in time, so there is no memory constrain.




Are you running this over the network, or on (each) server that 
contains the actual folders?


Hi,

  Yes, the file system used is a NetApp file system mapped on 
Windows server.


From,
Vino.B


Re: No of threads

2017-12-21 Thread Vino via Digitalmars-d-learn

On Wednesday, 20 December 2017 at 17:31:20 UTC, Ali Çehreli wrote:

On 12/20/2017 05:41 AM, Vino wrote:

> auto TL = dFiles.length;
> auto TP = new TaskPool(TL);

I assume dFiles is large. So, that's a lot of threads there.

> foreach (d; TP.parallel(dFiles[],1))

You tried with larger work unit sizes, right? More importantly, 
I think all these threads are working on the same disk. If the 
access is serialized by the OS or a lower entity, then all 
threads necessarily wait for each other, making the whole 
exercise serial.


> auto SdFiles = Array!ulong(dirEntries(d,
SpanMode.depth).map!(a =>
> a.size).fold!((a,b) => a + b) (x))[].filter!(a => a  > Size);
> Thread.sleep(5.seconds);

You don't need that at all. I had left it in there just to give 
me a chance to examine the number of threads the program was 
using.


Ali


Hi Ali,

Below are the answers.

"I think all these threads are working on the same disk. If the 
access is serialized by the OS or a lower entity, then all 
threads necessarily wait for each other, making the whole  
exercise serial."


   The File system that is used here to scan and find the folder 
size is an NetApp File system mapped on Windows 2008. The file 
system is exported using NFS v3 so you are right that the disk 
access is serialized.


The no of folders are from 2 NetApp file system and no of folders 
in each file system is as below


File system 1 : 76 folders and File system 2: 77 folders.

You don't need that at all. I had left it in there just to give 
me a chance to examine the number of threads the program was 
using.


We have not update your main code yet, it was a test that we 
performed on test server.


From,
Vino.B


Re: No of threads

2017-12-20 Thread Vino via Digitalmars-d-learn

On Tuesday, 19 December 2017 at 18:42:01 UTC, Ali Çehreli wrote:

On 12/19/2017 02:24 AM, Vino wrote:
> Hi All,
>
>Request your help in clarifying the below. As per the
document
>
> foreach (d; taskPool.parallel(xxx)) : The total number of
threads that
> will be created is total CPU -1 ( 2 processor with 6 core :
11 threads)
>
> foreach (d; taskPool.parallel(xxx,1)) : The total number of
threads that
> will be created is total CPU -1 ( 2 processor with 6 core :
12 threads)

That parameter is workUnitSize, meaning the number of elements 
each thread will process per work unit. So, when you set it to 
100, each thread will work on 100 elements before they go pick 
more elements to work on. Experiment with different values to 
find out which is faster for your work load. If each element 
takes very short amount of time to work on, you need larger 
values because you don't want to stop a happy thread that's 
chugging along on elements. It really depends on each program, 
so try different values.


> foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008
whatever
> value is set for the parallel the total number of threads
does not
> increase more than 12.

taskPool is just for convenience. You need to create your own 
TaskPool if you want more threads:


import std.parallelism;
import core.thread;
import std.range;

void main() {
auto t = new TaskPool(20);
foreach (d; t.parallel(100.iota)) {
// ...
}
Thread.sleep(5.seconds);
t.finish();
}

Now there are 20 + 1 (main) threads.

Ali


Hi Ali,

 Thank you very much, below are the observations, our program is 
used to calculate the size of the folders, and we don't see any 
improvements in the execution speed from the below test, are we 
missing something. Basically we expected the total execution time 
for the test 2 , as the time taken to calculate the size of the 
biggest folder + few additional mins, the biggest folder size is 
of 604 GB.  Memory usage is just 12 MB, whereas the server has 65 
GB and hardly 30% - 40% is used at any given point in time, so 
there is no memory constrain.



Test 1:
foreach (d; taskPool.parallel(dFiles[],1))
auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a 
=> a.size).fold!((a,b) => a + b) (x))[].filter!(a => a  > Size);


Execution Time is 26 mins with 11+1 (main) threads and 1 element 
per thread


Test 2:
auto TL = dFiles.length;
auto TP = new TaskPool(TL);
foreach (d; TP.parallel(dFiles[],1))
auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a 
=> a.size).fold!((a,b) => a + b) (x))[].filter!(a => a  > Size);

Thread.sleep(5.seconds); TP.finish();

Execution Time is 27 mins with 153+1 (main) threads and 1 element 
per thread



From,
Vino.B


Re: No of threads

2017-12-19 Thread Vino via Digitalmars-d-learn

On Tuesday, 19 December 2017 at 11:03:27 UTC, codephantom wrote:

On Tuesday, 19 December 2017 at 10:24:47 UTC, Vino wrote:


foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 
whatever value is set for the parallel the total number of 
threads does not increase more than 12.


So not sure if this is correct, so can any one explain me on 
same.




something to do with your cacheLineSize perhaps?


There are other process running on the same server which use 200+ 
threads which means the server is capable of running more that 
200+ threads, as i suspect is ti something to do with TaskPool


From,
Vino.B


Re: Fold in Parallelism

2017-12-19 Thread Vino via Digitalmars-d-learn

On Monday, 18 December 2017 at 20:53:28 UTC, Russel Winder wrote:

Ali,

Shouldn't this be a pull request for std.parallelism to be 
extended?


If the function is in std.algorithm, then people should not 
have to write it for themselves in std.parallelism.



On Mon, 2017-12-18 at 11:01 -0800, Ali Çehreli via 
Digitalmars-d-learn wrote:

[...]

[…]

[...]


Hi Ali,

  Sorry, I would like to echo the statement from Russel, as an 
user(newbie) I personally do not want to fiddle around the 
libraries even though it is a simple code copy+paste, as this 
might cause some serious issue  in case if anything went wrong, 
so i would like to leave it to expert's like you to help us. If 
possible can we added this to the next release (78).


From,
Vino.B.


No of threads

2017-12-19 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help in clarifying the below. As per the document

foreach (d; taskPool.parallel(xxx)) : The total number of threads 
that will be created is total CPU -1 ( 2 processor with 6 core : 
11 threads)


foreach (d; taskPool.parallel(xxx,1)) : The total number of 
threads that will be created is total CPU -1 ( 2 processor with 6 
core : 12 threads)


So if I increase the parallel process by any number what would be 
the no of threads that would be created


foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 
whatever value is set for the parallel the total number of 
threads does not increase more than 12.


So not sure if this is correct, so can any one explain me on same.


From,
Vino.B




Re: Fold in Parallelism

2017-12-18 Thread Vino via Digitalmars-d-learn

On Sunday, 17 December 2017 at 20:00:53 UTC, Ali Çehreli wrote:

On 12/17/2017 08:11 AM, Vino wrote:

>   As per the document form std.parallelism it states that we
can use
> taskPool.reduce so can we use the same for fold
(taskPool.fold) as
> basically both are same with slight variation on seed values,
if
> possible can can we define the same in the below lines

fold has only been added to std.algorithm. Opened an 
enhancement request:


  https://issues.dlang.org/show_bug.cgi?id=18096

Ali


Hi Ali,

  Thank you very much, may we know if possible as to when this 
would be added.


From,
Vino.B


Re: Dynamic Array reserve

2017-12-17 Thread Vino via Digitalmars-d-learn

On Sunday, 17 December 2017 at 00:45:06 UTC, Ali Çehreli wrote:

On 12/16/2017 03:58 PM, Steven Schveighoffer wrote:


[...]


I was going to suggest the same to Vino and I was writing the 
following program to demonstrate how low the number of 
allocations is.


[...]


Hi Steven /Ali,

  Initially we use the native array and we observed the execution 
time was higher so we  then we changed all the native array to 
container array and we were able to see some performance gain, 
the memory usage is not a constrain for us, are main goal is how 
fast the program can perform. Please let me know your thoughts on 
the same.


From,
Vino.B






Fold in Parallelism

2017-12-17 Thread Vino via Digitalmars-d-learn

HI All,

 As per the document form std.parallelism it states that we can 
use taskPool.reduce so can we use the same for fold 
(taskPool.fold) as basically both are same with slight variation 
on seed values, if possible can can we define the same in the 
below lines


Tried the below but getting an error
auto SdFiles = Array!ulong(dirEntries("C:\\TEMP\\BACKUP", 
SpanMode.depth).map!(a => a.size).taskPool.fold!((a,b) => a + b) 
(x))[];
Error : Srvnscleaner.d(89): Error: function 
std.parallelism.taskPool () is not callable using argument types 
(MapResult!(__lambda2, DirIterator))


auto SdFiles = Array!ulong(dirEntries("C:\\TEMP\\BACKUP", 
SpanMode.depth).map!(a => a.size).fold!((a,b) => a + b) 
(x)).taskPool[];


Error : Size.d(89): Error: function std.parallelism.taskPool () 
is not callable using argument types (Array!ulong)



From,
Vino.B


Re: Dynamic Array reserve

2017-12-16 Thread Vino via Digitalmars-d-learn
On Saturday, 16 December 2017 at 16:46:49 UTC, Jacob Carlborg 
wrote:

On 2017-12-16 15:11, Vino wrote:

Hi All,

  Request your help on reserve an dynamic array when the 
capacity is reached to a point(eg: 80%) so the array to extend 
the reserve by next 20%


Example:
Array!string Test;
Test. reserve(100) - Initall
Test =(.) - The number of entries are dynamic
if (array.capacity > 80%) { array.reserve(100+20%)


There's a "capacity" property which you can use. Compare that 
to the length of the array to know when it has reach 80%.


Hi Jacob,

  Thank you , yes we can use the length property and calculate 
the capacity, but the question is how to implement it 
dynamically, so let me explain a bit further.


1> Let assume that an array named Size is defined
string ConfigFile = "Test.txt"  //The size of the file is not 
known.

Array!string Size

2> Reserve the size of the array Test.
Size.reserve(100) //Initial allocation

3> Appending data
Size = File(ConfigFile).byLineCopy();

4> Let us assume the file Test.txt   contains 50,000 lines.

5> As per step 2 we have reserved the array to 100 which means 
that the array can hold 100 lines.


6> Check for every 1 mins if the length of the array(Size) is 
above 80(lines), then increase the reservation of the array by 
20, Size.reserve = (Size.capacity + 20).


7> Step 3 and Step 6 should be running parallel

8> Once step 3 is completed Step 6 should also be ended.

From,
Vino.B






Re: Array Template

2017-12-16 Thread Vino via Digitalmars-d-learn

On Saturday, 16 December 2017 at 06:42:53 UTC, codephantom wrote:

On Friday, 15 December 2017 at 17:21:55 UTC, Vino wrote:

Hi All,

  Request your help, Is it possible to an template array 
something similar as below so that we can insert any type of 
value(string, int etc). If possible can you provide me a 
example of how to define such array.


Array!(Tuple!(T n))

From,
Vino.B


Do you  mean 'an array of variable types of tuples'.

If so...good luck with that ;-)


Yes, will give a try.

From,
Vino.B


Dynamic Array reserve

2017-12-16 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help on reserve an dynamic array when the capacity 
is reached to a point(eg: 80%) so the array to extend the reserve 
by next 20%


Example:
Array!string Test;
Test. reserve(100) - Initall
Test =(.) - The number of entries are dynamic
if (array.capacity > 80%) { array.reserve(100+20%)


From,
Vino.B




Re: weird exception on windows

2017-12-16 Thread Vino via Digitalmars-d-learn

On Saturday, 16 December 2017 at 13:59:11 UTC, Vino wrote:

On Saturday, 16 December 2017 at 12:39:53 UTC, Kagamin wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


Regression in 2.072?


H, All,

  Are are also getting the same exception on Windows after 
updating the dmd to version v2.077.1, our code was working fine 
for the past 2 months, the exception is just crashes the 
program, and it occur's every 1 time  among in 3 runs. As per 
Microsoft it stated to download the package apps.diagcab and 
execute, but still no luck.


ExceptionCode: C005

From,
Vino.B


Moreover we were able to find the line of code which was causing 
this exception


string a = "1"
a.to!int.isNumber /* exception is occurring at this point.

From,
Vino.B


Re: weird exception on windows

2017-12-16 Thread Vino via Digitalmars-d-learn

On Saturday, 16 December 2017 at 12:39:53 UTC, Kagamin wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


Regression in 2.072?


H, All,

  Are are also getting the same exception on Windows after 
updating the dmd to version v2.077.1, our code was working fine 
for the past 2 months, the exception is just crashes the program, 
and it occur's every 1 time  among in 3 runs. As per Microsoft it 
stated to download the package apps.diagcab and execute, but 
still no luck.


ExceptionCode: C005

From,
Vino.B


Defining an Array

2017-12-16 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help for the below as how do i add an item to a 
array in the array is defined as Type 2.




Type 1: Working
import std.conatiner.array;
void main () {
auto PStore = Array!(string)("Test1", "Test1")
}

Type 2: not working
import std.conatiner.array;
void main () {
Array!(string) PStore;
PStore = ("Test1", "Test1"); or
PStore ~= ("Test1", "Test1"); or
PStore.insertBack("Test1", "Test1");
}

From,
Vino.B


database or disk is full ; Error while posting message in this D forum

2017-12-15 Thread Vino via Digitalmars-d-learn

Hi All,

 We are getting the above error message while posting any message 
in this forum, can any look into this please.




Re: Tuple Array Sorting

2017-12-15 Thread Vino via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 19:00:01 UTC, Biotronic wrote:

On Tuesday, 12 December 2017 at 15:19:35 UTC, Vino wrote:

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
	auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name, a.timeCreated)));

foreach(e; dFiles) { Result ~= e; } }
writefln("%(%-(%-63s %.20s %)\n%)", Result[].sort!((a, b) 
=> a[1] < b[1]));

}


Since there's little need to extract timeCreated and name 
before sorting, here's a version that doesn't:


import std.algorithm : map, filter, sort;
import std.array : array;
import std.range : join;
import std.file : SpanMode, dirEntries, isDir;
import std.stdio : writefln;
import std.typecons : tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


auto sorted = folders
.map!(f => f.dirEntries(SpanMode.shallow))
.join
.filter!(e => e.isDir)
.array
.sort!((a,b) => a.timeCreated < b.timeCreated)
.map!(e => tuple(e.name, e.timeCreated.toSimpleString[0 
.. 20]));


writefln("%(%-(%-63s %s %)\n%)", sorted);
}

And a version with normal loops, since the heavily range-based 
version above can be a bit dense. These programs do essentially 
the same thing:


import std.algorithm : sort;
import std.array : array;
import std.file : SpanMode, dirEntries, DirEntry, isDir;
import std.stdio : writefln;
import std.typecons : tuple, Tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


DirEntry[] subFolders;

foreach (folder; folders) {
auto children = dirEntries(folder, SpanMode.shallow);
foreach (child; children) {
if (child.isDir) subFolders ~= child;
}
}

subFolders.sort!((a,b) => a.timeCreated < b.timeCreated);
Tuple!(string, string)[] interestingParts;

foreach (subFolder; subFolders) {
interestingParts ~= tuple(subFolder.name, 
subFolder.timeCreated.toSimpleString[0..20]);

}

writefln("%(%-(%-63s %s %)\n%)", interestingParts);
}

As you can see, I'm just chopping off the parts I don't like 
from toSimpleString. It seems a good format function for dates 
does not exist in Phobos.


--
  Biotronic


Hi Biotronic,

 I was able to find a solution using container array and also 
date formatting, below is the code, please do let me know if you 
find any issue, as i have tested the script and it is working as 
expected.


Program:
import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Array Template

2017-12-15 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, Is it possible to an template array 
something similar as below so that we can insert any type of 
value(string, int etc). If possible can you provide me a example 
of how to define such array.


Array!(Tuple!(T n))

From,
Vino.B


Re: Tuple Array Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 19:00:01 UTC, Biotronic wrote:

On Tuesday, 12 December 2017 at 15:19:35 UTC, Vino wrote:

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
	auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name, a.timeCreated)));

foreach(e; dFiles) { Result ~= e; } }
writefln("%(%-(%-63s %.20s %)\n%)", Result[].sort!((a, b) 
=> a[1] < b[1]));

}


Since there's little need to extract timeCreated and name 
before sorting, here's a version that doesn't:


import std.algorithm : map, filter, sort;
import std.array : array;
import std.range : join;
import std.file : SpanMode, dirEntries, isDir;
import std.stdio : writefln;
import std.typecons : tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


auto sorted = folders
.map!(f => f.dirEntries(SpanMode.shallow))
.join
.filter!(e => e.isDir)
.array
.sort!((a,b) => a.timeCreated < b.timeCreated)
.map!(e => tuple(e.name, e.timeCreated.toSimpleString[0 
.. 20]));


writefln("%(%-(%-63s %s %)\n%)", sorted);
}

And a version with normal loops, since the heavily range-based 
version above can be a bit dense. These programs do essentially 
the same thing:


import std.algorithm : sort;
import std.array : array;
import std.file : SpanMode, dirEntries, DirEntry, isDir;
import std.stdio : writefln;
import std.typecons : tuple, Tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


DirEntry[] subFolders;

foreach (folder; folders) {
auto children = dirEntries(folder, SpanMode.shallow);
foreach (child; children) {
if (child.isDir) subFolders ~= child;
}
}

subFolders.sort!((a,b) => a.timeCreated < b.timeCreated);
Tuple!(string, string)[] interestingParts;

foreach (subFolder; subFolders) {
interestingParts ~= tuple(subFolder.name, 
subFolder.timeCreated.toSimpleString[0..20]);

}

writefln("%(%-(%-63s %s %)\n%)", interestingParts);
}

As you can see, I'm just chopping off the parts I don't like 
from toSimpleString. It seems a good format function for dates 
does not exist in Phobos.


--
  Biotronic


Hi Biotronic,

 I was able to find a solution using container array and also 
date formatting, below is the code, please do let me know if you 
find any issue, as i have tested the script and it is working as 
expected.


Program:
import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Re: Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 15:58:40 UTC, Vino wrote:

On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document 
or example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B


HI All,

  As per the message from the below forum  I understand that 
that we cannot perform a sorting on filtered result a container 
array but the same can be performed form the standard array, so 
i adjusted the above code as below and getting a different 
error than what is discussed in the forum.


Forum:
 
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org;


Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)))[]

.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function 
Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, 
SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is 
not callab

le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B


Hi All,

 Was able to find a solution and it is working as expected

import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Re: Date Formating

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 17:16:46 UTC, Vino wrote:
On Wednesday, 13 December 2017 at 08:32:34 UTC, codephantom 
wrote:

[...]


Hi All,

[...]


Hi All, Thank you very much , was able to resolve the issue by 
changing the writefln line as below.


Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));


From,
Vino.B


Re: Date Formating

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 08:32:34 UTC, codephantom wrote:
On Wednesday, 13 December 2017 at 07:35:40 UTC, Jonathan M 
Davis wrote:
In general, you probably want to cast the SysTime to a 
DateTime if you're going to do something like that.


yes, I would agree ;-)

Of course the intention was not really to just format it the 
same way as Clock.currTime() does it, but rather to provide a 
way to more easily customise the format, however one likes, 
whenever one likes..


e.g.the following small change to the format string would make 
it return: 20171213_1924_41


(that's more like something I'd use)

  return
format("%04s%02s%02s_%02s%02s_%02s",
(d.year),
to!(int)(d.month),
(d.day),
(d.hour),
(d.minute),
(d.second)
);


Hi All,

 Request your help on below program on how to format or cast 
SysTime to DateTime


import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
writefln("%(%-(%-63s %s %)\n%)", Sorted[].sort!((a,b) => a[1] < 
b[1]));

}
}

Output:
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00.7037169
C:\Temp\BACKUP\DND5 
2017-Sep-05 14:31:00.750517
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00.8909172
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42.7223837
C:\Temp\EXPORT\dir2 
2017-Sep-06 16:06:43.1435864
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11.7604069
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07.5122231
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02.6413853


Required Output
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\DND5 
2017-Sep-05 14:31:00
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\EXPORT\dir2 
2017-Sep-06 16:06:43
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02


From,
Vino.B



<    1   2   3   >