Re: const and immutable member variables in classes

2016-02-03 Thread Jonathan M Davis via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 06:11:07 UTC, H. S. Teoh wrote:
I still can't come up with a compelling use case that would 
justify using a const/immutable class member, that couldn't be 
done by some other means, though. Especially since we're 
talking about classes, we already have all the traditional OO 
mechanisms for controlling access to members - get methods, and 
so on, which are more flexible and adaptable to different use 
cases to begin with (e.g., can be overridden by derived 
classes, can implement custom access criteria not expressible 
by const/immutable, etc.), so I have a hard time justifying 
using const/immutable members instead.


You make a member variable const or immutable for the same 
reasons that you make a local variable const or immutable - it 
prevents accidental mutation and potentially makes it so that the 
compiler can optimize your code better. It's not necessarily the 
case that a const or immutable member variable is exposed in the 
API. It could be purely internal, or it could be exposed via a 
property function like any other member variable (I tend to think 
that member variable should never be exposed except for POD 
structs, since you lose out on flexibility if you do). But by 
simply making it const or immutable, you avoid certain bugs and 
potentially get faster code. IMHO, ideally, any variable that's 
never going to be mutated would be const or immutable, but that's 
not always possible for a variety of reasons (e.g. it doesn't 
play well with struct members, and const doesn't work well with 
all types).


- Jonathan M Davis



Re: How would you implement this in D? (signals & slots)

2016-02-03 Thread Vadim Lopatin via Digitalmars-d-learn

On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote:

module signals_and_slots;
How do you implement this template called like:
void onColorChange(in Color) {
   // do something with color
}
auto slots = Slots!(void delegate(in Color), Color);
slots.connect();
auto color = Color(0.0, 1.0, 1.0, 1.0);
slots.call(color);


Signals in DlangUI:

https://github.com/buggins/dlangui/blob/master/src/dlangui/core/signals.d




Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Sönke Ludwig via Digitalmars-d

Am 03.02.2016 um 08:45 schrieb Ola Fosheim Grøstad:

On Wednesday, 3 February 2016 at 07:06:47 UTC, cym13 wrote:

It's all true, D rose up 6 positions:
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

I don't quite know what the leading factor for that change was but it
sure will be great for its image.


I don't think anyone takes Tiobe seriously. Here is the search trend for
"dlang", "golang", "swift ios" and "rust (programming langauge)":

https://www.google.com/trends/explore#q=dlang%2C%20golang%2C%20swift%20ios%2C%20%2Fm%2F0dsbpg6=q=Etc%2FGMT-1


golang and swift are soaring, rust is gaining ground and dlang is stable.



Maybe it's showing different results to you, but the numbers I get are 
tiny. Also, picking arbitrary search terms skews the results 
considerably. Results using Google's categorization instead:

https://www.google.com/trends/explore#q=%2Fm%2F09gbxjr%2C%20%2Fm%2F010sd4y3%2C%20%2Fm%2F0dsbpg6%2C%20%2Fm%2F01kbt7=1%2F2009%2085m=q=Etc%2FGMT-1

Those are still the same tiny numbers, though, so there's really not 
much to infer from this.


Re: questions about NetBSD port

2016-02-03 Thread Nikolay via Digitalmars-d

On Wednesday, 3 February 2016 at 06:25:49 UTC, Joakim wrote:

On Tuesday, 2 February 2016 at 18:45:20 UTC, Nikolay wrote:

You're probably better off porting dmd 2.068 first (as it's the 
last dmd written wholly in C++), using it to compile dmd git 
master on NetBSD, then porting druntime and phobos master.  
Porting dmd to NetBSD/x86 is likely easy: simply follow what 
the other BSDs have done, as you did for ldc.




Is it possible to compile dmd with ldc?
There are some additional changes in druntime for dmd comparing 
with ldc. So even working NetBSD dmd compiler is not full 
solution. I think new platforms will have troubles until we have 
separate branches for druntime/phobos in LDC/GDC and patch 
direction master -> LDC/GDC.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Sönke Ludwig via Digitalmars-d

Am 03.02.2016 um 09:53 schrieb Ola Fosheim Grøstad:

On Wednesday, 3 February 2016 at 08:43:39 UTC, Sönke Ludwig wrote:

And how do you verify that that's a better classification? If you look
at the graphs of any of "D", "dlang", "D programming language", "D
language", "D programming", none of them seems to correlate with
events such as the date of first publication, version 1.000, version
2.000, the conferences etc.


You have to make a qualitative judgement. Terms such as "dlang" has only
been in used in recent years and probably only by invested users. It is
difficult to find terms for "D" that have enough volume to show up. "d
programming language" is probably only used by non-users, it shows a
clear spike in october 2004, july 2005, january 2007, july 2014, but a
general falling trend. While "dlang" is more stable.


I agree with this in general, but the uncertainty is still far to high 
to be able to make comparisons between languages. Rough trends maybe.


BTW, this one (using the "programming" category) looks like it could be 
somewhat neutral: 
https://www.google.com/trends/explore#cat=0-5-31=d%20language%2C%20rust%20language%2C%20go%20language%2C%20swift%20language=q=Etc%2FGMT-1


At least it shows the characteristic spikes for each language and the 
related searches look reasonable. But the popularity of D pre-2007 looks 
odd, and with such a bias it's impossible to read anything out of the 
more recent numbers (in terms of absolute value) without wishful thinking.


Re: questions about NetBSD port

2016-02-03 Thread Nikolay via Digitalmars-d

On Wednesday, 3 February 2016 at 10:36:31 UTC, Iain Buclaw wrote:
On 3 February 2016 at 10:25, Nikolay via Digitalmars-d < 
digitalmars-d@puremagic.com> wrote:



That is a relatively recent change with respect to the age of 
NetBSD.  :-)


I guess that in LDC the intrinsic for std.math.sin is forwarded 
to NetBSD libm.sinl?


Yes but https://www.netbsd.org/changes/changes-7.0.html#libm :
Most transcendent functions are stubbed out


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 08:43:39 UTC, Sönke Ludwig wrote:
And how do you verify that that's a better classification? If 
you look at the graphs of any of "D", "dlang", "D programming 
language", "D language", "D programming", none of them seems to 
correlate with events such as the date of first publication, 
version 1.000, version 2.000, the conferences etc.


You have to make a qualitative judgement. Terms such as "dlang" 
has only been in used in recent years and probably only by 
invested users. It is difficult to find terms for "D" that have 
enough volume to show up. "d programming language" is probably 
only used by non-users, it shows a clear spike in october 2004, 
july 2005, january 2007, july 2014, but a general falling trend. 
While "dlang" is more stable.





Re: questions about NetBSD port

2016-02-03 Thread Iain Buclaw via Digitalmars-d
On 3 February 2016 at 10:25, Nikolay via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:

> On Wednesday, 3 February 2016 at 07:45:23 UTC, Iain Buclaw wrote:
>
>> On 2 Feb 2016 7:50 pm, "Nikolay via Digitalmars-d" <
>> digitalmars-d@puremagic.com> wrote:
>>
>> Is NetBSD similar to FreeBSD in that you have 80-bit reals but only the
>> first 53 bits of the mantissa are used?
>>
>> I don't know how accurate LDC is when it sets up compile time float
>> properties.  But what do you get when:
>>
>> pragma (msg, real.sizeof);
>> pragma (msg, real.mant_dig);
>>
>> Alternatively, use a C program with printfs for:
>>
>> sizeof(long double)
>> LDBL_MANT_DIG
>>
>> To make sure both ldc and gcc are agreeable.
>>
>> Have a look at rt/dmain2.d (look for fldcw) if the problem is because of
>> what I describe above.
>>
>
> I suppose it is not similar FreeBSD ( according
> https://www.netbsd.org/changes/changes-7.0.html#x86 )
>

That is a relatively recent change with respect to the age of NetBSD.  :-)

I guess that in LDC the intrinsic for std.math.sin is forwarded to NetBSD
libm.sinl?


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Martin Tschierschke via Digitalmars-d

On Wednesday, 3 February 2016 at 07:06:47 UTC, cym13 wrote:
[...]
I don't quite know what the leading factor for that change was 
but it sure will be great for its image.


Oh, I am sure I caused it myself, I am new on D and all my 
searching for it and than Bang  ! :-)


So, don't try to understand Tiobe, just be happy D is a new entry 
for top 20, and work hard to improve DMD, GDC, LDC, DUB, vibe.d 
etc... to make this real cool programming experience open for 
more people. Like me, frustrated from ever faster computers 
becoming slower by scripting languages and Browsers doing the 
job, where a real alternative is around the corner: D.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 10:41:40 UTC, Martin 
Tschierschke wrote:
open for more people. Like me, frustrated from ever faster 
computers becoming slower by scripting languages and Browsers 
doing the job, where a real alternative is around the corner: D.


D has been around the corner for a D-ecade. The corner is 
constantly moving so that is obviously not a winning strategy.




Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 07:50:07 UTC, cym13 wrote:
Also I find showing even little achievements good for the 
troop's morale.


Well, it is better to have good information. If you zoom in on 
the link above you'll see some interesting facts on daily 
patterns. The Swift and Go graph go way down in weekends, so they 
are used by businesses. Rust does not, so it currently is 
appealing to hobbyists. D should think about capturing some of 
that Rust audience.


What is important is to be realistic, so that a good strategy can 
be selected.


Right now Rust may have 10x more interest than D, and C++ 40x 
more interest than Rust. Just a guesstimate based on search 
frequencies, but it stacks up with github.





Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Sönke Ludwig via Digitalmars-d

Am 03.02.2016 um 09:23 schrieb Sönke Ludwig:

Am 03.02.2016 um 08:45 schrieb Ola Fosheim Grøstad:

On Wednesday, 3 February 2016 at 07:06:47 UTC, cym13 wrote:

It's all true, D rose up 6 positions:
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

I don't quite know what the leading factor for that change was but it
sure will be great for its image.


I don't think anyone takes Tiobe seriously. Here is the search trend for
"dlang", "golang", "swift ios" and "rust (programming langauge)":

https://www.google.com/trends/explore#q=dlang%2C%20golang%2C%20swift%20ios%2C%20%2Fm%2F0dsbpg6=q=Etc%2FGMT-1



golang and swift are soaring, rust is gaining ground and dlang is stable.



Maybe it's showing different results to you, but the numbers I get are
tiny. Also, picking arbitrary search terms skews the results
considerably. Results using Google's categorization instead:
https://www.google.com/trends/explore#q=%2Fm%2F09gbxjr%2C%20%2Fm%2F010sd4y3%2C%20%2Fm%2F0dsbpg6%2C%20%2Fm%2F01kbt7=1%2F2009%2085m=q=Etc%2FGMT-1


Those are still the same tiny numbers, though, so there's really not
much to infer from this.


So for comparison, D (Programming Language) shows 36 searches in January 
2016 in Google Trends for me, while the webmaster tools show 235 klicks 
on vibed.org for "vibe.d" searches in the same timeframe (12 clicks for 
"dlang"). So the question is what those Google Trend numbers actually 
show, it can't be the total amount of searches.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 09:09:20 UTC, Sönke Ludwig wrote:
At least it shows the characteristic spikes for each language 
and the related searches look reasonable. But the popularity of 
D pre-2007 looks odd, and with such a bias it's impossible to 
read anything out of the more recent numbers (in terms of 
absolute value) without wishful thinking.


Yes, I think counting significant libraries/framworks and github 
activity provide better absolute measurements for comparable 
languages (Go, Rust, D), but doesn't work for enterprise 
languages.


