Re: Does betterC work different on windows and linux?

2019-11-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 14 November 2019 at 16:47:59 UTC, kinke wrote:
The -betterC for that app doesn't imply that its dependencies 
are compiled with -betterC too. So either also specify that 
flag in your library's dub config, or build the app with 
`DFLAGS=-betterC dub ...`.


Thank you, I added some information to the repo to use 
subConfigurations for betterC.


Re: Unexpected result with std.conv.to

2019-11-14 Thread Joel via Digitalmars-d-learn

On Friday, 15 November 2019 at 04:26:58 UTC, Jon Degenhardt wrote:

On Friday, 15 November 2019 at 03:51:04 UTC, Joel wrote:
I made a feature that converts, say, [9:59am] -> [10:00am] to 
1 minute. but found '9'.to!int = 57 (not 9).


Doesn't seem right... I'm guessing that's standard though, 
same with ldc.


Use a string or char[] array. e.g. writeln("9".to!int) => 9.

With a single 'char' what is being produced is the ascii value 
of the character.


Thanks, Jon Degenhardt. I did work it out.


Re: Unexpected result with std.conv.to

2019-11-14 Thread Jon Degenhardt via Digitalmars-d-learn

On Friday, 15 November 2019 at 03:51:04 UTC, Joel wrote:
I made a feature that converts, say, [9:59am] -> [10:00am] to 1 
minute. but found '9'.to!int = 57 (not 9).


Doesn't seem right... I'm guessing that's standard though, same 
with ldc.


Use a string or char[] array. e.g. writeln("9".to!int) => 9.

With a single 'char' what is being produced is the ascii value of 
the character.


Unexpected result with std.conv.to

2019-11-14 Thread Joel via Digitalmars-d-learn
I made a feature that converts, say, [9:59am] -> [10:00am] to 1 
minute. but found '9'.to!int = 57 (not 9).


Doesn't seem right... I'm guessing that's standard though, same 
with ldc.


Re: Translating Java into D

2019-11-14 Thread Heromyth via Digitalmars-d-learn

On Thursday, 14 November 2019 at 19:50:22 UTC, NonNull wrote:
Greetings, Java seems to be almost a subset of D in various 
ways.
No, it's not exactly right. Java is more powerful than D as for a 
language. Many things that Java can do can't be done by D. For 
example, reflection, full meta info for a type  in runtime, type 
deduction for a template, template member override.


See:
https://stackoverflow.com/questions/4829631/unusual-generic-syntax-arrays-stringaslist
https://www.baeldung.com/java-executor-service-tutorial

Has there been any work done to automatically translate Java 
source into D?


We ported some projects in Java by hand.


Re: csvReader & specifying separator problems...

2019-11-14 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 14 November 2019 at 12:25:30 UTC, Robert M. Münch 
wrote:
Just trying a very simple thing and it's pretty hard: "Read a 
CSV file (raw_data) that has a ; separator so that I can 
iterate over the lines and access the fields."


csv_data = raw_data.byLine.joiner("\n")

From the docs, which I find extremly hard to understand:

auto csvReader(Contents = string, Malformed ErrorLevel = 
Malformed.throwException, Range, Separator = char)(Range input, 
Separator delimiter = ',', Separator quote = '"')


So, let's see if I can decyphre this, step-by-step by trying 
out:


csv_records = csv_data.csvReader();

Would split the CSV data into iterable CSV records using ',' 
char as separator using UFCS syntax. When running this I get:


[...]


Side comment - This code looks like it was taken from the first 
example in the std.csv documentation. To me, the code in the 
std.csv example is doing something that might not be obvious at 
first glance and is potentially confusing.


In particular, 'byLine' is not reading individual CSV records. 
CSV can have embedded newlines, these are identified by CSV 
escape syntax. 'byLine' doesn't know the escape syntax. If there 
are embedded newlines, 'byLine' will read partial records, which 
may not be obvious at first glance. The .joiner("\n") step puts 
the newline back, stitching fields and records back together 
again in the process.


The effect is to create an input range of characters representing 
the entire file, using 'byLine' to do buffered reads. This input 
range is passed to CSVReader.


This could also be done using 'byChunk' and 'joiner' (with no 
separator). This would use a fixed size buffer, no searching for 
newlines while reading, so it should be faster.


An example:

 csv_by_chunk.d 
import std.algorithm;
import std.csv;
import std.conv;
import std.stdio;
import std.typecons;
import std.utf;

void main()
{
// Small buffer used to show it works. Normally would use a 
larger buffer.

ubyte[16] buffer;
auto stdinBytes = stdin.byChunk(buffer).joiner;
auto stdinDChars = stdinBytes.map!((ubyte b) => cast(char) 
b).byDchar;


writefln("--");
foreach (record; stdinDChars.csvReader!(Tuple!(string, 
string, string)))

{
writefln("Field 0: |%s|", record[0]);
writefln("Field 1: |%s|", record[1]);
writefln("Field 2: |%s|", record[2]);
writefln("--");
}
}

