June 22, 2015
On 6/19/15 9:50 PM, Joakim wrote:

> Then there's always this:
>
> http://www.theverge.com/2015/6/19/8811425/heinz-ketchup-qr-code-porn-site-fundorado
>
>
> Not the fault of the QR code of course, just an expired domain name, but
> still funny. :)

Oh man. Note to marketing department -- all QR codes must point to ourcompany.com, you can redirect from there!!!

-Steve
June 23, 2015
On Wednesday, 10 June 2015 at 15:44:40 UTC, Andrei Alexandrescu wrote:
> On 6/10/15 1:53 AM, ponce wrote:
>> On Wednesday, 10 June 2015 at 07:56:46 UTC, John Chapman wrote:
>>> It's a shame ucent/cent never got implemented. But couldn't they be
>>> added to Phobos? I often need a 128-bit type with better precision
>>> than float and double.
>>
>> FWIW:
>> https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d
>
> Yes, arbitrary fixed-size integrals would be good to have in Phobos. Who's the author of that code? Can we get something going here? -- Andrei

Sorry for the delay. I wrote this code a while earlier.
I will relicense it anyway that is needed (if needed).
Currently lack the time to polish it more (adding custom literals would be the one thing to do).

June 23, 2015
On Wednesday, 17 June 2015 at 09:28:00 UTC, Tofu Ninja wrote:
>
> I actually thought about it more, and D does have a bunch of binary operators that no ones uses. You can make all sorts of weird operators like +*, *~, +++, ---, *--, /++, ~~, ~-, -~,
> >>>--, &++, ^^+, in++, |-, %~, ect...
>

+* is a specially bad idea, as I would read that as "a + (*b)", which is quite usual in C.

But in general very cool. I love ~~ and |- the most :-)
June 23, 2015
On Tuesday, 23 June 2015 at 16:33:29 UTC, Dominikus Dittes Scherkl wrote:
> On Wednesday, 17 June 2015 at 09:28:00 UTC, Tofu Ninja wrote:
>>
>> I actually thought about it more, and D does have a bunch of binary operators that no ones uses. You can make all sorts of weird operators like +*, *~, +++, ---, *--, /++, ~~, ~-, -~,
>> >>>--, &++, ^^+, in++, |-, %~, ect...
>>
>
> +* is a specially bad idea, as I would read that as "a + (*b)", which is quite usual in C.
>
> But in general very cool. I love ~~ and |- the most :-)

Yeah |- does seem like an interesting one, not sure what it would mean though, I get the impression it's a wall or something. Also you can basicly combine any binOp and any number of unaryOps to create an arbitrary number of custom binOps. ~+*+*+*+ could be valid! You could probably make something like brainfuck in D's unary operators.
June 24, 2015
On Wednesday, 17 June 2015 at 09:28:00 UTC, Tofu Ninja wrote:
>
> I actually thought about it more, and D does have a bunch of binary operators that no ones uses. You can make all sorts of weird operators like +*, *~, +++, ---, *--, /++, ~~, ~-, -~,
> >>>--, &++, ^^+, in++, |-, %~, ect...
>
> void main(string[] args){
> 	test a;
> 	test b;
> 	a +* b;
> }
> struct test{
> 	private struct testAlpha{
> 		test payload;
> 	}
> 	testAlpha opUnary(string s : "*")(){
> 		return testAlpha(this);
> 	}
> 	void opBinary(string op : "+")(test rhs){
> 		writeln("+");
> 	}
> 	void opBinary(string op : "+")(testAlpha rhs){
> 		writeln("+*");
> 	}
> }

Oh right, meant to respond to this.  I'll admit it took me a few to really get why that works-- it's fairly clever and moderately terrifying.  (I showed it to a friend and he opined it may violate the grammar.)