Still, the trends says something about the future of competing 
languages, so if one want to lay down a strategy it can be 
useful. And it also can tell us something about what events leads 
to increased/falling interest.




Re: Binding to C - Arrays and Access Violation

2016-02-03 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 04:19:37 UTC, jmh530 wrote:



A few extra questions: 1) In other parts of the code I'm using 
extern(System), but that doesn't work for these. Why is 
extern(C) used for function pointers?,


extern(C) is only used with function pointers when it's needed. 
It depends entirely on how the C library was compiled.  By 
default, most compilers compile with the cdecl calling 
convention, which is what extern(C) specifies in D code. Windows 
system libraries are usually compiled to use the stdcall calling 
convention. The D equivalent is extern(Windows). extern(System) 
translates to extern(Windows) on Windows and extern(C) elsewhere. 
Function pointers passed to C code need to have the same calling 
convention as that of the library to which they are passed.


2) You use const(double)*, in other parts of the code I had 
converted the C code from const char* to const(char*). Does it 
matter where the pointer * falls?


Technically, const(char)* is a mutable pointer to const data and 
const(char*) is an immutable pointer to const data.


Re: questions about NetBSD port

2016-02-03 Thread Nikolay via Digitalmars-d

On Wednesday, 3 February 2016 at 07:45:23 UTC, Iain Buclaw wrote:
On 2 Feb 2016 7:50 pm, "Nikolay via Digitalmars-d" < 
digitalmars-d@puremagic.com> wrote:


Is NetBSD similar to FreeBSD in that you have 80-bit reals but 
only the first 53 bits of the mantissa are used?


I don't know how accurate LDC is when it sets up compile time 
float properties.  But what do you get when:


pragma (msg, real.sizeof);
pragma (msg, real.mant_dig);

Alternatively, use a C program with printfs for:

sizeof(long double)
LDBL_MANT_DIG

To make sure both ldc and gcc are agreeable.

Have a look at rt/dmain2.d (look for fldcw) if the problem is 
because of

what I describe above.


