Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Sönke Ludwig via Digitalmars-d

Am 11.09.2015 um 21:40 schrieb Martin Nowak:

I find the reasons for turining down my ER a bit moot.

[Issue 14593 – operator overloading can't be used with expression
templates](https://issues.dlang.org/show_bug.cgi?id=14593)

(...)


The missing support for overloading the individual relational operators 
is something that has often turned out very limiting to me in the past, 
too. The opCmp approach is good as a default, but explicitly disallowing 
implementation of the individual operators seems arbitrary.



Now expression templates make an awful DSL when being used to create a
HTML formatter, but when the original semantic of the operators is
preserved they are really powerful b/c the compiler already handles
typechecking, operator precedence, and captures variables.

Does anyone have a different idea how to make a nice query language?
db.get!Person.where!(p => p.age > 21 && p.name == "Peter")


I had played around with some ideas for a similar project, but didn't 
find a really satisfying solution:

https://github.com/rejectedsoftware/dotter/blob/11ec72325e76c3329a58545526940c1df5328a2d/source/dotter/orm.d#L320


Re: std.experimental.testing formal review

2015-09-13 Thread Dicebot via Digitalmars-d
On Saturday, 12 September 2015 at 14:50:32 UTC, Jacob Carlborg 
wrote:

On 2015-09-12 15:34, Dicebot wrote:

I also don't like mixing unittest and higher level functional 
tests
(with setup and cleanup phases) into the same buckets - this 
doesn't fit
nice with D module system. Latter should be placed in a 
separate
modules/package to avoid being picked up by rdmd & Co when 
compiled as

dependency.


Not sure I understand the problem. Does this prevent one from 
writing functional tests in a completely separate directory?


On related topic - there are 2 things that are currently missing 
in `TestCase` when applied for functional test purpose:


1) being able to mark test case as fatal (i.e. if internal 
handshake or sanity check fails there is no point in trying to 
run other tests)
2) being able to do weak ordering of tests (by defining strict 
sequence of groups so that parallelization/randomization only 
happens within such group) - I have used something as simple as 
numerical priority value so far for my needs


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Dicebot via Digitalmars-d
I am pretty sure I'd prefer hygienic string DSL (with explicit 
alias list for used context symbols, like in Diet) over LINQ-like 
magic.


Re: std.experimental.testing formal review

2015-09-13 Thread Atila Neves via Digitalmars-d

On Sunday, 13 September 2015 at 09:59:18 UTC, Dicebot wrote:
On Saturday, 12 September 2015 at 14:50:32 UTC, Jacob Carlborg 
wrote:

On 2015-09-12 15:34, Dicebot wrote:

I also don't like mixing unittest and higher level functional 
tests
(with setup and cleanup phases) into the same buckets - this 
doesn't fit
nice with D module system. Latter should be placed in a 
separate
modules/package to avoid being picked up by rdmd & Co when 
compiled as

dependency.


Not sure I understand the problem. Does this prevent one from 
writing functional tests in a completely separate directory?


On related topic - there are 2 things that are currently 
missing in `TestCase` when applied for functional test purpose:


1) being able to mark test case as fatal (i.e. if internal 
handshake or sanity check fails there is no point in trying to 
run other tests)


I've never heard of functionality like that, but should be easy 
to implement.


2) being able to do weak ordering of tests (by defining strict 
sequence of groups so that parallelization/randomization only 
happens within such group) - I have used something as simple as 
numerical priority value so far for my needs


There's `@singleThreaded` for that: all tests in a module with 
that UDA run in series (other modules are still run in parallel). 
I didn't think one was needed for random ordering.


Atila
Atila




Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Jack Stouffer via Digitalmars-d
On Saturday, 12 September 2015 at 22:38:53 UTC, Bahman Movaqar 
wrote:
Django's approach is, IMO,  the cleverest and least magical one 
while keeping it expressive and efficient:


Person.objects.filter(age__gt=21, name__eq='peter')