But playing with it a bit...well, it's very cumbersome having to do these overload gymnastics.  It eats away at your opUnary space because of the need for private proxy types, and each one needs an opBinary defined to support  it explicitly.  It also means you can't make overloads for mismatched types or builtin types (at least, I couldn't figure out how in the few minutes I spent poking it over lunch).

-Wyatt
June 24, 2015
On Wednesday, 24 June 2015 at 19:04:38 UTC, Wyatt wrote:
> On Wednesday, 17 June 2015 at 09:28:00 UTC, Tofu Ninja wrote:
>>
>> I actually thought about it more, and D does have a bunch of binary operators that no ones uses. You can make all sorts of weird operators like +*, *~, +++, ---, *--, /++, ~~, ~-, -~,
>> >>>--, &++, ^^+, in++, |-, %~, ect...
>>
>> void main(string[] args){
>> 	test a;
>> 	test b;
>> 	a +* b;
>> }
>> struct test{
>> 	private struct testAlpha{
>> 		test payload;
>> 	}
>> 	testAlpha opUnary(string s : "*")(){
>> 		return testAlpha(this);
>> 	}
>> 	void opBinary(string op : "+")(test rhs){
>> 		writeln("+");
>> 	}
>> 	void opBinary(string op : "+")(testAlpha rhs){
>> 		writeln("+*");
>> 	}
>> }
>
> Oh right, meant to respond to this.  I'll admit it took me a few to really get why that works-- it's fairly clever and moderately terrifying.  (I showed it to a friend and he opined it may violate the grammar.)
>
> But playing with it a bit...well, it's very cumbersome having to do these overload gymnastics.  It eats away at your opUnary space because of the need for private proxy types, and each one needs an opBinary defined to support  it explicitly.  It also means you can't make overloads for mismatched types or builtin types (at least, I couldn't figure out how in the few minutes I spent poking it over lunch).
>
> -Wyatt

I am thinking of writing a mixin that will set up the proxy for you so that you can just write.

struct test
{
     mixin binOpProxy("*");
     void opBinary(string op : "+*", T)(T rhs){
          writeln("+*");
     }
}

The hard part will be to get it to work with arbitrarily long unary proxies. Eg:
mixin binOpProxy("~-~");
void opBinary(string op : "+~-~", T)(T rhs){
     writeln("+~-~");
}
June 25, 2015
On 06/24/2015 11:41 PM, Tofu Ninja wrote:
> On Wednesday, 24 June 2015 at 19:04:38 UTC, Wyatt wrote:
>> On Wednesday, 17 June 2015 at 09:28:00 UTC, Tofu Ninja wrote:
>>>
>>> I actually thought about it more, and D does have a bunch of binary
>>> operators that no ones uses. You can make all sorts of weird
>>> operators like +*, *~, +++, ---, *--, /++, ~~, ~-, -~,
>>> >>>--, &++, ^^+, in++, |-, %~, ect...
>>>
>>> void main(string[] args){
>>>     test a;
>>>     test b;
>>>     a +* b;
>>> }
>>> struct test{
>>>     private struct testAlpha{
>>>         test payload;
>>>     }
>>>     testAlpha opUnary(string s : "*")(){
>>>         return testAlpha(this);
>>>     }
>>>     void opBinary(string op : "+")(test rhs){
>>>         writeln("+");
>>>     }
>>>     void opBinary(string op : "+")(testAlpha rhs){
>>>         writeln("+*");
>>>     }
>>> }
>>
>> Oh right, meant to respond to this.  I'll admit it took me a few to
>> really get why that works-- it's fairly clever and moderately
>> terrifying.  (I showed it to a friend and he opined it may violate the
>> grammar.)
>>
>> But playing with it a bit...well, it's very cumbersome having to do
>> these overload gymnastics.  It eats away at your opUnary space because
>> of the need for private proxy types, and each one needs an opBinary
>> defined to support  it explicitly.  It also means you can't make
>> overloads for mismatched types or builtin types (at least, I couldn't
>> figure out how in the few minutes I spent poking it over lunch).
>>
>> -Wyatt
>
> I am thinking of writing a mixin that will set up the proxy for you so
> that you can just write.
>
> struct test
> {
>       mixin binOpProxy("*");
>       void opBinary(string op : "+*", T)(T rhs){
>            writeln("+*");
>       }
> }
>
> The hard part will be to get it to work with arbitrarily long unary
> proxies. Eg:
> mixin binOpProxy("~-~");
> void opBinary(string op : "+~-~", T)(T rhs){
>       writeln("+~-~");
> }

Obviously you will run into issues with precedence soon, but this should do it:

import std.stdio;
struct Test{
    mixin(binOpProxy("+~+-~*--+++----*"));
    void opBinary(string op : "+~+-~*--+++----*", T)(T rhs){
        writeln("+~+-~*--+++----*");
    }
}

void main(){
    Test a,b;
    a +~+-~*--+++----* b;
}

import std.string, std.algorithm, std.range;
int operatorSuffixLength(string s){
	int count(dchar c){ return 2-s.retro.countUntil!(d=>c!=d)%2; }
	if(s.endsWith("++")) return count('+');
	if(s.endsWith("--")) return count('-');
	return 1;
}
struct TheProxy(T,string s){
    T unwrap;
    this(T unwrap){ this.unwrap=unwrap; }
    static if(s.length){
        alias NextType=TheProxy!(T,s[0..$-operatorSuffixLength(s)]);
        alias FullType=NextType.FullType;
		mixin(`
        auto opUnary(string op : "`~s[$-operatorSuffixLength(s)..$]~`")(){
            return NextType(unwrap);
        }`);
    }else{
        alias FullType=typeof(this);
    }
}

string binOpProxy(string s)in{
	assert(s.length>=1+operatorSuffixLength(s));
	assert(!s.startsWith("++"));
	assert(!s.startsWith("--"));
	foreach(dchar c;s)
		assert("+-*~".canFind(c));
}body{
	int len=operatorSuffixLength(s);
    return `
        auto opUnary(string op:"`~s[$-len..$]~`")(){
            return TheProxy!(typeof(this),"`~s[1..$-len]~`")(this);
        }
        auto opBinary(string op:"`~s[0]~`")(TheProxy!(typeof(this),"`~s[1..$-1]~`").FullType t){
            return opBinary!"`~s~`"(t.unwrap);
        }
    `;
}


June 25, 2015
On Thursday, 25 June 2015 at 01:32:22 UTC, Timon Gehr wrote:
> [...]

Heres what I came up with... I love D so much <3

module util.binOpProxy;

import std.algorithm : joiner, map;
import std.array : array;
struct __typeproxy(T, string s)
{
	enum op = s;
	T payload;
	auto opUnary(string newop)()
	{
		return __typeproxy!(T,newop~op)(payload);
	}
}

/**
 * Example:
 * struct test
 * {
 *     mixin(binOpProxy!("~", "*"));
 *
 *     void opBinary(string op : "+~~", T)(T rhs)
 *     {
 *         writeln("hello!");
 *     }
 *
 *     void opBinary(string op : "+~+-~*--+++----*", T)(T rhs)
 *     {
 *         writeln("world");
 *     }
 *
 *     void opBinary(string op, T)(T rhs)
 *     {
 *         writeln("default");
 *     }
 * }
 *
 */
enum binOpProxy(proxies ...) = `
    import ` ~ __MODULE__ ~ ` : __typeproxy;
    auto opBinary(string op, D : __typeproxy!(T, T_op), T, string T_op) (D rhs)
    {
        return opBinary!(op~D.op)(rhs.payload);
    }
` ~ [proxies].map!((string a) => `
    auto opUnary(string op : "` ~ a ~ `")()
    {
        return __typeproxy!(typeof(this),op)(this);
    }
`).joiner.array;


6 7 8 9 10 11 12 13 14 15 16
Next ›   Last »