I suppose it is not similar FreeBSD ( according 
https://www.netbsd.org/changes/changes-7.0.html#x86 )


Detecting exception unwinding

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
Is there some reliable way to detect that a destructor is called 
because of exception unwinding?


I basically want to change behaviour within a destructor based on 
whether the destructor is called as a result of a regular or an 
exceptional situation.


E.g. commit changes to a database on regular destruction, or 
inhibit logging during exception unwinding.




Re: Interested in D, spec confuses me.

2016-02-03 Thread Kagamin via Digitalmars-d

On Tuesday, 2 February 2016 at 14:36:05 UTC, Bambi wrote:

1. const isn't constant


The idea was to ease porting C code to D, so many things work the 
same in C and D except for maybe integer types that were borrowed 
from java.


The example snippet ' immutable(int[]) bar() immutable {} ' 
brings back bad memories of redundant declarations of the style 
' Object object = new Object(); '.


Redundancy is not all that bad, but if you want less of it, you 
can: `auto bar() immutable {}` - the compiler will infer the 
return type.



2. when is an extern an extern?
 The wiki page on interfacing with C states that C globals 
require an extra extern.


extern attribute is optimized for binding extern functions, which 
is what you need most of the time. In C you would need two 
attributes `extern cdecl` - one for extern and one for calling 
convention, in D it's done with one attribute, though it only 
specifies calling convention, because everything is implicitly 
extern anyway. It works well for functions, but not for 
variables, when you can't differentiate between declaration and 
definition.



3. typeof is an operator, sizeof is a property


sizeof is a property because it can work that way, and making it 
a whole special syntactical construct for this single purpose 
would be overkill. Now it can be implemented as a template, but 
it wasn't always this way.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 08:40:54 UTC, Ola Fosheim 
Grøstad wrote:
On Wednesday, 3 February 2016 at 08:34:47 UTC, Sönke Ludwig 
wrote:
So for comparison, D (Programming Language) shows 36 searches 
in January 2016 in Google Trends for me, while the webmaster 
tools show 235 klicks on vibed.org for "vibe.d" searches in 
the same timeframe (12 clicks for "dlang"). So the question is 
what those Google Trend numbers actually show, it can't be the 
total amount of searches.


I believe it is percentage relative to the peak of the graph?


If you hover over the question mark in the circle you get this:

«Numbers represent search interest relative to the highest point 
on the chart. If, at most,10% of searches for the given region 
and time frame were for "pizza," we'd consider this 100. This 
doesn't convey absolute search volume. Learn more»




Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Sönke Ludwig via Digitalmars-d

Am 03.02.2016 um 09:29 schrieb Ola Fosheim Grøstad:

On Wednesday, 3 February 2016 at 08:23:39 UTC, Sönke Ludwig wrote:

Maybe it's showing different results to you, but the numbers I get are
tiny. Also, picking arbitrary search terms skews the results
considerably.


Not really, you look at trends over time not absolutes.



Okay, I see, it's just percentage of the highest value. To make any kind 
of qualitative judgements, it would be necessary to at least have a hint 
for the absolute numbers.





Results using Google's categorization instead:


I have found the Google classification to be wrong in the past.


I have no doubt about that!



So I think it is better to find a term that is unique for the language,
I don't know any such term for Rust though.



And how do you verify that that's a better classification? If you look 
at the graphs of any of "D", "dlang", "D programming language", "D 
language", "D programming", none of them seems to correlate with events 
such as the date of first publication, version 1.000, version 2.000, the 
conferences etc.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 08:34:47 UTC, Sönke Ludwig wrote:
So for comparison, D (Programming Language) shows 36 searches 
in January 2016 in Google Trends for me, while the webmaster 
tools show 235 klicks on vibed.org for "vibe.d" searches in the 
same timeframe (12 clicks for "dlang"). So the question is what 
those Google Trend numbers actually show, it can't be the total 
amount of searches.


I believe it is percentage relative to the peak of the graph?

But the heuristics for the aggregated Google classification is 
very wrong, maybe they put more effort into the big languages 
like Java and C++? I've previously seen "java d compiler" 
classified as related to "d programming language".




Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 08:53:27 UTC, Ola Fosheim 
Grøstad wrote:
enough volume to show up. "d programming language" is probably 
only used by non-users, it shows a clear spike in october 2004, 
july 2005, january 2007, july 2014, but a general falling 
trend. While "dlang" is more stable.


The cause of the biggest spike of interest,  january 2007:

http://developers.slashdot.org/story/07/01/01/2041256/the-d-programming-language-version-10



Re: Detecting exception unwinding

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 11:41:28 UTC, Jonathan M Davis 
wrote:
AFAIK, there is no way to detect whether an exception is in 
flight or not aside from the cases where scope(failure) or 
catch would catch the exception, and from what I recall of the 
last time that someone asked this question, the consensus was 
that it couldn't be done - but maybe I'm remembering 
incorrectly. I am pretty sure that this was asked within the 
last few months though, so if you search D.Learn, you can 
probably find that discussion.


:-/

I am looking for something like this:

http://en.cppreference.com/w/cpp/error/uncaught_exception

It is useful for certain types of libraries where you want to 
cancel out effects "undo commits" when exceptional situations 
arise.





Call D from TCL

2016-02-03 Thread Vasileios Anagnostopoulos via Digitalmars-d-learn
Is there any example,framework or tutorial on how to call D from Tcl (write
new commands in D for Tcl)?

I am on Windows 10 x86_64.

thank you.

-- 
Dr. Vasileios Anagnostopoulos (MSc,PhD)
Researcher/Developer
ICCS/NTUA 9 Heroon Polytechneiou Str., Zografou 15773 Athens,Greece
T (+30) 2107723404 M (+30) 6936935388
E va...@mail.ntua.gr www.ntua.gr<
http://www.ntua.gr/>


Re: Interested in D, spec confuses me.

2016-02-03 Thread Bambi via Digitalmars-d

On Tuesday, 2 February 2016 at 23:41:07 UTC, H. S. Teoh wrote:
You're misunderstanding D's type system.  Immutable is not a 
"better const", as though const is somehow defective.  Perhaps 
the following diagram may help to clear things up:


const
   / \
(mutable)   immutable

What this means is that both mutable and immutable are 
implicitly convertible to const. Or, to put it another way, 
const is a kind of "wildcard" that can point to underlying data 
that's either mutable or immutable.


Mutable data is, well, mutable -- anybody who can get to it, 
can modify it. Immutable means *nobody* can modify it once it's 
initialized.


Why const, then?  Const is useful for when a function doesn't 
care whether the underlying data is mutable or not, because it 
doesn't need to change the data. Const provides guarantees to 
the caller that the function won't touch the data -- even if 
the data is actually mutable in the caller's context.  It's a 
"no-mutation view" on data that's possibly mutable by a third 
party.


Furthermore, since const provides actual guarantees that the 
called function isn't going to touch the data, this opens up 
optimization opportunities for the compiler. E.g., it can 
assume that any part(s) of the data that are held in registers 
will remain valid after the function call (provided said 
registers aren't touched by the function), so it doesn't need 
to issue another load after the function returns. As a 
contrived example, say you have code like this:


struct Data { int x; }
int func1(Data* d) { ... }
int func2(const(Data)* d) { ... }
...
void main() {
Data d;
int value1 = d.x*func1() + d.x;
int value2 = d.x*func2() + d.x;
d.x++;
}

When evaluating value1, the compiler may have issued a load for 
the first occurrence of d.x, then it calls func1. But since 
func1 may modify d.x, the second d.x needs another load in 
order to ensure the correct value is used.


When evaluating value2, however, since func2 takes a const 
pointer to the Data, the compiler knows the value of d.x cannot 
possibly change across that function call, so it can safely 
reuse the value of d.x that was previously loaded.  It may also 
go further and refactor the expression as d.x*(func2() + 1), 
because the const guarantees that func2 can't mutate d.x behind 
our backs and invalidate the result. Such a refactoring is 
invalid with func1, because there is no guarantee that d.x will 
have the same value after func1 returns.


Now, the same argument applies if immutable was used in place 
of const. However, the last line in main() illustrates why we 
need const rather than immutable in this case: we actually 
*want* to modify d.x in main(). We just don't want func2 to 
touch anything. So we can't use immutable -- since immutable 
means *nobody* can touch the data. So, const provides both the 
guarantee that func2 won't touch the data, thus allowing the 
aforementioned optimization, and also continues to let main() 
mutate the data at its leisure.



T


In C90+, const can apply to both values and pointers to those 
values. And since pointers are themselves values of a memory 
address that is consistent usage. That seems to be the only 
meaningful distinction here. Pointing to a const value makes the 
pointer mutable but the value immutable. Pointing a const to a 
value makes the pointer immutable but the value mutable. etc.


Immutable accomplishes nothing distinct here that I can see, 
other than making the use of const confusing. To make a function 
not change a value you declare a const input. Because it is the 
value declared in the function definition that is a const, not 
the value you pass it. "Passing as const" doesn't make any 
logical sense. To be honest, it smells like the kind of opaque 
cleverness D is ostensibly supposed to obviate.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Dejan Lekic via Digitalmars-d

On Wednesday, 3 February 2016 at 07:06:47 UTC, cym13 wrote:
It's all true, D rose up 6 positions: 
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html


I don't quite know what the leading factor for that change was 
but it sure will be great for its image.


Well, people who observe TIOBE index knew this is going to 
happen. Did we? :)


Cannot get Derelict to work

2016-02-03 Thread Whirlpool via Digitalmars-d-learn
Hi, I'd like to use Derelict, more specifically the GLFW package, 
but so far I have been unable to make it work. (I posted in the 
IDE section but didn't get a reply (link below), and since the 
Derelict forum seems not to exist anymore, I post here. I hope it 
is OK to do so)


Things I tried :

- First I tried to create a VisualD project on Windows, and to 
manually compile derelict-util and derelict-glfw3: 
http://forum.dlang.org/post/ssibsuuhuaswaelxz...@forum.dlang.org


- then, I tried on Fedora 23, which has packages in its 
repositories for LDC and Derelict. I first tried to use a command 
such as this one :
ldc2 -I=/usr/include/d/derelict -L=DerelictUtil -L=DerelictGLFW3 
glfw_test.d
/usr/bin/ld: ne peut pas trouver DerelictUtil: Aucun fichier ou 
dossier de ce type (which means "cannot find DerelictUtil. No 
such file or directory")
/usr/bin/ld: ne peut pas trouver DerelictGLFW3: Aucun fichier ou 
dossier de ce type

collect2: erreur: ld a retourné 1 code d'état d'exécution
Error: /usr/bin/gcc failed with status: 1

I indeed don't have a /usr/bin/ld directory. Is the command I 
tried correct ?


Still on Fedora, I've also tried with DUB :
$ dub build
Performing "debug" build using ldc2 for x86_64.
derelict-util 2.0.4: building configuration "library"...
Error: failed to create path to file: 
.dub/obj/../../.dub/packages/derelict-util-2.0.4/.dub/build/library-debug-linux.posix-x86_64-ldc_0-A2036AF2F4C2D6CD8A2817C4F5C50907/libDerelictUtil.a

No such file or directory
ldc2 failed with exit code 1.


- trying again with DUB on Windows 10, I created a dub project, 
added derelict-util and derelict-glfw3 as dependencies in the 
dub.sdl file, and then used "dub generate visuald", but when I 
try to build in Visual Studio, I get the following kind of 
exceptions :


First-chance exception: 
derelict.util.exception.SharedLibLoadException Failed to load one 
or more shared libraries:


	glfw3.dll - Le module spécifié est introuvable. (The specified 
module cannot be found.) at 
..\AppData\Roaming\dub\packages\derelict-util-2.0.4\source\derelict\util\exception.d(35)


After that, I've tried compiling derelict-util and derelict-glfw3 
in AppData, because there seemed to be no lib files. But isn't 
one of the points of using DUB precisely that users don't have to 
compile the dependency libs themselves ?


I'd really need a tutorial or help about that. I could only find 
a couple of old posts or articles from years ago.


Thank you


Re: Cannot get Derelict to work

2016-02-03 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 12:18:17 UTC, Whirlpool wrote:
Hi, I'd like to use Derelict, more specifically the GLFW 
package, but so far I have been unable to make it work. (I 
posted in the IDE section but didn't get a reply (link below), 
and since the Derelict forum seems not to exist anymore, I post 
here. I hope it is OK to do so)


Things I tried :

- First I tried to create a VisualD project on Windows, and to 
manually compile derelict-util and derelict-glfw3: 
http://forum.dlang.org/post/ssibsuuhuaswaelxz...@forum.dlang.org


Your problem there is that you have misconfigured Visual D. The 
DerelictGLFW3 and DerelictUtil *source* files need to be on the 
import path. The libraries need to be on the library path. Don't 
confuse importing with linking. The former happens at *compile 
time*. The compiler needs to know where to find the source files 
so it can determine which symbols are available to your module. 
That's what the import path is for. At *link time*, which comes 
after the compiler has generated object files, the linker will 
take all of the object files and any libraries you need and 
combine them into an executable. Setting the library path in your 
IDE configuration will allow the IDE to ultimately pass that path 
to the linker so that it will know where to find the library 
files. This is the same for any IDE you may use. The only 
difference will be in the details, i.e. where and how you set the 
import and library paths.



- then, I tried on Fedora 23, which has packages in its 
repositories for LDC and Derelict. I first tried to use a 
command such as this one :
ldc2 -I=/usr/include/d/derelict -L=DerelictUtil 
-L=DerelictGLFW3 glfw_test.d
/usr/bin/ld: ne peut pas trouver DerelictUtil: Aucun fichier ou 
dossier de ce type (which means "cannot find DerelictUtil. No 
such file or directory")
/usr/bin/ld: ne peut pas trouver DerelictGLFW3: Aucun fichier 
ou dossier de ce type

collect2: erreur: ld a retourné 1 code d'état d'exécution
Error: /usr/bin/gcc failed with status: 1

I indeed don't have a /usr/bin/ld directory. Is the command I 
tried correct ?


/usr/bin/ld is not a directory. ld is the GNU linker, which you 
will have if you've installed GCC. I'm not an LDC user, but I 
will guess your problem is in the command line. With GCC, -L is 
used to pass the library *path* to the linker. Infivusal 
libraries are passed with -l. And usually, there's no '=', but I 
don't know if that's the problem here or not. You'll need to look 
up what command line options LDC supports specifically.




Still on Fedora, I've also tried with DUB :
$ dub build
Performing "debug" build using ldc2 for x86_64.
derelict-util 2.0.4: building configuration "library"...
Error: failed to create path to file: 
.dub/obj/../../.dub/packages/derelict-util-2.0.4/.dub/build/library-debug-linux.posix-x86_64-ldc_0-A2036AF2F4C2D6CD8A2817C4F5C50907/libDerelictUtil.a

No such file or directory
ldc2 failed with exit code 1.


What were you running dub build on here? Just derelict-util or 
your project?





- trying again with DUB on Windows 10, I created a dub project, 
added derelict-util and derelict-glfw3 as dependencies in the 
dub.sdl file, and then used "dub generate visuald", but when I 
try to build in Visual Studio, I get the following kind of 
exceptions :


First-chance exception: 
derelict.util.exception.SharedLibLoadException Failed to load 
one or more shared libraries:


	glfw3.dll - Le module spécifié est introuvable. (The specified 
module cannot be found.) at 
..\AppData\Roaming\dub\packages\derelict-util-2.0.4\source\derelict\util\exception.d(35)


The good news is that you've compiled and linked DerelictGLFW3 
and DerelictUtil just fine. That's why this is the recommended 
approach, as it's so easy. However, you still actually need the 
GLFW3 DLL on your system. DerelictGLFW3 is a binding to GLFW3, 
nothing more. It's a dynamic binding, so you don't need to mess 
with the GLFW library at compile time. But you still need the 
GLFW DLL at runtime. You can go to glfw.org and download the 
latest release. Unfortunately, they do not provide a binary 
distribution, so you will have to build the DLL from source or 
find somewhere that makes it available prebuilt DLLs available 
for you.


Re: Call D from TCL

2016-02-03 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 12:20:42 UTC, Vasileios 
Anagnostopoulos wrote:
Is there any example,framework or tutorial on how to call D 
from Tcl (write new commands in D for Tcl)?


I am on Windows 10 x86_64.

thank you.


I've created a wrapper around Tcl/Tk to create GUI's here:

https://github.com/nomad-software/tkd

It uses the library found here:

https://github.com/nomad-software/tcltk

In the project, I've created a simple interpreter which handles 
communicating to Tcl here:


https://github.com/nomad-software/tkd/blob/master/source/tkd/interpreter/tcl.d

There is a method on that class for creating commands for use in 
Tcl.


Re: DMD OSX / Segfault 11

2016-02-03 Thread anonymous via Digitalmars-d-learn

On 03.02.2016 14:16, Robert M. Münch wrote:

Well, it should of course be:

BaseOperator: Value {
}


Still missing "class". I know I'm being pedantic, but if you're being 
sloppy here, how do I know that you're not being sloppy where it matters?



Casting between class types that have an inheritance relation, like
Value and BaseOperator, does make sense (upcat/downcast).


Yes, that's what I need.


Do that then. Cast between class types. Pointers don't by you anything here.


If anything, you should be casting between Value* and BaseOperator*
(both pointer types) if you want to do something with pointers.


I tried this, but that doesn't work either.


Yeah, you can't check if the downcast succeeded this way. Casts between 
pointers always succeed (and then fail horribly at run-time).



But you very seldom need pointers to class references. Just return
Value from get, and cast to BaseOperator.


But am I not getting a copy then? I want to avoid copying objects as
much as possible.


No, you're not getting a copy. Classes are reference types. That means, 
variables of class types are references already. They're pointers in 
disguise.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 13:12:13 UTC, CraigDillabaugh 
wrote:
C++ is likely searched the most because every time you need to 
do anything non-trivial you need to go on Stack Overflow or a 
similar site and find out how to do it, because there is very 
little chance you would ever be able to figure out the syntax 
on your own :o)


:-)

"C++" has a 30% drop in weekends so it is certainly affected by 
business usage.




Re: Using C++ everywhere D is makes things worst

2016-02-03 Thread jkpl via Digitalmars-d

On Wednesday, 3 February 2016 at 13:27:45 UTC, karabuta wrote:
I understand many D programmers were formally(or still is or 
in-between) C++ but most explanations for certain things tells 
me either D is a C++ clone or I need to learn C++ first before 
I really understand D (kind of like C++ is a subset of D). I 
must say that I never coded C++ beyond "hello, world!" and I 
don't plan to.


This is not about me and what I want, it is about improving the 
D learning resources available. Explaining D code by using 
C/C++ code and or theory confuses me as a learner. D alone is 
too much to learn.


You neither need a C nor a CPP background to learn D.
Before starting to learn D I was only (and barely) reading C, 
just because of the few times I had to deal with C headers file 
when using bindings in another lang.


You can start D from scratch. This is not because there are 
comparisons (such as the wiki sections: comming from...) that 
it's mandatory.


For example with

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

you can start from scratch, at least the book is advertised so.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Martin Tschierschke via Digitalmars-d
On Wednesday, 3 February 2016 at 10:43:44 UTC, Ola Fosheim 
Grøstad wrote:
On Wednesday, 3 February 2016 at 10:41:40 UTC, Martin 
Tschierschke wrote:
open for more people. Like me, frustrated from ever faster 
computers becoming slower by scripting languages and Browsers 
doing the job, where a real alternative is around the corner: 
D.


D has been around the corner for a D-ecade. The corner is 
constantly moving so that is obviously not a winning strategy.

If something is around the corner, you must know!

So I got it via this:
http://www.heise.de/developer/meldung/Programmiersprache-D-Compiler-ist-jetzt-selbst-in-D-geschrieben-2869589.html

The most read IT News Ticker in Germany, pointing to D, saying 
that the D compiler now is written in D, and what made me 
interested, the reference to C++ and Ruby.

So I started to read Wikipedia and in the end I gave it a try.

What about making a special voting list/page, where every one 
registered to the forum, can
put in, why he/she is using D and vote for other arguments giving 
+ or maybe - points.


And a special second list, where people can vote, which topic of 
D (language or environemt) need to be improved most?








Re: Cannot get Derelict to work

2016-02-03 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 13:04:54 UTC, Mike Parker wrote:


latest release. Unfortunately, they do not provide a binary 
distribution, so you will have to build the DLL from source or 
find somewhere that makes it available prebuilt DLLs available 
for you.


Actually, they do provide prebuilt binaries for Windows now [1] . 
I'm so used to compiling it myself I forgot all about that.


[1] http://www.glfw.org/download.html


Using C++ everywhere D is makes things worst

2016-02-03 Thread karabuta via Digitalmars-d
I understand many D programmers were formally(or still is or 
in-between) C++ but most explanations for certain things tells me 
either D is a C++ clone or I need to learn C++ first before I 
really understand D (kind of like C++ is a subset of D). I must 
say that I never coded C++ beyond "hello, world!" and I don't 
plan to.


This is not about me and what I want, it is about improving the D 
learning resources available. Explaining D code by using C/C++ 
code and or theory confuses me as a learner. D alone is too much 
to learn.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 08:23:39 UTC, Sönke Ludwig wrote:
Maybe it's showing different results to you, but the numbers I 
get are tiny. Also, picking arbitrary search terms skews the 
results considerably.


Not really, you look at trends over time not absolutes.



Results using Google's categorization instead:


I have found the Google classification to be wrong in the past.

So I think it is better to find a term that is unique for the 
language, I don't know any such term for Rust though.




Re: Interested in D, spec confuses me.

2016-02-03 Thread Kagamin via Digitalmars-d

On Wednesday, 3 February 2016 at 00:43:36 UTC, Dicebot wrote:
The fact DMD doesn't do anything scary right now when you do it 
is a mere coincidence and may change in any release with no 
notice.


DMD performs some immutable optimizations and people noticed it.


Re: Detecting exception unwinding

2016-02-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 03, 2016 11:09:00 Ola Fosheim Grøstad via 
Digitalmars-d-learn wrote:
> Is there some reliable way to detect that a destructor is called
> because of exception unwinding?
>
> I basically want to change behaviour within a destructor based on
> whether the destructor is called as a result of a regular or an
> exceptional situation.
>
> E.g. commit changes to a database on regular destruction, or
> inhibit logging during exception unwinding.

AFAIK, there is no way to detect whether an exception is in flight or not
aside from the cases where scope(failure) or catch would catch the
exception, and from what I recall of the last time that someone asked this
question, the consensus was that it couldn't be done - but maybe I'm
remembering incorrectly. I am pretty sure that this was asked within the
last few months though, so if you search D.Learn, you can probably find that
discussion.

- Jonathan M Davis




Re: std.typecons.Proxy requires a nothrow destructor and toHash?

2016-02-03 Thread Marc Schütz via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 10:16:56 UTC, Saurabh Das wrote:
Why doesn't this work? Is it a requirement that a proxied 
struct must have a nothrow destructor and toHash?


It used to work in 2.066.1; bisecting points to this PR:
https://github.com/D-Programming-Language/phobos/pull/3043

When bisecting between 2.066 and 2.067, there are other 
candidates:

https://github.com/D-Programming-Language/phobos/pull/3042
https://github.com/D-Programming-Language/dmd/pull/4459
https://github.com/D-Programming-Language/druntime/pull/1188

Unlikely:
https://github.com/D-Programming-Language/phobos/pull/3001
https://github.com/D-Programming-Language/phobos/pull/3043
https://github.com/D-Programming-Language/dmd/pull/4452
https://github.com/D-Programming-Language/dmd/pull/4463

Please file a bug report at:
https://issues.dlang.org/enter_bug.cgi


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 12:06:30 UTC, Martin 
Tschierschke wrote:

If something is around the corner, you must know!


There are many corners. Some, like the corner of compiled 
languages with automatic memory management and high level 
features have moved a lot in the past few years (Swift and Go). 
It is gone. There is no way for D to catch up with Swift and Go.


The other corner, taken by C, C++ and now also Rust, moves a lot 
slower and is in some areas incapable of moving. So I think the 
current focus on interfacing with C++ is the right focus, just 
keep focused on it. D needs to reach parity with common C++ 
features and then do it better across the board.


C++ is basically incapable of undoing past bad design decisions. 
D also have baggage, but D is fortunate enough to have commercial 
users who have clearly stated that they welcome breaking changes, 
so D can thankfully get rid of bad design choices.


C++ cannot break existing code, and Rust has gone down a trail of 
semantics that leads to complicated compiler design. That's to 
D's advantage, if D avoid going down similar complicated routes 
(unfortunately some DIPs suggests otherwise). There's lots of 
potential there if the D designers stay focused on that target 
and take the fast path (avoid convoluted semantics and compiler 
requirements).



And a special second list, where people can vote, which topic 
of D (language or environemt) need to be improved most?


The historical challenge for D is a tendency to spread out. 
Voting is no good, it takes away focus. Then you are back to 
hunting down many corners, and D will remain one step behind.




Re: Cannot get Derelict to work

2016-02-03 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 13:07:51 UTC, Mike Parker wrote:
On Wednesday, 3 February 2016 at 13:04:54 UTC, Mike Parker 
wrote:



latest release. Unfortunately, they do not provide a binary 
distribution, so you will have to build the DLL from source or 
find somewhere that makes it available prebuilt DLLs available 
for you.


Actually, they do provide prebuilt binaries for Windows now [1] 
. I'm so used to compiling it myself I forgot all about that.


[1] http://www.glfw.org/download.html


And just to be clear, the typical thing to do on Windows is to 
put this in the same directory as the binary. I like to set a 
targetPath directive in my dub.sdl/json for a bin directory so 
that the executable is created there. Then I just save the dll in 
the bin directory.


// dub.json
"targetPath": "bin",

// dub.sdl
targetPath "bin"

So then the project tree looks like:

- myproj
-- bin
--- glfw3.dll
-- source
--- app.d
-- dub.sdl

Your exectuable will be output to the bin directory and 
DerelictGLFW3.load should find the DLL just fine.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread jmh530 via Digitalmars-d
On Wednesday, 3 February 2016 at 08:53:27 UTC, Ola Fosheim 
Grøstad wrote:


You have to make a qualitative judgement. Terms such as "dlang" 
has only been in used in recent years and probably only by 
invested users. It is difficult to find terms for "D" that have 
enough volume to show up. "d programming language" is probably 
only used by non-users, it shows a clear spike in october 2004, 
july 2005, january 2007, july 2014, but a general falling 
trend. While "dlang" is more stable.


I never search dlang. I typically search d language


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread CraigDillabaugh via Digitalmars-d
On Wednesday, 3 February 2016 at 08:00:20 UTC, Ola Fosheim 
Grøstad wrote:

On Wednesday, 3 February 2016 at 07:50:07 UTC, cym13 wrote:
Also I find showing even little achievements good for the 
troop's morale.


Well, it is better to have good information. If you zoom in on 
the link above you'll see some interesting facts on daily 
patterns. The Swift and Go graph go way down in weekends, so 
they are used by businesses. Rust does not, so it currently is 
appealing to hobbyists. D should think about capturing some of 
that Rust audience.


What is important is to be realistic, so that a good strategy 
can be selected.


Right now Rust may have 10x more interest than D, and C++ 40x 
more interest than Rust. Just a guesstimate based on search 
frequencies, but it stacks up with github.


C++ is likely searched the most because every time you need to do 
anything non-trivial you need to go on Stack Overflow or a 
similar site and find out how to do it, because there is very 
little chance you would ever be able to figure out the syntax on 
your own :o)


