Re: Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-08 Thread kdevel via Digitalmars-d

On Sunday, 8 April 2018 at 13:00:02 UTC, bauss wrote:

[...]


// a.d
module a;

class Foo
{
private:
bool _baz;

public:
void handleBar(T : Foo)(T[] foos)
{
foreach (child; foos)
{
child._baz = true; // Not ok.


replace this line with

   import std.stdio;
   __PRETTY_FUNCTION__.writeln;
   foos.writeln;

This writelns:

   void a.Foo.handleBar!(Bar).handleBar(Bar[] foos)
   [b.Bar, b.Bar]

So foos is actually an array of Bars. And there is no access from 
a Bar to the private elements of it's baseclass Foo.


What I am wondering about is why does the method template match 
in the first place?



(cast(Foo)child)._baz = true; // Ok.


You also may use the ternary conditional operator for that (SCNR).



Re: that is bug?

2018-04-08 Thread kdevel via Digitalmars-d

On Sunday, 8 April 2018 at 07:22:19 UTC, Patrick Schluter wrote:

You may find an in-depth discussion of the C++ case in

https://stackoverflow.com/questions/7499400/ternary-conditional-and-assignment-operator-precedence


My formulation was ambiguous, it is the same precedence as the 
link says. The link also says that's it's right to left 
evaluation. This means that for expression:


a ? b = c : d = e;


right to left evaluation will make the = e assignment higher 
priority than the b = c assignment or the ternary even if they 
have the same priority level.


To summarize: C++ works as expected and C prevents the assigment 
because the conditional operator does not yield an l-value:


ccondo1.c
---
int main ()
{
   int a, b;
   1 ? a = 1 : b = 2;
   return 0;
}
---

$ cc ccondo1.c
ccondo1.c: In function 'main':
ccondo1.c:4: error: lvalue required as left operand of assignment

Other languages:


- go: has no ternary conditional

- Java: Same as in C, example does not compile due to missing 
l-value.


- JS: Like C++ (!).

  
https://www.ecma-international.org/ecma-262/6.0/#sec-conditional-operator


"The grammar for a ConditionalExpression in ECMAScript is 
slightly different from that in C and Java, which each allow the 
second subexpression to be an Expression but restrict the third 
expression to be a ConditionalExpression. The motivation for this 
difference in ECMAScript is to allow an assignment expression to 
be governed by either arm of a conditional and to eliminate the 
confusing and fairly useless case of a comma expression as the 
centre expression."




Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 19:44:35 UTC, Ali wrote:

so it seems
that since
b = (true ? stt="AA": stt )="BB";
and
b = true ? stt="AA": stt ="BB";

are equivalent
that

that the ternary operator return stt (after assigning it "AA") 
then assign "BB" to it


Can the ternary conditional even be used to assign objects of the 
wrong type?


dcondo.d
---
import std.stdio;

class A {
   int a;
   this (int i)
   {
  a = i;
   }
}

class C {
   int c;
   this (int i)
   {
  c = i;
   }
}

void dump (A a, A b, C c, C d)
{
   a.writeln;
   b.writeln;
   c.writeln;
   d.writeln;
   a.a.writeln;
   b.a.writeln;
   c.c.writeln;
   d.c.writeln;
}

void main ()
{
   A a = new A (1), b = new A (2);
   C c = new C (3), d = new C (4);
   dump (a, b, c, d);
   true ? a = b : c = d;
//   a = c; // Error: cannot implicitly convert expression
//   c = a; // Error: cannot implicitly convert expression
   dump (a, b, c, d);
}
---

Output:

dcondo.A
dcondo.A
dcondo.C
dcondo.C
1
2
3
4
dcondo.C
dcondo.A
dcondo.C
dcondo.C
4
2
3
4



Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 16:52:00 UTC, Patrick Schluter wrote:
[...]
The odd man out is C++ [1], assignment has higher precedence 
because of right to left evaluation.


Your reference [1] is not even a witness to your claim. The 
precedence table says that the "Ternary conditional" has the 
*same* precedence as the "Direct Assigment", namely "16".


You may find an in-depth discussion of the C++ case in

https://stackoverflow.com/questions/7499400/ternary-conditional-and-assignment-operator-precedence


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 14:43:53 UTC, Jonathan M Davis wrote:
On Saturday, April 07, 2018 14:29:15 kdevel via Digitalmars-d 
wrote:

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:
> On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:
>> true?stt="AA":stt="BB";<<<<-///Out:BB
>
> It's an UB.
>
> Not a bug.

Why UB? stt is only modified once.


It's modified twice.


So we have diffrent behavior of D wrt to C.

[...] which would imply (though not guarantee) that the D 
behavior is a bug.


After rereading

https://dlang.org/spec/expression.html#conditional_expressions

carefully I found that Unlike § 6.1.5 of the C standard the 
"only" is missing in the D docs.




Re: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, [your code here]

2018-04-07 Thread kdevel via Digitalmars-d

On Friday, 6 April 2018 at 14:03:18 UTC, Abdulhaq wrote:

On Friday, 6 April 2018 at 13:10:07 UTC, jason wrote:

what is this?


It's a perl program that converts D code into APL


+1


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:


true?stt="AA":stt="BB";-///Out:BB


It's an UB.

Not a bug.


Why UB? stt is only modified once.


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis wrote:

 true?stt="AA":stt="BB";-///Out:BB


[...]


Assignment takes precendence over the ternary operator.


That's not true. Not in D and not in C/C++
https://wiki.dlang.org/Operator_precedence
http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2

So, no, I don't think that it is. Putting parens around the 
assignment expressions makes it print AA.


It should not matter if there are parens around the assignment.

As it stands, it evaluates both assignment expressions before 
evaluating the ternary operator.


That is not true in C/C++, let me quote from a C standard 
(draft), § 6.1.5 conditional operator:


[this is about  ?  : ]

"Semantics

The first operand is evaluated; there is a sequence point between 
its evaluation and the evaluation of the second or third operand 
(whichever is evaluated). The second operand is evaluated only if 
the first compares unequal to 0; the third operand is evaluated 
only if the first compares equal to 0; the result is the value of 
the second or third operand (whichever is evaluated), converted 
to the type described below.110)"


According to

https://dlang.org/spec/expression.html#conditional_expressions

the same shall be valid for D. Hence when

   true ? s = A : s = B;

or

   true ? (s = A) : (s = B);

does not yield A for s it's a bug.


Re: Postgres and other database interfaces

2018-02-25 Thread kdevel via Digitalmars-d

On Sunday, 25 February 2018 at 11:46:26 UTC, Denis F wrote:
But it is impossible to convert text :names or '?' into 
Postgres's "$1": Postgres isn't knows fields names at start of 
a query processing and you can't replace '?' to "$" by 
simple 'replace' call - it will need full syntax parsing of 
Posgres SQL query because queries can contain EXECUTE statement 
(whose purpose is executing dynamic commands).


You don't have to parse the full syntax. Quote from another 
language (which also supports underscore in integer literals):


'Placeholders

There are three types of placeholders that can be used in 
DBD::Pg. The first is the "question mark" type, in which each 
placeholder is represented by a single question mark character. 
This is the method recommended by the DBI specs and is the most 
portable. Each question mark is internally replaced by a "dollar 
sign number" in the order in which they appear in the query 
(important when using "bind_param").


The second type of placeholder is "dollar sign numbers". This is 
the method that Postgres uses internally and is overall probably 
the best method to use if you do not need compatibility with 
other database systems. DBD::Pg, like PostgreSQL, allows the same 
number to be used more than once in the query. Numbers must start 
with "1" and increment by one value (but can appear in any order 
within the query). If the same number appears more than once in a 
query, it is treated as a single parameter and all instances are 
replaced at once. [...]


The final placeholder type is "named parameters" in the format 
":foo". While this syntax is supported by DBD::Pg, its use is 
discouraged in favor of dollar-sign numbers.


The different types of placeholders cannot be mixed within a 
statement, but you may use different ones for each statement 
handle you have. This is confusing at best, so stick to one style 
within your program.


If your queries use operators that contain question marks (e.g. 
some of the native Postgres geometric operators and JSON 
operators) or array slices (e.g. data[100:300]), there are 
methods to instruct DBD::Pg to not treat some symbols as 
placeholders. First, you may simply add a backslash before the 
start of a placeholder, and DBD::Pg will strip the backslash and 
not treat the character as a placeholder.


You can also tell DBD::Pg to ignore any non-dollar sign 
placeholders by setting the pg_placeholder_dollaronly attribute 
at either the database handle or the statement handle level. 
[...] ' [1]


[1] 
http://search.cpan.org/~turnstep/DBD-Pg-3.7.4/Pg.pm#Placeholders




Re: Slow code, slow

2018-02-23 Thread kdevel via Digitalmars-d

On Friday, 23 February 2018 at 20:15:12 UTC, H. S. Teoh wrote:

Now that I got your attention:

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


Your bug report is about slowdown in *compilation* time. I 
wondered if the longer compilation time is due to the better 
(faster) generated code. But this is not the case either:


$ ./dotbench
initialized arrays of type double
dot_fast: 279 ms
value = 0
dot_slow: 5413 ms
value = 0
dotProduct: 217 ms
value = 0





Re: SPF record for forum.dlang.org

2018-02-21 Thread kdevel via Digitalmars-d

Vladimir!

On Wednesday, 21 February 2018 at 23:21:05 UTC, Vladimir 
Panteleev wrote:

On Wednesday, 21 February 2018 at 21:57:59 UTC, kdevel wrote:
I would greatly appreciate if the zone admin of dlang.org adds 
an SPF record

also to forum.dlang.org.


Hi,

SPF/DKIM/DMARC are good ideas in general (currently 
*.forum.dlang.org is CNAME'd to a single domain, so that would 
need to change first). But, do I understand correctly that the 
email you received was unexpected?


Sure. And I also got a notification email of your reply:

Return-Path: 
Received: from k3.1azy.net (k3.1azy.net [178.33.224.37])
From: D Programming Language Forum 
Subject: Vladimir Panteleev replied to your post in the thread 
"SPF record for forum.dlang.org"


Is this host ligitimately sending out these notifications?

[...]


and you enabled the subscription on 2017-10-14.


I stand corrected. Found the config in the settings area.

Is it possible that you've simply forgotten that you've done 
this?


Well, yes. Because I have not yet gotten any of these 
notification until today.

I got no notification e.g. of this post

https://forum.dlang.org/thread/mutegviphsjwqzqfo...@forum.dlang.org?page=2#post-fgfsezyxdzszmwniuizc:40forum.dlang.org

of 2018-01-11.

In any case, if you no longer wish to receive emails, every 
email includes an unsubscribe link.


Hope this helps.


Yes, partly.

Stefan


SPF record for forum.dlang.org

2018-02-21 Thread kdevel via Digitalmars-d
Today I received a notification *e-mail* after somebody has 
replied to a post:


https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-sksbiiwnfsxocklwcfsd:40forum.dlang.org

I would greatly appreciate if the zone admin of dlang.org adds an 
SPF record

also to forum.dlang.org. At present there is none:

$ host -t txt forum.dlang.org
forum.dlang.org is an alias for dfeed.kimsufi.thecybershadow.net.
dfeed.kimsufi.thecybershadow.net descriptive text 
"google-site-verification=v0zp5IJgjZ-bfE4El8UEQwnHdNma3wwmU8JNvbzlVDY"


in contrast to

$ host -t txt dlang.org
dlang.org descriptive text "v=spf1 mx a ip4:205.201.128.0/20 
ip4:198.2.128.0/18 ip4:205.201.134.0/24 -all"


That would help to reject unsolicited e-mail traffic from 
k3.1azy.net (k3.1azy.net [178.33.224.37]) and possibly others.


Re: Why Physicists Still Use Fortran

2017-10-17 Thread kdevel via Digitalmars-d

On Monday, 16 October 2017 at 09:06:01 UTC, qznc wrote:

Dijkstra made a good argument for zero-based:
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html


Donald Knuth on that proposal ;-)

Edsger Dijkstra's Retirement Banquet - Part 8 of 13
https://www.youtube.com/watch?v=6gH4bWuMUEs&t=1m23s


Re: Annoying module name / typename conflict

2017-07-16 Thread kdevel via Digitalmars-d

On Monday, 2 April 2012 at 22:20:13 UTC, bearophile wrote:

For DMD choosing one or the other is arbitrary. It's a defect 
of the way the D module system is designed.


Ran into that problem with a Module S containing

   module S;
   import std.stdio;
   struct S {
  this (string s)
  {
 writeln ("S: " ~ s);
  }
   }

This code

// auto s1 = S("X"); // useS.d(6): Error: function expected 
before (), not module S of type void


would not compile while

   S s3 = "X"; // OK

works. Has this issue been filed in bugzilla?