As the main examples in this thread are for ORMs, I think the 
best case for more powerful operator overloading is the very 
popular Python library SQLAlchmey. SQLAlchmey is the reason that 
any project of mine that requires a database is going to be in 
Python.


Here is a real code sample from one of my projects from my day 
job:


shipped = session.query(
func.sum(
InvoiceHistoryDetail.QuantityShipped * 
InvoiceHistoryDetail.UnitPrice

).label("sum")
).join(
InvoiceHistoryHeader,
InvoiceHistoryHeader.InvoiceNo == 
InvoiceHistoryDetail.InvoiceNo

).join(
Customer,
and_(
InvoiceHistoryHeader.ARDivisionNo == 
Customer.ARDivisionNo,

InvoiceHistoryHeader.CustomerNo == Customer.CustomerNo
)
).filter(
InvoiceHistoryHeader.ShipDate >= 
fiscal_month.PeriodStartingDate,
InvoiceHistoryHeader.ShipDate == datetime.date.today() - 
datetime.timedelta(days=1),

InvoiceHistoryHeader.SalesOrderNo != None,
Customer.UDF_PARTICIPATION.in_(participation)
).one()

Note how complex operator overloading is used to make very 
readable JOIN and WHERE clauses. One other cool thing to note is 
the func function, which is a generator function that allows 
expressing any SQL function in Python by translating the name 
after the dot to the function name is the final SQL. So 
func.whatever(model.field) would become WHATEVER(`model.field`) 
in the SQL.


I know that this effect is much harder to create in a explicitly 
and strongly typed language, but I just wanted to show a real 
world example of how these could be used to great effect.


Re: Looking for someone that could work on 32 bits support for SDC

2015-09-13 Thread BBasile via Digitalmars-d

On Sunday, 13 September 2015 at 05:53:27 UTC, deadalnix wrote:

On Sunday, 13 September 2015 at 02:19:27 UTC, BBasile wrote:
On Wednesday, 9 September 2015 at 20:33:43 UTC, deadalnix 
wrote:

All is in the title.

ARM/Mips/pNaCl/WebAssembly require 32bits to work. These are 
valuable targets IMO.


I can provide support, but I just don't have the bandwidth to 
pull it by myself. If someone could step up, that'd be great.


Do you think that libd is 32bit ready ?

https://github.com/SDC-Developers/SDC/pull/141


Building on 32 bits and generating 32 bit code are 2 different 
things.


No I don't think libd can compile on a 32 bits system ATM, but 
I do not expect it to be that far away from being able to do so.


That's a pitty. libd itself could be usefull to program some 
tools for the language. I particularly think to IDE stuff like 
symbol list, module name finder, etc. So far in Coedit I use 
libdparse but if libd would be available for the 32 bit 
plateforms I won't be against using it.


D, finance, London,…

2015-09-13 Thread Russel Winder via Digitalmars-d
An acquaintance of mine is trying to find someone to speak on the use
of D in finance and/or investment banking. Conference is early November
in London. Is anyone interested in investigating this further? If so,
please email me offlist.

(I had a couple of people in mind to ask, but I cannot find their
private email addresses. This may be lack of good research on my part,
but hence this rather wide email.)
-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



signature.asc
Description: This is a digitally signed message part


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 11:00 AM, Sönke Ludwig wrote:
> I had played around with some ideas for a similar project, but didn't
> find a really satisfying solution:
> https://github.com/rejectedsoftware/dotter/blob/11ec72325e76c3329a58545526940c1df5328a2d/source/dotter/orm.d#L320

Yeah, that doesn't look too nice.

I think db.get!Author.where!(a => a.books.count > 10) is very powerful
b/c you can easily use relations for querying.

struct Author
{
  @hasMany // relation in SQL or nested in MongoDB
  Book[] books;
}


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 05:03 AM, Andrei Alexandrescu wrote:
> Yah, understood. Problem here is the approach is bound to run into walls
> at every few steps. Say you fix the comparisons to work. Then you have
> operators such as LIKE that are necessary yet not representable in D. So
> more tricks are in order. This is what I've seen with ET in C++ - an
> endless collection of tricks to achieve modest outcomes at enormous costs.