Counting time difference.

2016-02-03 Thread holo via Digitalmars-d-learn

Hello

I'm trying to count time difference to count time for how long 
instance is running. Here is how am i doing it:



import std.stdio, sigv4, kxml.xml, awsxml;
import std.datetime;
import std.string;



void main()
{
SigV4 req = new SigV4;
IfResult result = req.go;
AwsXml instancesData = new AwsXml(result.retResult);
auto instsData =  instancesData.getInstancesData;


foreach(instData; instsData)
{



auto currentTime = Clock.currTime();
   // auto currentStrTime = 
currentTime.toISOExtString().split(".")[0];
   // auto currTime = 
SysTime.fromISOExtString(currentStrTime);


auto launchStrTime = instData.instanceLaunchTime;
auto launchTime = SysTime.fromISOExtString(launchStrTime);

auto diff = currentTime - launchTime;

auto zagadka = launchTime + diff;




writeln(instData.instanceId ~ " " ~ instData.instanceName 
~ " " ~ instData.instanceState ~ " " ~ 
instData.instanceLaunchTime ~ " " ~ instData.instanceReason);

writeln(launchTime);
writeln(currentTime);
writeln(diff);
writeln(zagadka);
}
}

but the results do not match (launchTime + diff != currentTime)


...

2015-Mar-17 14:32:24Z
2016-Feb-03 23:21:41.2374511
46 weeks, 1 day, 7 hours, 49 minutes, 17 secs, 237 ms, 451 μs, 
and 1 hnsec

2016-Feb-03 22:21:41.2374511Z


When i start same program on server in different timezone 
difference is much higher (more than hour). Why it is happening? 
Timezones shouldnt have influence on such equation.


//holo


Re: Get the return type of the function

2016-02-03 Thread sigod via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 19:21:06 UTC, Meta wrote:

On Wednesday, 3 February 2016 at 18:40:27 UTC, xtreak wrote:
Thanks. I was trying to get the return type of lambdas. I was 
trying the following and got an error. I was using dpaste with 
dmd 2.070


writeln(ReturnType!(a =(a *a)))

Error: template instance f662.main.ReturnType!((a) => a * a) 
does not match template declaration ReturnType(func...) if 
(func.length == 1 && isCallable!func)


Ah, I see. I'd like to test something; can you please change 
`(a) => a * a` to

`(int a) => a * a` and post the results?


This works.

http://dpaste.dzfl.pl/92c254ef6cf6


Re: Call D from TCL

2016-02-03 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 14:19:32 UTC, Vasileios 
Anagnostopoulos wrote:

Thank you very much. I investigate

Tcl_CmdProc

more closely.

On Wed, Feb 3, 2016 at 3:50 PM, Gary Willoughby via 
Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote:


On Wednesday, 3 February 2016 at 12:20:42 UTC, Vasileios 
Anagnostopoulos wrote:



[...]


I've created a wrapper around Tcl/Tk to create GUI's here:

https://github.com/nomad-software/tkd

It uses the library found here:

https://github.com/nomad-software/tcltk

In the project, I've created a simple interpreter which 
handles communicating to Tcl here:



https://github.com/nomad-software/tkd/blob/master/source/tkd/interpreter/tcl.d

There is a method on that class for creating commands for use 
in Tcl.


Here's the reference to the C interface:

https://www.tcl.tk/man/tcl/TclLib/contents.htm


Re: Dwarf Exception Handling now on FreeBSD!

2016-02-03 Thread Brad Roberts via Digitalmars-d

On 2/3/16 11:28 AM, Jonathan M Davis via Digitalmars-d wrote:

On Sunday, 31 January 2016 at 06:34:26 UTC, Walter Bright wrote:

32/64 support now on Linux and FreeBSD.

  https://github.com/D-Programming-Language/dmd/pull/5376

Turns out that FreeBSD is close enough to Linux that it "just worked".


It's always nice when that happens, especially when there's not much 
FreeBSD-specific work going on,
and the autotesters have generally been on older versions of FreeBSD such that 
issues on the newer
versions don't always get noticed (e.g. for a while there, the shared library 
stuff passed the tests
on FreeBSD 8 but not later; fortunately Martin got that fixed though).

- Jonathan M Davis


I haven't put much time into investigation, but the last time I tried it, neither 9 nor 10 passed 
the test suite.  If someone puts in the effort to get either or both of those working, I'd be happy 
to upgrade some of the freebsd testers to newer versions.  There's currently 4 freebsd machines, so 
plenty of room to have a mix of versions.  Not enough to test every combination of version and 
bitness, but enough to allow randomness to expose issues.


Re: Interested in D, spec confuses me.

2016-02-03 Thread Bambi via Digitalmars-d

On Wednesday, 3 February 2016 at 12:12:03 UTC, Kagamin wrote:
Immutability provides stronger guarantee that allows more 
optimizations, e.g. reading the same immutable value is known 
to result in the same value so such repeated reading can be 
optimized out, in C such optimization is illegal, because const 
data can change over time.