Pass it csv data without embedded newlines:

$ echo $'abc,def,ghi\njkl,mno,pqr' | ./csv_by_chunk
--
Field 0: |abc|
Field 1: |def|
Field 2: |ghi|
--
Field 0: |jkl|
Field 1: |mno|
Field 2: |pqr|
--

Pass it csv data with embedded newlines:

$ echo $'abc,"LINE 1\nLINE 2",ghi\njkl,mno,pqr' | ./csv_by_chunk
--
Field 0: |abc|
Field 1: |LINE 1
LINE 2|
Field 2: |ghi|
--
Field 0: |jkl|
Field 1: |mno|
Field 2: |pqr|
--

An example like this may avoid the confusion about newlines. 
Unfortunately, the need to do the odd looking conversion from 
ubyte to char/dchar is undesirable in a code example. I haven't 
found a cleaner way to write that. If there's a nicer way I'd 
appreciate hearing about it.


--Jon



Re: csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-14 13:08:10 +, Mike Parker said:

Contents, ErrorLevel, Range, and Separator are template (i.e. 
compile-time) parameters. Input, delimiter, and quote are function 
(i.e. runtime) parameters.


Mike, thanks a lot... I feel like an idiot. As casual D programmer the 
template-syntax is not so easy to get used too because it's not so 
distinguishable.


However, your explanation helps a lot to make things much more clear now.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Translating Java into D

2019-11-14 Thread NonNull via Digitalmars-d-learn
Greetings, Java seems to be almost a subset of D in various ways. 
Has there been any work done to automatically translate Java 
source into D?




Re: Dlang + QtE5 + "Qt Designer": How convert .ui to .d Grafic Interface?

2019-11-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 14 November 2019 at 19:07:56 UTC, Marcone wrote:

Hi,

I use Dlang with QtE5 to make my programs with GUI.


If QT is is not a must, you can go for gtkd + Glade designer. I 
wrote a small utility to work together with Glade and gtkd. 
please note that it doesn't convert all fields of Glade file into 
a d source as at designer does. 
https://github.com/aferust/makegtkdclass





Dlang + QtE5 + "Qt Designer": How convert .ui to .d Grafic Interface?

2019-11-14 Thread Marcone via Digitalmars-d-learn

Hi,

I use Dlang with QtE5 to make my programs with GUI.
I want to design my program with "Qt Designer" and convert .ui 
file to .d file for use with Dlang + QtE5.


In Python, Ruby, C++ you can designe GUI using "Qt Designer" and 
convert to respective language using uic.exe.


I found this duic convert, but is in C++ and yet not compiled. I 
don't develop in C++, so I can't compile. Someon can compile it 
to duic.exe, send to internet and send me the link for download? 
thank you.


duic.cpp link: 
https://bitbucket.org/qtd/repo/src/default/tools/duic/


Re: CI: Why Travis & Circle

2019-11-14 Thread jmh530 via Digitalmars-d-learn

On Thursday, 14 November 2019 at 17:06:36 UTC, Andre Pany wrote:

[snip]

With the public availability of Github Actions I highly 
recommend it if you have open source project on Github. If is 
free and works well with D and Dub.


Kind regards
Andre


I'm not that familiar with Github Actions, but I should get more 
familiar with it.


But my broader question is why both? Don't they both do largely 
the same things?


I was motivated to ask this by looking at the mir repositories, 
which have both.

https://github.com/libmir/mir


Re: CI: Why Travis & Circle

2019-11-14 Thread Andre Pany via Digitalmars-d-learn

On Thursday, 14 November 2019 at 13:47:32 UTC, jmh530 wrote:
I'm curious what the typical motivation is for using both 
Travis CI and Circle CI in a project is.


Thanks.


With the public availability of Github Actions I highly recommend 
it if you have open source project on Github. If is free and 
works well with D and Dub.


Kind regards
Andre


Re: Why same pointer type for GC and manual memory?

2019-11-14 Thread kinke via Digitalmars-d-learn

On Thursday, 14 November 2019 at 01:08:58 UTC, Suleyman wrote:

On Wednesday, 13 November 2019 at 16:43:27 UTC, IGotD- wrote:
Best example is probably managed C++, an MS extension to C++ 
which is now deprecated.


MS Managed C++ was superseded by C++/CLI[1] which was 
standardized. They actually retained the special syntax for GC 
pointers.
One of the motivations if I understand correctly is to let the 
programmers easily distinguish which pointers should be freed 
and which ones are managed by the GC. It's not a bad idea when 
there is extensive use of both manual memory management and 
garbage collection.