But this is not an argument to rule out `opBinary!"<"`.

To summarize the arguments.

- logical indexing x[x < 20]

  e.g. opBinary!"<" returns a bit mask to select entries of a large vector

- faster comparison

  struct Foo
  {
  size_t id;
  int opCmp(Foo rhs)
  {
  if (id < rhs.id) return -1;
  if (id == rhs.id) return 0;
  else return 1;
  }
  bool opBinary(string s:"<")(Foo rhs)
  {
  return id < rhs.id;
  }
  }

  Sorting a million Foos w/ random ids is 37.5% slower with opCmp.

  foos.sort!((a, b) => a.opBinary!"<"(b))(); // 104ms
  foos.sort!((a, b) => a < b)(); // 143ms

- expression templates

  I'm well aware of the limitations, but still think it will work out
nicely for an ORM b/c there is precedence in other language, e.g. Rails'
(ActiveRecord) query syntax.

- language regularization

  It's surprising to find these "arbitrary" language limitations.
  The non-predictability of what's possible has always been a huge issue
for me with C++, i.e. you come up with an idea, spend 4 hours
implementing it only to find out that the small detail x isn't feasible.


Re: std.experimental.testing formal review

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/11/2015 01:27 PM, Atila Neves wrote:
>> How about Fuzz-tests, randomize input for test on each run?
> 
> Like QuickCheck? Robert has something for that.

There is also https://github.com/MartinNowak/qcheck for that.


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 03:15 PM, Jack Stouffer wrote:
> 
> I know that this effect is much harder to create in a explicitly and
> strongly typed language, but I just wanted to show a real world example
> of how these could be used to great effect.

But it is doable in D, and even better it's possible to optimize the
queries b/c we can know in advance what fields are used.
http://dpaste.dzfl.pl/cd375ac594cf


Re: Type helpers instead of UFCS

2015-09-13 Thread Kagamin via Digitalmars-d

On Saturday, 12 September 2015 at 21:04:47 UTC, BBasile wrote:
You've got the idea. IDE plugins can not decently provide 
completion based on the UFCS possibilities.


It's possible, just not implemented yet.


Re: std.experimental.testing formal review

2015-09-13 Thread Jacob Carlborg via Digitalmars-d

On 2015-09-13 12:44, Atila Neves wrote:


I've never heard of functionality like that, but should be easy to
implement.


We're using that at work, but on a different level. We have two separate 
jobs in Jenkins, one depends on the other one. If the first one fails, 
the second one is not run.


--
/Jacob Carlborg


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Jack Stouffer via Digitalmars-d

On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote:

- logical indexing x[x < 20]

  e.g. opBinary!"<" returns a bit mask to select entries of a 
large vector


Oh yes please! This is one of the more powerful features of numpy.



Re: Type helpers instead of UFCS

2015-09-13 Thread Puming via Digitalmars-d

On Sunday, 13 September 2015 at 14:37:36 UTC, Kagamin wrote:

On Saturday, 12 September 2015 at 21:04:47 UTC, BBasile wrote:
You've got the idea. IDE plugins can not decently provide 
completion based on the UFCS possibilities.


It's possible, just not implemented yet.


Mono-d seems to have experimental UFCS support


Re: Interesting user mistake

2015-09-13 Thread Marco Leise via Digitalmars-d
Am Fri, 04 Sep 2015 13:38:26 +
schrieb "Jonathan M Davis" :

> I didn't realize that a unary + operator existed. I would have 
> assumed that +a as an expression would be illegal. It doesn't 
> even mean anything.
> 
> - Jonathan M Davis

Often (mostly with linear algebra) you have e.g. a sum of 4
products that differ only in some index and the sign. I use to
put superfluous + signs there and put each product on a
separate line just to make the similarities stick out more.