In C, you can only make pointers to const data a const pointer. 
The guarantee is built in there. Sure you can cast the address of 
a const to a regular pointer but then you are kind of going out 
of your way to break the rules and deliberately shoot yourself in 
the foot. I'm pretty sure casting away a const pointer to a const 
value is undefined behaviour.


Re: Article: We're Overlooking A Key Part of C/C++ to D User Migration

2016-02-03 Thread Nick Sabalausky via Digitalmars-d-announce

On 02/03/2016 02:33 PM, H. S. Teoh via Digitalmars-d-announce wrote:

On Wed, Feb 03, 2016 at 07:25:55PM +0200, Dicebot via Digitalmars-d-announce 
wrote:


The problem is how you are going to expose templated stuff which
dominates most useful D libraries.


This is certainly an interesting idea worth exploring, and certainly
doable for plain ABI interop, as Dicebot says.

For templates... I dunno, some stuff is probably untranslatable, or at
least, can't be translated into a form that's suitable for end-users,
like alias parameters, variadics, tuple/AliasSeq shenanigans, etc.. But
some of the simpler stuff might be doable.

Perhaps... this is a crazy idea that just occurred to me -- write a D to
C++ template syntax translator?


Well, I don't think it's worth (at least short term anyway) getting too 
caught up in the idea of more advanced stuff like that, and equivalent 
template semantics and such, being usable from the C/C++ side of an 
interface.


Much of the time, the bulk of a lib's use-cases can be exposed via 
simple wrappers that expose a simplified API. Naturally, this wouldn't 
be as nice as benefiting from D's full feature set, but if you're not 
writing *in* D then you're kind of forgoing a lot of those niceties anyway.


Longer term, maybe more tricks could be devised to offer more benefits 
to a D lib's C/C++ users. Or maybe not. But either way, that's not 
really the important part. The important part is just straightforward 
out-of-the-box access to a D lib's main use-cases, rather than 
reproducing as much of the D experience as possible.


Perhaps I was overstating a bit saying "every" D library. Naturally, 
some libs will make more or less sense to use from C/C++ than others. 
But with just a little thought given to "What is this lib's MAIN 
purpose? What are the IMPORTANT features that could be wrapped up in a 
simpler C-accessible API, verses merely D niceties that aren't necessary 
for C/C++ users to gain usefulness from this lib?" With just a little 
thought given to that, I think we could offer some actual usefulness to 
C/C++ users, which simultaneously benefits them and helps our street cred.


Of course I'm not saying D libs should jettison D niceties for the sake 
of C/C++ compatibility. But just offer whatever C/C++-sensible subset 
they reasonably can to the C/C++ world.


From the C/C++ perspective, think of it like exposing a C/C++ library 
with "the core of this is written in D" as an implementation detail. Of 
course, actual D programs would get even MORE benefit from the lib, by 
bypassing the "funneling this into C/C++-compatible form" layer.




Re: Detecting exception unwinding

2016-02-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 03, 2016 11:47:35 Ola Fosheim Grøstad via 
Digitalmars-d-learn wrote:
> On Wednesday, 3 February 2016 at 11:41:28 UTC, Jonathan M Davis
> wrote:
> > AFAIK, there is no way to detect whether an exception is in
> > flight or not aside from the cases where scope(failure) or
> > catch would catch the exception, and from what I recall of the
> > last time that someone asked this question, the consensus was
> > that it couldn't be done - but maybe I'm remembering
> > incorrectly. I am pretty sure that this was asked within the
> > last few months though, so if you search D.Learn, you can
> > probably find that discussion.
>
> :-/
>
> I am looking for something like this:
>
> http://en.cppreference.com/w/cpp/error/uncaught_exception
>
> It is useful for certain types of libraries where you want to
> cancel out effects "undo commits" when exceptional situations
> arise.

Yeah, and I'm pretty sure that we don't have anything like that at this
point. Feel free to create an enhancement request for it:

https://issues.dlang.org

At least that way, it's kept track of, though I certainly have no idea when
it might be implemented (presumably when someone needs it enough that they
take the time to do so).

- Jonathan M Davis



Re: reduce -> fold?

2016-02-03 Thread Timon Gehr via Digitalmars-d

On 02/03/2016 09:12 PM, Atila Neves wrote:


https://github.com/D-Programming-Language/phobos/pull/3968

I think fold should be nothrow, but maybe that's just me. It's also a
massive pain to make it that way, so I didn't for now.


Returning Unqual!(ElementType!R).init makes no sense though.
The "correct" result of fold!f([]) is a (often, the) value 'a' such that 
for any 'b', 'f(a,b)==b' (which is the canonical choice of "seed"), but 
there is no way for fold to infer such a value.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 19:48:48 UTC, Bubbasaur wrote:
Yes they leave and go to another language with a lot of tools 
but the new language design sucks or it's slow to developing or 
have restrictions whatever.


It is possible to position a language as a focused niche 
alternative, people like to bet on the underdog. That's what 
attracted me to D 10 years ago. Walter was this courageous geek 
that singlehandedly challenged the big and bloated C++. I 
realized D was not finished, but had a favourable impression 
because my initial expectations were low.


That meant I had low resistance to downloading D again a few 
years later, and so on. So, even if people are leaving, it is 
important that they leave without resentment, after all if they 
were willing to give D a spin once, they might be willing to spin 
it up a few more times later on. Feel good.



Couldn't some of those "new" people see a great potential on D 
and write new tools that is lacking right now?


They could, but are they likely to? The most likely group to do 
system level programming are system level programmers, so 
realistic articles, presentations and talks that make D look 
technically interesting are more likely to win them over.


As the "most voted topics" on StackOverflow shows, D has a 
perceived credibility problem. Being honest and realistic is the 
best way to address that, IMO.


Perpetrating the idea that D is as big as Swift just hurts D's 
credibility.




Re: reduce -> fold?

2016-02-03 Thread John Colvin via Digitalmars-d

On Wednesday, 3 February 2016 at 21:45:04 UTC, Timon Gehr wrote:

On 02/03/2016 09:12 PM, Atila Neves wrote:


https://github.com/D-Programming-Language/phobos/pull/3968

I think fold should be nothrow, but maybe that's just me. It's 
also a

massive pain to make it that way, so I didn't for now.


Returning Unqual!(ElementType!R).init makes no sense though.
The "correct" result of fold!f([]) is a (often, the) value 'a' 
such that for any 'b', 'f(a,b)==b' (which is the canonical 
choice of "seed"), but there is no way for fold to infer such a 
value.


I wish we had some standardised way to express what the 
identities (and maybe inverses) are for a given type under given 
operations.


Re: DMD OSX / Segfault 11

2016-02-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/3/16 8:17 AM, Robert M. Münch wrote:

On 2016-02-02 18:59:35 +, Steven Schveighoffer said:


If this is valid D, I'm not sure what it means :)


There was one type, the rest I stripped totally away as IMO it's not
relevant for the actual problem.



Very relevant: what are you declaring? A class, struct, template, enum?

-Steve


Re: This feels wrong

2016-02-03 Thread Shachar Shemesh via Digitalmars-d

On 02/02/16 21:24, Ali Çehreli wrote:

On 02/02/2016 07:21 AM, Shachar Shemesh wrote:

 > it is a potential pitfall when implementing that I don't think is
 > documented.

Good catch! Please either open a documentation bug for this or fork the
repo and fix it yourself. :) (Hopefully, there is an 'Improve this page'
link on that page.)

Ali



https://github.com/D-Programming-Language/dlang.org/pull/1224


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Bubbasaur via Digitalmars-d

On Wednesday, 3 February 2016 at 07:06:47 UTC, cym13 wrote:
It's all true, D rose up 6 positions: 
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html


Very good, and different from the other guy I think this list is 
very reasonable, just look the top languages and their positions 
and I agree.


So guys let's celebrate this! :)

Bubba.


Re: reduce -> fold?

2016-02-03 Thread Atila Neves via Digitalmars-d
On Wednesday, 3 February 2016 at 00:57:18 UTC, Andrei 
Alexandrescu wrote:

On 2/2/16 3:50 PM, Atila Neves wrote:
On Tuesday, 2 February 2016 at 20:02:39 UTC, Andrei 
Alexandrescu wrote:

On 2/2/16 11:02 AM, Atila Neves wrote:
On Friday, 29 January 2016 at 12:08:01 UTC, Andrei 
Alexandrescu wrote:

As has been discussed before there's been discussion about
std.algorithm.reduce taking the "wrong" order of arguments 
(its
definition predates UFCS). I recall the conclusion was 
there'd be
subtle ambiguities if we worked reduce to implement both 
orders.


So the next best solution is to introduce a new name such 
as the

popular "fold", and put them together in the documentation.


Thoughts?

Andrei


Definitely yes.


Atila, wanna do the honors? -- Andrei


If it's not urgent, sure.


Thanks! And don't forget: in D, everything is top priority. -- 
Andrei


Of course it is ;)

I guess this is to be a brand new PR? I've been reading the old 
one and the discussions. A lot of unanswered questions there and 
I have a new opinion on at least one of them.


Atila


Re: Cannot get Derelict to work

2016-02-03 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 13:04:54 UTC, Mike Parker wrote:

- First I tried to create a VisualD project on Windows, and to 
manually compile derelict-util and derelict-glfw3:


FYI, this thread motivated me to revisit the manual compilation 
instructions in the Derelict docs [1]. I've outline a different 
approach using dub fetch that is probably easier to get started 
with.


[1] http://derelictorg.github.io/compiling.html#nodub



Re: [dlang.org] new forum design

2016-02-03 Thread Bubbasaur via Digitalmars-d

On Wednesday, 3 February 2016 at 14:19:14 UTC, ZombineDev wrote:
That's strange. Here's what I get: http://imgur.com/SZbJedj on 
Chrome 48, Ubuntu 15.10 amd64.


What browser, OS, etc. are you using?


Using Chrome and I just have Ublock Origin here, I tried 
dev-tools and there are NO errors or anything, them I changed the 
Font family from "ROBOT SLAB" to "SAN SERIF" and this is what I 
got: http://i.imgur.com/zuaLXx0.png


Bubba.