IIRC (it's been a while), a mandatory reason for that distinction 
is that the .NET GC may move managed objects in memory 
(compaction) and so you have to pin them first to get a stable 
pointer.


Re: Does betterC work different on windows and linux?

2019-11-14 Thread kinke via Digitalmars-d-learn
On Thursday, 14 November 2019 at 16:34:07 UTC, Ferhat Kurtulmuş 
wrote:
I could also run the code in that way. Probably I have some 
problems with dub configurations. I get linking errors when I 
try to import the library in a newly created dub project, 
although there is "dflags": ["-betterC"] in the dub.json of 
client app. Then we can be sure that it supports betterC.


The -betterC for that app doesn't imply that its dependencies are 
compiled with -betterC too. So either also specify that flag in 
your library's dub config, or build the app with `DFLAGS=-betterC 
dub ...`.


Re: Does betterC work different on windows and linux?

2019-11-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Thursday, 14 November 2019 at 16:12:19 UTC, kinke wrote:
I can't reproduce this with LDC 1.17.0, after changing 
`unittest` to `extern (C) int main()` and returning 0 at the 
end; compiled & linked with `ldc2 -betterC stringnogc.d`.


I could also run the code in that way. Probably I have some 
problems with dub configurations. I get linking errors when I try 
to import the library in a newly created dub project, although 
there is "dflags": ["-betterC"] in the dub.json of client app. 
Then we can be sure that it supports betterC.


Re: Does betterC work different on windows and linux?

2019-11-14 Thread kinke via Digitalmars-d-learn
I can't reproduce this with LDC 1.17.0, after changing `unittest` 
to `extern (C) int main()` and returning 0 at the end; compiled & 
linked with `ldc2 -betterC stringnogc.d`.


Re: Why same pointer type for GC and manual memory?

2019-11-14 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 13 November 2019 at 16:43:27 UTC, IGotD- wrote:

On Wednesday, 13 November 2019 at 15:30:33 UTC, Dukc wrote:


I'm not 100% sure what managed pointers mean -Are they so that 
you can't pass them to unregistered memory? A library solution 
would likely do -wrap the pointer in a struct and make it 
@system to extract it's pointer as "raw". So you cannot put it 
to C-allocated arrays without type casting, which you probably 
don't do accidently.




Best example is probably managed C++, an MS extension to C++ 
which is now deprecated. However, it server as an interesting 
example where MS extended C++ with a ^gc type.


AFAIK those managed pointers are not general purpose, but 
specifically for managed .net objects, you can't allocate 
unmanaged object on managed heap, and managed object on unmanaged 
heap. In case of D you would have raw pointers for unmanaged 
objects allocated in C heap and D GC heap, and additional .net 
pointers for .net objects.


Does betterC work different on windows and linux?

2019-11-14 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
I was trying to make my stupid writeln2 function 
(https://github.com/aferust/stringnogc/blob/master/source/stringnogc.d) compatible with betterC. writeln2() calls obParse() function which may contain some code incompatible with betterC. However; while the code in the unittest can be compiled and linked with betterC (extern (C) main...) on Ubuntu (LDC 1.17.0), it causes linking errors on windows (LDC 1.17.0):  unresolved external symbol _D15TypeInfo_Struct6__vtblZ... I know that TypeInfo and ModuleInfo features are unavailable with betterC. I want to know why my obParse() function compiles and links on ubuntu but not on windows, and which part of my code requires runtime.


CI: Why Travis & Circle

2019-11-14 Thread jmh530 via Digitalmars-d-learn
I'm curious what the typical motivation is for using both Travis 
CI and Circle CI in a project is.


Thanks.


Re: csvReader & specifying separator problems...

2019-11-14 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 14 November 2019 at 12:25:30 UTC, Robert M. Münch 
wrote:



From the docs, which I find extremly hard to understand:

auto csvReader(Contents = string, Malformed ErrorLevel = 
Malformed.throwException, Range, Separator = char)(Range input, 
Separator delimiter = ',', Separator quote = '"')



Contents, ErrorLevel, Range, and Separator are template (i.e. 
compile-time) parameters. Input, delimiter, and quote are 
function (i.e. runtime) parameters.




So, let's see if I can decyphre this, step-by-step by trying 
out:


csv_records = csv_data.csvReader();



Here, you aren't providing any template parameters and only the 
first function parameter, so it's the equivalent to calling the 
function like so:


csvReader!(string, Malformed.throwException, typeof(csv_data), 
char)(csv_data, ',', '"');



Which indicates some problem because not all fields are set in 
my CSV data. So let's ignore any error by specifying 
Malformed.ignore;


csv_records = csv_data.csvReader(Malformed.ignore);



csv_records = csv_data.csvReader!(string, Malformed.ignore)();





The docs state Malformed as 2nd parameter, since I use UFCS I 
assume that this becomes the first parameter. I don't



Malformed is the 2nd template parameter, your UFCS value is the 
first function parameter.



understand what the 3rd parameter (Range) is about.


Range is the type of the first parameter. It's common outside of 
Phobos use T and U for template types, but any valid symbol name 
can be used. This template has three type parameters which are 
named according to their purpose (Contents, Range, and 
Separator). Since Range is also the type of the first function 
parameter, the compiler will infer the type if you don't specify 
it.



4th parameter is my separator, which I need to set to ';' 
somehow.


The fourth _template_ parameter is the _type_ of your separator 
(and is set to default to char) not the actual separator. You 
want to set the delimiter, which is the second _function_ 
parameter.


csv_records = csv_data.csvReader!(string, Malformed.ignore)(';');



csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn
Just trying a very simple thing and it's pretty hard: "Read a CSV file 
(raw_data) that has a ; separator so that I can iterate over the lines 
and access the fields."


csv_data = raw_data.byLine.joiner("\n")


From the docs, which I find extremly hard to understand:


auto csvReader(Contents = string, Malformed ErrorLevel = 
Malformed.throwException, Range, Separator = char)(Range input, 
Separator delimiter = ',', Separator quote = '"')


So, let's see if I can decyphre this, step-by-step by trying out:

csv_records = csv_data.csvReader();

Would split the CSV data into iterable CSV records using ',' char as 
separator using UFCS syntax. When running this I get:


	std.csv.CSVException@/Library/D/dmd/src/phobos/std/csv.d(1283): Row 
1's length 0 does not match previous length of 1.


Which indicates some problem because not all fields are set in my CSV 
data. So let's ignore any error by specifying Malformed.ignore;


csv_records = csv_data.csvReader(Malformed.ignore);

And now I'm lost (just showing the first candidate):

Error: template std.csv.csvReader cannot deduce function from argument 
types !()(Result, Malformed), candidates are:
/Library/D/dmd/src/phobos/std/csv.d(327):csvReader(Contents = 
string, Malformed ErrorLevel = Malformed.throwException, Range, 
Separator = char)(Range input, Separator delimiter = ',', Separator 
quote = '"')

 with Contents = string,
  ErrorLevel = cast(Malformed)1,
  Range = Result,
  Separator = Malformed
 whose parameters have the following constraints:
 
   isInputRange!Range
   is(Unqual!(ElementType!Range) == dchar)
 > isSomeChar!Separator
 - !is(Contents T : T[U], U : string)
 

The docs state Malformed as 2nd parameter, since I use UFCS I assume 
that this becomes the first parameter. I don't understand what the 3rd 
parameter (Range) is about. 4th parameter is my separator, which I need 
to set to ';' somehow.


But from the error message, it looks like DMD tries to use 
Malformed.ignore as the 4th (!!) Parameter being the Separator.


I'm totally confused:

* What is used as the 3rd parameter by DMD? Where does it come from?
* How to specify a ';' separator?

This is all pretty confusing...

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-14 Thread Simen Kjærås via Digitalmars-d-learn

On Thursday, 14 November 2019 at 09:30:23 UTC, user9876 wrote:
A good thing is that in many cases the template instance 
parameters can be deduced from the arguments used:


---
import std;

void main()
{
assert(max(0,1) == 1);
// same as assert(max!(int,int)(0,1) == 1);
}
---

This feature is known as "IFTI" see §6, 
https://dlang.org/spec/template.html#function-templates.


You're not forced to use the D templates but you'll have to 
write many code by yourself because the standard library use 
them everywhere.


IFTI is nifty. (sorry, I had to)

--
  Simen


Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-14 Thread user9876 via Digitalmars-d-learn

On Wednesday, 13 November 2019 at 14:01:13 UTC, BoQsc wrote:
I don't like to see exclamation marks in my code in as weird 
syntax as these ones:

to!ushort(args[1])
s.formattedRead!"%s!%s:%s"(a, b, c);


I'm not sure why, but template instantiation syntax is 
prevalent in the documentation examples of d lang libraries. It 
almost seems like every other example contains at least one or 
two  of them.


It look horrible, and I'm feeling like I'm being forced/coerced 
to learn from examples that do not provide alternatives to the 
template instantiation syntax. Even if the alternative examples 
were provided, why would anyone want to have syntax as ugly and 
weird as current template instantiation syntax with exclamation 
point in the middle of the statement with all other things that 
come with it.


A good thing is that in many cases the template instance 
parameters can be deduced from the arguments used:


---
import std;

void main()
{
assert(max(0,1) == 1);
// same as assert(max!(int,int)(0,1) == 1);
}
---

This feature is known as "IFTI" see §6, 
https://dlang.org/spec/template.html#function-templates.


You're not forced to use the D templates but you'll have to write 
many code by yourself because the standard library use them 
everywhere.