Sure they do nothing, but I'd miss them when there is ++/--/-
as prefix operators but no +.

About the proposal I'm undecided. Rare mistake, stuffing more
fuzzy logic into the compiler front-end where I don't know
how maintainable this is on the long run and how much in fact
they start to annoy as they target mistakes that newcomers
make, but may actually be legit. For example assuming you
learned the operator precedence rules, warnings about adding
parenthesis where the code was already correct can be annoying.
"=+ " goes in the same direction.
We could end up with DMD and SDC implementing a different set
of somewhat fuzzy, well meant restrictions on what is correct
code, that most of the time avoid errors and sometimes annoy.
A compiler front-end is complex and such language patches may
actually make the code less readable by adding snippets of
code all over the front-end code bases.
I like the "did you mean ..." messages though as the last step
of symbol resolution. They happen when the code already
doesn't compile and as such don't alter what is valid code and
they have good visibility.

So my opinion is to collect such snippets in a proper linter
like https://github.com/Hackerpilot/Dscanner instead of
burdening the front-end with them and creating a de-facto
new DMD specific spec different from other emerging D
implementations.

-- 
Marco



Re: Interesting user mistake

2015-09-13 Thread Marco Leise via Digitalmars-d
Am Fri, 4 Sep 2015 19:13:45 -0400
schrieb Andrei Alexandrescu :

> Most likely. My question was whether to put it in bugzilla or not. Guess 
> not.
> 
> 
> Andrei

Put it here: https://github.com/Hackerpilot/Dscanner/issues ;)

-- 
Marco



Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Daniel N via Digitalmars-d

On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote:

  struct Foo
  {
  size_t id;
  int opCmp(Foo rhs)
  {
  if (id < rhs.id) return -1;
  if (id == rhs.id) return 0;
  else return 1;
  }
  bool opBinary(string s:"<")(Foo rhs)
  {
  return id < rhs.id;
  }
  }

  Sorting a million Foos w/ random ids is 37.5% slower with 
opCmp.




Could you try this?

int opCmp(Foo rhs)
{
  return (id > rhs.id) - (id < rhs.id);
}



Re: Type helpers instead of UFCS

2015-09-13 Thread bitwise via Digitalmars-d

On Saturday, 12 September 2015 at 20:37:37 UTC, BBasile wrote:

UFCS is good but there are two huge problems:
- code completion in IDE. It'will never work.


By this do you mean completion will be flooded?

If so, then +1.

I would much prefer something like C# extension methods, but 
where the first argument has to be typed so that every random 
template UFC under the sun doesn't appear in completion.


class Foo {
   void foo() {}
}

void bar(this Foo foo, int arg) { }// fine
void baz(this T t) { }// compile error: first arg 
can't be a template

void boo(Foo foo)   // fine, but can't be used like a UFC

int Main(string[] args) {
Foo foo = new Foo();
foo.bar(1); // fine
foo.baz(); // error, undefined method 'baz'
boo(foo); // fine
foo.boo(); // error, undefined method 'boo'
}



Re: Type helpers instead of UFCS

2015-09-13 Thread BBasile via Digitalmars-d

On Sunday, 13 September 2015 at 17:17:18 UTC, bitwise wrote:

On Saturday, 12 September 2015 at 20:37:37 UTC, BBasile wrote:

UFCS is good but there are two huge problems:
- code completion in IDE. It'will never work.


By this do you mean completion will be flooded?

If so, then +1.

I would much prefer something like C# extension methods, but 
where the first argument has to be typed so that every random 
template UFC under the sun doesn't appear in completion.


class Foo {
   void foo() {}
}

void bar(this Foo foo, int arg) { }// fine
void baz(this T t) { }// compile error: first arg 
can't be a template

void boo(Foo foo)   // fine, but can't be used like a UFC

int Main(string[] args) {
Foo foo = new Foo();
foo.bar(1); // fine
foo.baz(); // error, undefined method 'baz'
boo(foo); // fine
foo.boo(); // error, undefined method 'boo'
}