Re: D's equivalent to C++'s std::move?

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 15:05:39 UTC, Sönke Ludwig wrote:
For std.move, isn't the only place where an exception can be 
thrown in the destructor (which shouldn't throw)? It uses 
memcpy to move the memory around to circumvent any extended 
construction logic.


Not sure if you are talking about something else, but in C++ if 
you do


"somefunction(std::move(resource))"

then somefunction can throw and the resource remains untouched 
(if implemented in a reasonable fashion).



In D, std.move(...) has this implementation:

private T moveImpl(T)(ref T source)
{
T result = void;
moveEmplace(source, result);
return result;
}

So clearly by the time somefunction is called, the resource is 
already moved and an exception will cause permanent damage?






Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Martin Tschierschke via Digitalmars-d
On Wednesday, 3 February 2016 at 12:21:05 UTC, Ola Fosheim 
Grøstad wrote:
On Wednesday, 3 February 2016 at 12:06:30 UTC, Martin 
Tschierschke wrote:

If something is around the corner, you must know!


There are many corners. Some, like the corner of compiled 
languages with automatic memory management and high level 
features have moved a lot in the past few years (Swift and Go). 
It is gone. There is no way for D to catch up with Swift and Go.
May be, I did not start to learn anything about these languages 
yet,

so I just looked on the Wikipedia pages, and I am not convinced.
Why? Syntax not C compatible, but for me this is a very strong 
argument, because everybody is defining his own similar elements 
and after "learning" some
Languages 
(Basic,Z80Asm,Pascal,Comal,Prolog,(x86Asm),C,C++,Perl,Php,Ruby 
(RoR))

I am quite happy, that D offers a 'known' syntax.
And the opportunity to use it for scripting - compiling very fast 
(#!-rdmd Execution).


By learning D, I can write a super fast web applications (vibe.d) 
+

stand alone programs for any purpose and even do scripting tasks.

Is there any other language candidate offering the same?

The other corner, taken by C, C++ and now also Rust, moves a 
lot slower and is in some areas incapable of moving. So I think 
the current focus on interfacing with C++ is the right focus, 
just keep focused on it. D needs to reach parity with common 
C++ features and then do it better across the board.

Sounds right.

[...]

And a special second list, where people can vote, which topic 
of D (language or environment) need to be improved most?


The historical challenge for D is a tendency to spread out. 
Voting is no good, it takes away focus. Then you are back to 
hunting down many corners, and D will remain one step behind.


The voting purpose is exactly to see what are the improvements 
really needed, to get this focus. I think, it is not so useful, 
that there are already min. 4 different DUB modules to access 
MySQL/MariaDB).


Re: Call D from TCL

2016-02-03 Thread Vasileios Anagnostopoulos via Digitalmars-d-learn
Thank you very much. I investigate

Tcl_CmdProc

more closely.

On Wed, Feb 3, 2016 at 3:50 PM, Gary Willoughby via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Wednesday, 3 February 2016 at 12:20:42 UTC, Vasileios Anagnostopoulos
> wrote:
>
>> Is there any example,framework or tutorial on how to call D from Tcl
>> (write new commands in D for Tcl)?
>>
>> I am on Windows 10 x86_64.
>>
>> thank you.
>>
>
> I've created a wrapper around Tcl/Tk to create GUI's here:
>
> https://github.com/nomad-software/tkd
>
> It uses the library found here:
>
> https://github.com/nomad-software/tcltk
>
> In the project, I've created a simple interpreter which handles
> communicating to Tcl here:
>
>
> https://github.com/nomad-software/tkd/blob/master/source/tkd/interpreter/tcl.d
>
> There is a method on that class for creating commands for use in Tcl.
>



-- 
Dr. Vasileios Anagnostopoulos (MSc,PhD)
Researcher/Developer
ICCS/NTUA 9 Heroon Polytechneiou Str., Zografou 15773 Athens,Greece
T (+30) 2107723404 M (+30) 6936935388
E va...@mail.ntua.gr www.ntua.gr<
http://www.ntua.gr/>


Re: [dlang.org] new forum design

2016-02-03 Thread ZombineDev via Digitalmars-d

On Wednesday, 3 February 2016 at 01:55:16 UTC, bubbasaur wrote:
On Sunday, 24 January 2016 at 10:39:51 UTC, Vladimir Panteleev 
wrote:
The font size looks larger than I recall seeing it in the iOS 
simulator. I'm switching OSes so can't look at the moment 
though.


I'm thinking that the end-all solution would probably be a 
font size adjustment setting.


So talking about fonts, in this page: 
http://dlang.org/spec/const3.html at the end:


"Implicit Conversions" - The table is missing the ticks over 
the conversions. Look what I'm seeing there: 
http://i.imgur.com/L4a6bx6.png


Bubba.


That's strange. Here's what I get: http://imgur.com/SZbJedj on 
Chrome 48, Ubuntu 15.10 amd64.


What browser, OS, etc. are you using?


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d

On Wednesday, 3 February 2016 at 14:34:09 UTC, WebFreak001 wrote:
Combining that with the categories now gives a graph which 
looks very likely to be correct:


https://www.google.com/trends/explore#cat=0-5-31=%2Fm%2F01kbt7%2C%20%2Fm%2F0dsbpg6%2C%20%2Fm%2F09gbxjr%2C%20%2Fm%2F010sd4y3=q=Etc%2FGMT-1


That would make D very popular in China and Russia, compared to 
the US. Maybe it is, I don't know.





Re: D's equivalent to C++'s std::move?

2016-02-03 Thread Sönke Ludwig via Digitalmars-d

Am 03.02.2016 um 00:21 schrieb Ali Çehreli:

On 02/02/2016 03:09 PM, Ola Fosheim Grøstad wrote:

On Tuesday, 2 February 2016 at 22:36:22 UTC, Ali Çehreli wrote:

This question has been brought up a lot lately. I've decided to look
at this more seriously yesterday.


Nice to see that others are playing around with this, I don't have time
to check your code, but one key issue with move semantics is exception
safety.

AFAICT D's "std.move" is insufficient, as it would null out the original
pointer prematurely and when an exception is thrown the resource will
disappear rather than simple remain "unmoved".



Exactly. I've saved my rear end by inserting a TODO comment just before
posting the code: :p

 /* TODO: Be exception-safe; don't destroy before succesful
  * construction. */
 if (occupied) {
 destroy_at(i);
 }

 emplace(place, args);

Ali



For std.move, isn't the only place where an exception can be thrown in 
the destructor (which shouldn't throw)? It uses memcpy to move the 
memory around to circumvent any extended construction logic.




Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Martin Tschierschke via Digitalmars-d
On Wednesday, 3 February 2016 at 14:34:26 UTC, Ola Fosheim 
Grøstad wrote:

[..]
You know Comal? Isn't that a danish language that never got 
much traction outside Denmark? I remember reading danish 
computer magazines in the late 80s that devoted many pages to 
it.
Comal, Yes, it was one of our learning languages in 
School...~1984?

[...]
The voting purpose is exactly to see what are the improvements 
really needed, to get this focus.


If the D community wasn't spread out: economic/scientific, 
games, web, hobby, professional, educated, non-educated... 
There tends to be contention between those that want to see D 
strive to become a potent system level programming language and 
those that want to see D become a convenient compiled scripting 
language. Trying to move in both directions at the same time is 
bound to lead to a net slow down in progress IMHO.

Ok.






Re: Interested in D, spec confuses me.

2016-02-03 Thread Steven Schveighoffer via Digitalmars-d

On 2/2/16 8:42 PM, Chris Wright wrote:

On Tue, 02 Feb 2016 15:41:07 -0800, H. S. Teoh via Digitalmars-d wrote:


Furthermore, since const provides actual guarantees that the called
function isn't going to touch the data, this opens up optimization
opportunities for the compiler.


const opens up optimizations at the call site, so it's useful. immutable
is useful on top of const because it allows optimizations within the
function.

Want to memoize a function? If it takes const(char[]), you have to copy
your input and later check the entire array to see if the parameters
match a previous call. If it takes an immutable(char[]), you can compare
pointers.


This isn't exactly right. If I call a function with "hello", I'd want it 
to memoize if the function is called with "hello" that resides elsewhere.


What *is* true is that you can safely save the array (pointer + len) of 
"hello" and be sure it won't change when you check against it later. 
With const(char[]), you'd need to allocate a new block to make sure it 
doesn't change.


-Steve


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread WebFreak001 via Digitalmars-d

On Wednesday, 3 February 2016 at 09:09:20 UTC, Sönke Ludwig wrote:
BTW, this one (using the "programming" category) looks like it 
could be somewhat neutral: 
https://www.google.com/trends/explore#cat=0-5-31=d%20language%2C%20rust%20language%2C%20go%20language%2C%20swift%20language=q=Etc%2FGMT-1


Combining that with the categories now gives a graph which looks 
very likely to be correct:


https://www.google.com/trends/explore#cat=0-5-31=%2Fm%2F01kbt7%2C%20%2Fm%2F0dsbpg6%2C%20%2Fm%2F09gbxjr%2C%20%2Fm%2F010sd4y3=q=Etc%2FGMT-1


On Wednesday, 3 February 2016 at 10:43:44 UTC, Ola Fosheim 
Grøstad wrote:

D has been around the corner for a D-ecade.


I laughed.


Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 3 February 2016 at 14:14:39 UTC, Martin 
Tschierschke wrote:
Why? Syntax not C compatible, but for me this is a very strong 
argument, because everybody is defining his own similar 
elements and after "learning" some  Languages 
(Basic,Z80Asm,Pascal,Comal,Prolog,(x86Asm),C,C++,Perl,Php,Ruby 
(RoR))

I am quite happy, that D offers a 'known' syntax.


What is considered a "known" syntax changes over time though. You 
know Comal? Isn't that a danish language that never got much 
traction outside Denmark? I remember reading danish computer 
magazines in the late 80s that devoted many pages to it.


By learning D, I can write a super fast web applications 
(vibe.d) +
stand alone programs for any purpose and even do scripting 
tasks.


Is there any other language candidate offering the same?


Not if you want the kind of C++ style metaprogramming that D 
offers. Go is ok for web applications, Python is ok for 
scripting; I am inclined to use those for web as they are 
supported by Google Cloud. If you want to do everything with one 
language D might be closer.


I personally don't see much advantage in using one language for 
everything, but some people see it as a major benefit.


The voting purpose is exactly to see what are the improvements 
really needed, to get this focus.


If the D community wasn't spread out: economic/scientific, games, 
web, hobby, professional, educated, non-educated... There tends 
to be contention between those that want to see D strive to 
become a potent system level programming language and those that 
want to see D become a convenient compiled scripting language. 
Trying to move in both directions at the same time is bound to 
lead to a net slow down in progress IMHO.


I think, it is not so useful, that there are already min. 4 
different DUB modules to access MySQL/MariaDB).


The D eco system suffers a bit from having eager programmers, but 
not enough of them, so you have all these libraries that are 
created, but not polished and maintained.





Re: TIOBE February 2016.... 15 ?!

2016-02-03 Thread WebFreak001 via Digitalmars-d
On Wednesday, 3 February 2016 at 14:41:01 UTC, Ola Fosheim 
Grøstad wrote:
That would make D very popular in China and Russia, compared to 
the US. Maybe it is, I don't know.


It puts Japan on the first place. Considering how the #dlang 
twitter hashtag looks like this could be very true.


Re: Interested in D, spec confuses me.

2016-02-03 Thread Kagamin via Digitalmars-d
Another nice property of immutable data is that it can be safely 
shared between threads: const data that is a readonly view into 
changing mutable data may require locking to get consistent view 
of data; immutable data doesn't require locking, since it doesn't 
change.


Re: inner functions calling each other - how to do this with inner struct?

2016-02-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 14:01:24 UTC, Ivan Kazmenko 
wrote:

1. What works.


Read my post here:

http://stackoverflow.com/questions/34398408/struct-declaration-order/34398642#34398642

then see if you can use the same reasoning on your problem.


Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn

This code:

import std.stdio;

int very_very_long_function(in int k)
{
if (!__ctfe) writeln("Can't use ctfe!");
return k/2;
}

void main()
{
enum first = very_very_long_function(10);
writeln("First is ", first);

auto second = very_very_long_function(12);
writeln("Second is ", second);

auto third = first;
third += 1;
writeln("Third is ", third);
}

Why second init doesn't work with CTFE? It could be something 
like third, but with one less copy. What am I missing?


Re: How do you get a hexstring from a base10 string -or- from a number?

2016-02-03 Thread Enjoys Math via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:

I am making a method called:

@property string debugIDString() {
in {
  assert(super.toHash() == this.toHash());
} body {

}


body { // is currently:
  return to!string(this.toHash());
}

and is returning a base10 string, so how would I return a hex 
string so I can compare numbers displayed to the debugger 
addresses in visual D?


print function

2016-02-03 Thread ixid via Digitalmars-d-learn
It would be nice to have a simple writeln that adds spaces 
automatically like Python's 'print' in std.stdio, perhaps called 
print.


Re: D's equivalent to C++'s std::move?

2016-02-03 Thread Matt Elkins via Digitalmars-d

On Tuesday, 2 February 2016 at 22:36:22 UTC, Ali Çehreli wrote:
Have you used something similar before? Is this a correct 
approach to this problem?


This reminds me of C++ prior to C++11; there were libraries with 
whole sets of data structures intended to make move-like 
semantics work. While functional (C++ certainly did fine with it 
for many years), it's not ideal. That said, I don't know a better 
solution. For my resource handles, I am expanding the array and 
then assigning the handle in to the new slots, but that's only 
acceptable because I happen to know my assignments are cheap. And 
even then, it is a bit ugly.


Thus far in my (admittedly short) explorations of D, this has 
been my only major gripe. It feels like a significant step down 
from C++, but that significance is probably unique to my use case 
-- the particular project I am working with happens to use a lot 
of non-memory, non-copyable (but movable) resources. In some of 
the projects I do at work, I would hardly notice this.


This [apparent] lack of clean move semantics is one of only a 
handful of things keeping me from wholeheartedly converting to D, 
and proselytizing the gospel to my coworkers (most of the other 
issues are transient, like compiler bugs). Everything else in D 
has been pretty awesome so far, and I definitely plan on 
continuing to use it for my pet projects for the time being :).


Anecdote: just after porting one of my C++ classes to D, I 
realized that without sacrificing generality, performance, or 
readability I had cut away something like 1/3 of the code, 
primarily from the cleaner syntax (this actually increased 
readability). I know D isn't _just_ "cleaner C++", but it sure is 
cleaner than C++!


Re: reduce -> fold?

2016-02-03 Thread H. S. Teoh via Digitalmars-d
On Wed, Feb 03, 2016 at 10:30:45PM +, John Colvin via Digitalmars-d wrote:
> On Wednesday, 3 February 2016 at 21:45:04 UTC, Timon Gehr wrote:
> >On 02/03/2016 09:12 PM, Atila Neves wrote:
> >>
> >>https://github.com/D-Programming-Language/phobos/pull/3968
> >>
> >>I think fold should be nothrow, but maybe that's just me. It's also
> >>a massive pain to make it that way, so I didn't for now.
> >
> >Returning Unqual!(ElementType!R).init makes no sense though.  The
> >"correct" result of fold!f([]) is a (often, the) value 'a' such that
> >for any 'b', 'f(a,b)==b' (which is the canonical choice of "seed"),
> >but there is no way for fold to infer such a value.
> 
> I wish we had some standardised way to express what the identities
> (and maybe inverses) are for a given type under given operations.

I've been wishing for something like this for a long time, though I
haven't come upon a nice way to implement it just yet.  It would present
awesome optimization opportunities to the compiler, if it could be done,
though.  Imagine if you can tell the compiler that a custom numeric type
(say BigInt, or, for that matter, Complex) satisfies certain identities.
That would lift a lot of the case-specific code in the optimizer into
library land, thus simplifying the compiler while affording even more
powerful, high-level optimizations defined by the user.

IMO, compilers of the future will have such capabilities, simply because
one day we will eventually reach the point where certain optimizations
just aren't possible without the user prodding the compiler in the right
direction. Manually writing out optimized code will eventually be a
thing of the past, since it's hard to ensure code correctness, and
nobody wants to optimize the same computations 100 times, every time
they implement something that requires that sequence of operations. The
programmer *should* be able to express the idea of "hey compiler, my
custom type T obeys identities x, y, z; now you go figure out how to
apply x, y, z to produce the most optimized code you can".


T

-- 
Long, long ago, the ancient Chinese invented a device that lets them see 
through walls. It was called the "window".


Re: Counting time difference.

2016-02-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 03, 2016 22:27:07 holo via Digitalmars-d-learn wrote:
> When i start same program on server in different timezone
> difference is much higher (more than hour). Why it is happening?
> Timezones shouldnt have influence on such equation.

You're probably getting problems due to the fact that LocalTime does not put
the timezone on the end of the ISO extended string like it should. Per the
standard, an ISO Extended string without the timezone on the end is
considered to be local time, so reading such strings in as local time is
what fromISOExtString should be doing, but I made the mistake of also having
it output the string without the timezone on it for local time (which is
technically correct but error-prone). Until that gets fixed, you probably
should never use toISOExtString on a SysTime that's has LocalTime for its
TimeZone (which is the default). Either use Clock.currTime(UTC()) to get the
time in UTC, or do st.toUTC().toISOExtString() to convert the SysTime to UTC
before converting it to a string.

Now, that being said, you never actually use the wall clock time for timing
anyway. The wall clock gets skewed all the time for time adjustments, and
stuff like DST screws life up. SysTime does hold its time internally in UTC,
which reduces the problem with regards to time zones and DST, but there's
still no guarantee that what the computer considers the wall clock time is
going to be consistent. It's useful for any time you need a timestamp (and
aside from DST is probably no more than a few seconds off), but using for it
for precise timing is very error-prone.

If you want to time stuff, then you should use the system's monotonic clock,
which means using core.time.MonoTime. e.g.

auto start = MonoTime.currTime;
// do stuff
Duration diff = MonoTime.currTime - start;

The monotonic clock moves forward by a fixed number of ticks per second,
never moves backwards, and doesn't care one whit what the timezone is or how
its ticks correspond to the wall clock time. It's just counting how many
clock ticks have passed. So, it's exactly what you want to use for timing
stuff. So, try using MonoTime instead and see how well that works for you
(though it's still not likely to match the difference between the wall clock
time when you start and when you end, precisely because the wall clock time
is constantly shifting, even if it's only by a little; though if you fix the
issue with toISOExtString and local time in your code, then it should be
fairly close).

- Jonathan M Davis



Re: print function

2016-02-03 Thread ixid via Digitalmars-d-learn

On Thursday, 4 February 2016 at 00:30:03 UTC, cym13 wrote:

On Thursday, 4 February 2016 at 00:23:07 UTC, ixid wrote:
It would be nice to have a simple writeln that adds spaces 
automatically like Python's 'print' in std.stdio, perhaps 
called print.


Sounds way too redundant to me.


Normally you'd be right but printing out data is such a common 
thing, especially for beginners. It's the kind of thing that can 
make their early experience of a language a lot more positive.


writeln(a, " ", b, " ", c, " ", d);

Is very clunky. Programming languages are like cereal, you need 
sugar to get the kids hooked.


Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 17:49:39 UTC, Marc Schütz wrote:

On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote:
What is a good way to try to force it? Using enum? Then 
optionally copying the value once to avoid the "manifest 
constant" copy/paste behaviour, where applicable?


template forceCTFE(alias expr) {
alias forceCTFE = expr;
}

auto value = forceCTFE!(some_expression());


Interesting :)
Thank you!


Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Timon Gehr via Digitalmars-d-learn

On 02/03/2016 11:39 PM, Andrea Fontana wrote:

On Wednesday, 3 February 2016 at 17:49:39 UTC, Marc Schütz wrote:

On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote:

What is a good way to try to force it? Using enum? Then optionally
copying the value once to avoid the "manifest constant" copy/paste
behaviour, where applicable?


template forceCTFE(alias expr) {
alias forceCTFE = expr;
}

auto value = forceCTFE!(some_expression());


Interesting :)
Thank you!


I would use enum forceCTFE(alias expr)=expr; though. With alias it won't 
force compile-time evaluation of expressions that can be interpreted as 
symbols.


Re: Counting time difference.

2016-02-03 Thread sigod via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 22:27:07 UTC, holo wrote:
When i start same program on server in different timezone 
difference is much higher (more than hour). Why it is 
happening? Timezones shouldnt have influence on such equation.


Try using `Clock.currTime(UTC())`. And make sure all instances 
produce timezone independent timestamps.


Re: Vision for the first semester of 2016

2016-02-03 Thread Tofu Ninja via Digitalmars-d-announce
On Wednesday, 3 February 2016 at 11:22:50 UTC, Márcio Martins 
wrote:


How would you select the package version you want to use. 
Obviously it would be fine for small scripts to pick the latest 
version, but no so much for non-trivial projects.


Somewhat related: I would love to be able to install packages 
with dub "globally", and then have them automatically added to 
the compiler's search paths and working with import with rdmd 
and dmd.


I install version 0.1 of package X globally and now all my 
programs pick that up with import. If the package is a library, 
dub would (re)compile then upon installation and put the 
resulting libs in the correct places so that all my programs 
can simply link to them.
I should also be able to override the global import with a 
different version at the project level if I which to do so. 
Similar to what dub.selections.json currently does.


Having dub fully integrated with the compiler and it's 
configuration would be a major quality of life improvement, and 
a nice step towards the "it just works" state. Much like C/C++ 
libraries get installed by Linux's package managers and just 
work, but for D.


Right now the easiest way to boot up a new project is to copy 
one that already exists, rename it, and edit the dub.json file 
to add/remove any dependencies. This gets old really quickly 
and is the only reason why D doesn't really feel like a 
scripting language for small projects, because setting up the 
environment and frequently used dependencies takes longer than 
writing the script, and you need a project directory instead of 
a single .d file that just uses all your common imports.


There are a few problems with it. For instance dub packages have 
no information about the files in them, you can't ask dub for 
derelict.opengl3.gl3.d, you ask it for the package derelict-gl3. 
So for something like this to work, there would need to be some 
type of syntax to import the package.


Probably something simple could be done like pragma(dub, 
"derelict-gl3", "==1.0.12");. As far as I can tell a dub pragma 
could be 100% ignored by the compiler unless a flag gets passed 
to print the dub dependencies. Then a tool like rdmd that gets 
all the imports for a file could also get all the dub 
dependencies and call out to dub to download them and pass the 
import paths for the dub dependencies to the final invocation of 
dmd. Otherwise the dub pragma would really do nothing other than 
be a signifier to outside tools. Tools like dcd could even use 
the pragmas to automatically call out to dub to find the paths of 
the dependencies and start indexing them for auto completion.


Really would be a great day to have that all automatically work. 
Also dub could be packaged with dmd and make all this more simple.


Right now the easiest way to use dub is to make a .json for your 
own project and build with dub, but honestly that sucks a lot 
because really the only thing people want to use dub for is the 
dependencies, the rest of it kinda gets in the way and is 
annoying as hell to use. Like trying to figure out how to build 
projects for x64 or unittests or whatever with dub is a pain. Its 
not really what people want to use dub for, but it tries to pass 
itself off as a build system which it sucks at.





Re: inner functions calling each other - how to do this with inner struct?

2016-02-03 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 15:09:35 UTC, Adam D. Ruppe 
wrote:

Read my post here:

http://stackoverflow.com/questions/34398408/struct-declaration-order/34398642#34398642

then see if you can use the same reasoning on your problem.


This indeed works without any other tricks such as compile-time 
parameters:


-
import std.stdio;

void outerFun () {
struct Holder {
static struct S {
void fun2 (int x) {
writeln (x);
if (x > 0) fun1 (x - 1);
}
}

static S s;

static void fun1 (int y) {
writeln (y);
if (y > 1) s.fun2 (y - 2);
}
}

Holder.fun1 (10);
}

void main () {outerFun ();}
-

Thank you!

Ivan Kazmenko.



Re: How do you get a hexstring from a base10 string -or- from a number?