Yes this exactly what I meant. But a few hours after starting the 
topic i'm less excited about the feature. I was biased by the 
fact that i uniquely use DCD while there is of course also 
A.Bothe completion system and the default Visual D completion 
(don't know if it's been droped since the last time i used VD but 
there was setting to use Bothe's completion system in stead of 
VD's one).


Re: dmd codegen improvements

2015-09-13 Thread BBasile via Digitalmars-d

On Tuesday, 18 August 2015 at 10:45:49 UTC, Walter Bright wrote:
Martin ran some benchmarks recently that showed that ddmd 
compiled with dmd was about 30% slower than when compiled with 
gdc/ldc. This seems to be fairly typical.


I'm interested in ways to reduce that gap.

There are 3 broad kinds of optimizations that compilers do:

1. source translations like rewriting x*2 into x<<1, and 
function inlining


2. instruction selection patterns like should one generate:

SETC AL
MOVZ EAX,AL

or:
SBB EAX
NEG EAX

3. data flow analysis optimizations like constant propagation, 
dead code elimination, register allocation, loop invariants, 
etc.


Modern compilers (including dmd) do all three.

So if you're comparing code generated by dmd/gdc/ldc, and 
notice something that dmd could do better at (1, 2 or 3), 
please let me know. Often this sort of thing is low hanging 
fruit that is fairly easily inserted into the back end.


For example, recently I improved the usage of the SETcc 
instructions.


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

A while back I improved usage of BT instructions, the way 
switch statements were implemented, and fixed integer divide by 
a constant with multiply by its reciprocal.


Maybe the ENTER instruction should be replaced by a full prologue:

- 
https://github.com/D-Programming-Language/dmd/blob/ef24f9acd99aa52ed28e7221cb0997099ab85f4a/src/backend/cod3.c#L2939
- 
http://stackoverflow.com/questions/5959890/enter-vs-push-ebp-mov-ebp-esp-sub-esp-imm-and-leave-vs-mov-esp-ebp


It seems that since the Pentium I, ENTER is always slower. But i 
don't know if it's used as a kind of optimization for the binary 
size. Actually before using DMD I had **never** seen an ENTER.


Re: dmd codegen improvements

2015-09-13 Thread ponce via Digitalmars-d

On Sunday, 13 September 2015 at 17:30:12 UTC, BBasile wrote:


It seems that since the Pentium I, ENTER is always slower. But 
i don't know if it's used as a kind of optimization for the 
binary size. Actually before using DMD I had **never** seen an 
ENTER.


Same here, I thought nobody used this one instruction.


Re: Interesting user mistake

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/03/2015 06:46 PM, Andrei Alexandrescu wrote:
> http://stackoverflow.com/questions/32369114/leap-years-not-working-in-date-and-time-program-in-dlang
> 
> 
> The gist of it is the user wrote =+ instead of +=. I wonder if we should
> disallow during tokenization the sequence "=", "+", whitespace. Surely
> it's not a formatting anyone would aim for, but instead a misspelling of
> +=.
> 
> 
> Andrei

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


Re: dmd codegen improvements

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 07:30 PM, BBasile wrote:
> It seems that since the Pentium I, ENTER is always slower. But i don't
> know if it's used as a kind of optimization for the binary size.
> Actually before using DMD I had **never** seen an ENTER.

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


Re: dmd codegen improvements

2015-09-13 Thread BBasile via Digitalmars-d

On Sunday, 13 September 2015 at 18:33:52 UTC, Martin Nowak wrote:

On 09/13/2015 07:30 PM, BBasile wrote:
It seems that since the Pentium I, ENTER is always slower. But 
i don't know if it's used as a kind of optimization for the 
binary size. Actually before using DMD I had **never** seen an 
ENTER.


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


Yeah, that was fast. With the hope it'll be approved.


Re: dmd codegen improvements

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 08:45 PM, BBasile wrote:
> Yeah, that was fast. With the hope it'll be approved.

If only it wasn't for me to do this...


Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 07:16 PM, Daniel N wrote:
> 
> Could you try this?
> 
> int opCmp(Foo rhs)
> {
>   return (id > rhs.id) - (id < rhs.id);
> }

That's not the point, opCmp requires twice as many comparisons as needed
for <. If they are more expansive, e.g. string comparison, your trick
won't work.


Re: Type helpers instead of UFCS

2015-09-13 Thread bitwise via Digitalmars-d

On Sunday, 13 September 2015 at 17:23:25 UTC, BBasile wrote:

On Sunday, 13 September 2015 at 17:17:18 UTC, bitwise wrote:

On Saturday, 12 September 2015 at 20:37:37 UTC, BBasile wrote:

[...]


By this do you mean completion will be flooded?

If so, then +1.

I would much prefer something like C# extension methods, but 
where the first argument has to be typed so that every random 
template UFC under the sun doesn't appear in completion.


class Foo {
   void foo() {}
}

void bar(this Foo foo, int arg) { }// fine
void baz(this T t) { }// compile error: first arg 
can't be a template

void boo(Foo foo)   // fine, but can't be used like a UFC

int Main(string[] args) {
Foo foo = new Foo();
foo.bar(1); // fine
foo.baz(); // error, undefined method 'baz'
boo(foo); // fine
foo.boo(); // error, undefined method 'boo'
}


Yes this exactly what I meant. But a few hours after starting 
the topic i'm less excited about the feature. I was biased by 
the fact that i uniquely use DCD while there is of course also 
A.Bothe completion system and the default Visual D completion 
(don't know if it's been droped since the last time i used VD 
but there was setting to use Bothe's completion system in stead 
of VD's one).


Yea, I think this is one of those things that's just way to 
engrained in D to be changed.


T* obj = cast(T*)malloc(sz);
emplace(obj);
obj.destroy();  // < this

If things like this stopped working, I doubt if there's a D 
codebase in existence that wouldn't break =/


   Bit




Re: Looking for someone that could work on 32 bits support for SDC

2015-09-13 Thread deadalnix via Digitalmars-d

On Sunday, 13 September 2015 at 13:26:05 UTC, BBasile wrote:

On Sunday, 13 September 2015 at 05:53:27 UTC, deadalnix wrote:

On Sunday, 13 September 2015 at 02:19:27 UTC, BBasile wrote:
On Wednesday, 9 September 2015 at 20:33:43 UTC, deadalnix 
wrote:

All is in the title.

ARM/Mips/pNaCl/WebAssembly require 32bits to work. These are 
valuable targets IMO.


I can provide support, but I just don't have the bandwidth 
to pull it by myself. If someone could step up, that'd be 
great.


Do you think that libd is 32bit ready ?

https://github.com/SDC-Developers/SDC/pull/141


Building on 32 bits and generating 32 bit code are 2 different 
things.


No I don't think libd can compile on a 32 bits system ATM, but 
I do not expect it to be that far away from being able to do 
so.


That's a pitty. libd itself could be usefull to program some 
tools for the language. I particularly think to IDE stuff like 
symbol list, module name finder, etc. So far in Coedit I use 
libdparse but if libd would be available for the 32 bit 
plateforms I won't be against using it.


That's a pitty that everybody ask for it, but nobody makes it 
happens, expecting it to magically fall from the sky.




Re: Looking for someone that could work on 32 bits support for SDC

2015-09-13 Thread dnewbie via Digitalmars-d

On Sunday, 13 September 2015 at 19:49:58 UTC, deadalnix wrote:
That's a pitty. libd itself could be usefull to program some 
tools for the language. I particularly think to IDE stuff like 
symbol list, module name finder, etc. So far in Coedit I use 
libdparse but if libd would be available for the 32 bit 
plateforms I won't be against using it.


That's a pitty that everybody ask for it, but nobody makes it 
happens, expecting it to magically fall from the sky.


WTF?