2016-02-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 03, 2016 at 11:45:15PM +, Enjoys Math via Digitalmars-d-learn 
wrote:
> On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:
> >I am making a method called:
> >
> >@property string debugIDString() {
> >in {
> >  assert(super.toHash() == this.toHash());
> >} body {
> >
> >}
> 
> body { // is currently:
>   return to!string(this.toHash());
> }
> 
> and is returning a base10 string, so how would I return a hex string so I
> can compare numbers displayed to the debugger addresses in visual D?

@property string debugIDString() {
import std.format;
return format("%x", this.toHash());
}


T

-- 
Study gravitation, it's a field with a lot of potential.


Re: How do you get a hexstring from a base10 string -or- from a number?

2016-02-03 Thread anonymous via Digitalmars-d-learn

On 04.02.2016 00:45, Enjoys Math wrote:

On Wednesday, 3 February 2016 at 23:43:45 UTC, Enjoys Math wrote:
body { // is currently:
   return to!string(this.toHash());
}

and is returning a base10 string, so how would I return a hex string so
I can compare numbers displayed to the debugger addresses in visual D?


to!string has an optional radix (aka base) parameter:

  return to!string(this.toHash(), 16);


Re: print function

2016-02-03 Thread cym13 via Digitalmars-d-learn

On Thursday, 4 February 2016 at 00:23:07 UTC, ixid wrote:
It would be nice to have a simple writeln that adds spaces 
automatically like Python's 'print' in std.stdio, perhaps 
called print.


Sounds way too redundant to me.


Re: Vision for the first semester of 2016

2016-02-03 Thread Tofu Ninja via Digitalmars-d-announce

On Wednesday, 3 February 2016 at 23:35:21 UTC, Tofu Ninja wrote:

...


Actually now that I think about it, you can do with out the 
pragma and just define something like this...


mixin template DubDependency(string dependency, string vers)
{
// Does nothing but print a dependency
version(Dub_Dependency){
		pragma(msg, "DubDependency: \"" ~ dependency ~ "\" \"" ~ vers ~ 
"\"");

}
}


Then whenever you need it you just put:
mixin DubDependency!("derelict-gl3", "==1.0.12");

And to get the dependencies for a file you can just do
dmd test.d -o- -version=Dub_Dependency


[Issue 15644] Change object layout ABI to MI style

2016-02-03 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15644

--- Comment #1 from Walter Bright  ---
https://github.com/D-Programming-Language/dmd/pull/5397

--


Re: Vision for the first semester of 2016

2016-02-03 Thread Matt Elkins via Digitalmars-d-announce

On Thursday, 28 January 2016 at 11:25:08 UTC, Laeeth Isharc wrote:
In theory it's completely irrelevant as to whether is something 
is in the standard library or can just be imported via dub or a 
git clone, but in practice that's not the case.


In support of this statement in particular I'd like to point out 
that there are many environments which, for various reasons of 
security and policy, often require that any 3rd-party libraries 
not included as a language's standard be explicitly vetted by 
teams of very slow-moving people who seem to actively enjoy 
paperwork. In practice this means that non-standard libraries 
simply don't get used in those environments. That said, if a 
library gets popular enough (Boost, parts of Apache), they might 
manage to get pre-vetted and still used in these situations.


I'm not really offering a good solution to the debate, I just 
wanted to make a note of this.


[Issue 15644] New: Change object layout ABI to MI style

2016-02-03 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15644

  Issue ID: 15644
   Summary: Change object layout ABI to MI style
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: bugzi...@digitalmars.com

The current runtime object layout does:

   base class
   fields
   interfaces

Change it to:

   base classes (note plural)
   fields

Since we have to support the latter anyway in order to interface with C++, this
simplifies the logic compiler.

--


Idempotent partition around median of 5?

2016-02-03 Thread Andrei Alexandrescu via Digitalmars-d
This appears a simple problem: given numbers a, b, c, d, e, swap them 
around so as to place the median in c and partition the others around 
it. I.e. the postcondition is: a <= c && b <= c && c <= d && c <= e.


Searching the Net for this isn't easy. Fortunately "our own" Xinok has 
the best of breed result, see 
http://stackoverflow.com/questions/11065963/possible-to-partition-five-elements-by-median-with-six-comparisons.


His algorithm is a little suboptimal in that when given a sorted array, 
it sometimes leaves it unsorted. So I changed it to 
http://dpaste.dzfl.pl/5fb2238d9891 to fix that. If I count right, it 
also saves one swap: does 0-9 swaps instead of 0-10.


Ideally however, such an algorithm would do 0 swaps if the median is 
already in c. My algorithm may still swap d and e without necessity.


So there's got to be a better solution. Your challenge - should you 
choose to accept it :o) - is an algorithm that does the partitioning in 
6 comparisons and <= 9 swaps, which is idempotent: when applied twice, 
it always does 0 swaps.



Andrei



[Issue 15644] Change object layout ABI to MI style

2016-02-03 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15644

--- Comment #2 from Walter Bright  ---
Spec change:

  https://github.com/D-Programming-Language/dlang.org/pull/1225

--


[Issue 15644] Change object layout ABI to MI style

2016-02-03 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15644

Walter Bright  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=15618

--


Re: Get the return type of the function

2016-02-03 Thread xtreak via Digitalmars-d-learn

On Wednesday, 3 February 2016 at 19:21:06 UTC, Meta wrote:

On Wednesday, 3 February 2016 at 18:40:27 UTC, xtreak wrote:
Thanks. I was trying to get the return type of lambdas. I was 
trying the following and got an error. I was using dpaste with 
dmd 2.070


writeln(ReturnType!(a =(a *a)))

Error: template instance f662.main.ReturnType!((a) => a * a) 
does not match template declaration ReturnType(func...) if 
(func.length == 1 && isCallable!func)


Ah, I see. I'd like to test something; can you please change 
`(a) => a * a` to

`(int a) => a * a` and post the results?


Thanks for the reply. But the issue was about knowing the type of 
lambda in map. Most people won't enter the type of argument in a 
map. Is there a way to detect the return type will be non void. 
The return type is not much necessary here I just need to verify 
the function is not void.


Re: Vision for the first semester of 2016

2016-02-03 Thread Chris Wright via Digitalmars-d-announce
On Thu, 04 Feb 2016 01:23:14 +, Tofu Ninja wrote:

> Actually, nvm, wouldn't actually work because as soon as you add an
> import derelict.opengl3.gl3; it would error out because it cant find the
> file and it wouldn't print the dependencies.

You could do it with libdparse, since it doesn't do semantic analysis.


Re: Idempotent partition around median of 5?

2016-02-03 Thread Xinok via Digitalmars-d

On Thursday, 4 February 2016 at 01:33:54 UTC, Era Scarecrow wrote:
On Thursday, 4 February 2016 at 01:24:15 UTC, Andrei 
Alexandrescu wrote:
This appears a simple problem: given numbers a, b, c, d, e, 
swap them around so as to place the median in c and partition 
the others around it. I.e. the postcondition is: a <= c && b 
<= c && c <= d && c <= e.




So there's got to be a better solution. Your challenge - 
should you choose to accept it :o) - is an algorithm that does 
the partitioning in 6 comparisons and <= 9 swaps, which is 
idempotent: when applied twice, it always does 0 swaps.


 Well if we look at it, the max compares for optimal sorting 
algorithm is the log2 of the max combinations in how the 
elements could be arranged; !5 = 120 or 7 compares.


The order of a,b and d,e don't matter because we're partitioning, 
not sorting. So this problem can be solved in six comparisons.


 I'm not sure of the max swaps, seems like it could be 4 if 
done right, but that might be impractical.


I believe that's correct. Each swap can move at least one element 
into it's final position. After three swaps, there may be two 
elements which are still out of place, and swapping them will 
move them both into their final position. Thus, four swaps max. 
:-)



A solution to this problem does exist: Build a tree of if-else 
branches for all the different possibilities (2^6=64) and 
hard-code the optimal sequence of swaps. However, this function 
would be huge so this isn't very practical. Ideally, we want to 
minimize the size of the function as much as possible, adding in 
a few extra swaps if necessary.


I'll take a crack at it this weekend. It sounds like an 
interesting problem.


Re: [dlang.org] new forum design

2016-02-03 Thread Bubbasaur via Digitalmars-d

On Wednesday, 3 February 2016 at 16:59:13 UTC, ZombineDev wrote:

And which version of Chrome are you using and on what OS?


I think it's something with my OS (Windows), because in Firefox 
it isn't working too. And about the Chrome version it's the 
latest.


On android/KitKat 4.4 I can see the icons.

Bubba.


Re: Vision for the first semester of 2016

2016-02-03 Thread Tofu Ninja via Digitalmars-d-announce

On Thursday, 4 February 2016 at 00:50:43 UTC, Tofu Ninja wrote:

On Wednesday, 3 February 2016 at 23:35:21 UTC, Tofu Ninja wrote:

...


Actually now that I think about it, you can do with out the 
pragma and just define something like this...


mixin template DubDependency(string dependency, string vers)
{
// Does nothing but print a dependency
version(Dub_Dependency){
		pragma(msg, "DubDependency: \"" ~ dependency ~ "\" \"" ~ vers 
~ "\"");

}
}


Then whenever you need it you just put:
mixin DubDependency!("derelict-gl3", "==1.0.12");

And to get the dependencies for a file you can just do
dmd test.d -o- -version=Dub_Dependency


Actually, nvm, wouldn't actually work because as soon as you add 
an import derelict.opengl3.gl3; it would error out because it 
cant find the file and it wouldn't print the dependencies.


Re: Get the return type of the function

2016-02-03 Thread xtreak via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 23:57:12 UTC, Ivan Kazmenko 
wrote:

On Wednesday, 3 February 2016 at 22:09:37 UTC, sigod wrote:

On Wednesday, 3 February 2016 at 19:21:06 UTC, Meta wrote:
Ah, I see. I'd like to test something; can you please change 
`(a) => a * a` to

`(int a) => a * a` and post the results?


This works.

http://dpaste.dzfl.pl/92c254ef6cf6


Seems reasonable: `(int a) => a * a` has return type `int` but 
just `(a) => a * a` does not yet know the type of `a`, and so 
can not tell the return type.


Thanks for the reply. But the issue was about knowing the type of 
lambda in map. Most people won't enter the type of argument in a 
map. Is there a way to detect the return type will be non void. I 
don't need to know the type I just wanr to verify its not void. 
Yes * can be overloaded and can have different types based on the 
input having the overloaded operator implemented. I just want to 
check if the return type is not void.


Re: D's equivalent to C++'s std::move?

2016-02-03 Thread Andrei Alexandrescu via Digitalmars-d

On 02/03/2016 09:01 PM, Matt Elkins wrote:


[code]
import std.algorithm;

struct ResourceHandle(T, alias Deleter, T Default = T.init)
{
 // Constructors/Destructor
 this(T handle) {m_handle = handle;}
 @disable this(this);
 ~this() {Deleter(m_handle);}

 // Operators
 @disable void opAssign(ref ResourceHandle lvalue);
 ref ResourceHandle opAssign(ResourceHandle rvalue) {swap(m_handle,
rvalue.m_handle); return this;}

 // Methods
 @property inout(T) handle() inout {return m_handle;}
 @property T handle(T handle) {Deleter(m_handle); m_handle = handle;
return m_handle;}
 T release() {T result = m_handle; m_handle = Default; return result;}

 private:
 T m_handle = Default;
}
[/code]

This seems to cover most of my bases, but I still can't do things like
this:

[code]
unittest
{
 alias RH = ResourceHandle!(uint, (uint) {});
 RH[] handles;
 handles ~= RH(5); // Compile error: ResourceHandle is not copyable
because it is annotated with @disable
}
[/code]


Got it, thanks. That's a bug in the implementation, no two ways about 
it. No copy should occur there, neither theoretically nor practically. 
Please report it to bugzilla at http://issues.dlang.org. Thanks very 
much! -- Andrei




  1   2   >