December 31, 2011
On 12/30/2011 10:50 PM, Walter Bright wrote:
> On 12/30/2011 8:34 PM, Timon Gehr wrote:
>> On 12/31/2011 05:19 AM, Walter Bright wrote:
>>> On 12/30/2011 8:02 PM, Timon Gehr wrote:
>>>> On 12/31/2011 04:50 AM, Walter Bright wrote:
>>>>> Because inevitably someone will write:
>>>>>
>>>>> #define FOO a + FOO
>>>>>
>>>>> and expect it to work (the correct expansion would be "a + FOO", not a
>>>>> stack overflow). The C preprocessor works this way, as do makefile
>>>>> macros, as Ddoc does.
>>>>
>>>> Makes sense, but why is it an issue if expansion is explicit?
>>>>
>>>> enum FOO = q{a + FOO};
>>>>
>>>> mixin(FOO);
>>>
>>> Because the expanded text is then rescanned for further macro replacement.
>>>
>>
>> Yes, but in q{a + FOO} there is none.
>
> #define FOO a+Foo
> FOO;
>
> What is the text after macro expansion?

Blast, I meant

#define FOO a+FOO
FOO;
December 31, 2011
On 12/31/2011 02:59 AM, so wrote:
> On Sat, 31 Dec 2011 03:40:43 +0200, Iain Buclaw <ibuclaw@ubuntu.com> wrote:
>
>> Take a pick of any examples posted on this ML. They are far better
>> fit to use as a test bed. Ideally one that does number crunching and
>> can't be easily folded away.
>
> Well not them but another dummy function, i didn't think it would differ
> this much.
>

real test() nothrow pure

> real test() // test.d
> real test() @inline // test_inl.d
> {
> real a=423123, b=432, c=10, d=100, e=4045, f=123;
> a = a / b * c / d + e - f;
> b = a / b * c / d + e - f;
> c = a / b * c / d + e - f;
> d = a / b * c / d + e - f;
> e = a / b * c / d + e - f;
> f = a / b * c / d + e - f;
> a = a / b * c / d + e - f;
> b = a / b * c / d + e - f;
> c = a / b * c / d + e - f;
> d = a / b * c / d + e - f;
> e = a / b * c / d + e - f;
> f = a / b * c / d + e - f;
> a = a / b * c / d + e - f;
> b = a / b * c / d + e - f;
> c = a / b * c / d + e - f;
> d = a / b * c / d + e - f;
> e = a / b * c / d + e - f;
> f = a / b * c / d + e - f;
> return f;
> }
>
> void main()
> {
> for(uint i=0; i<1_000_000_0; ++i)
> test();
> }

When marking the function as pure and nothrow dmd is able to optimize the loop:

.text._Dmain	segment
	assume	CS:.text._Dmain
_Dmain:
		push	RBP
		mov	RBP,RSP
		xor	EAX,EAX
L6:		inc	EAX
		cmp	EAX,0989680h
		jb	L6
		xor	EAX,EAX
		pop	RBP
		ret
.text._Dmain	ends


-- 
Mike Wey
December 31, 2011
On 31 December 2011 13:05, Mike Wey <mike-wey@example.com> wrote:
> On 12/31/2011 02:59 AM, so wrote:
>>
>> On Sat, 31 Dec 2011 03:40:43 +0200, Iain Buclaw <ibuclaw@ubuntu.com> wrote:
>>
>>> Take a pick of any examples posted on this ML. They are far better fit to use as a test bed. Ideally one that does number crunching and can't be easily folded away.
>>
>>
>> Well not them but another dummy function, i didn't think it would differ this much.
>>
>
> real test() nothrow pure
>
>
>> real test() // test.d
>> real test() @inline // test_inl.d
>> {
>> real a=423123, b=432, c=10, d=100, e=4045, f=123;
>> a = a / b * c / d + e - f;
>> b = a / b * c / d + e - f;
>> c = a / b * c / d + e - f;
>> d = a / b * c / d + e - f;
>> e = a / b * c / d + e - f;
>> f = a / b * c / d + e - f;
>> a = a / b * c / d + e - f;
>> b = a / b * c / d + e - f;
>> c = a / b * c / d + e - f;
>> d = a / b * c / d + e - f;
>> e = a / b * c / d + e - f;
>> f = a / b * c / d + e - f;
>> a = a / b * c / d + e - f;
>> b = a / b * c / d + e - f;
>> c = a / b * c / d + e - f;
>> d = a / b * c / d + e - f;
>> e = a / b * c / d + e - f;
>> f = a / b * c / d + e - f;
>> return f;
>> }
>>
>> void main()
>> {
>> for(uint i=0; i<1_000_000_0; ++i)
>> test();
>> }
>
>
> When marking the function as pure and nothrow dmd is able to optimize the loop:
>
> .text._Dmain    segment
>        assume  CS:.text._Dmain
> _Dmain:
>                push    RBP
>                mov     RBP,RSP
>                xor     EAX,EAX
> L6:             inc     EAX
>                cmp     EAX,0989680h
>                jb      L6
>                xor     EAX,EAX
>                pop     RBP
>                ret
> .text._Dmain    ends
>
>
> --
> Mike Wey

Yep, as I've mentioned earlier, the function has no side effects and it's return value is not used, hence can be optimised away completely.

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
December 31, 2011
On 12/31/2011 07:50 AM, Walter Bright wrote:
> On 12/30/2011 10:50 PM, Walter Bright wrote:
>> On 12/30/2011 8:34 PM, Timon Gehr wrote:
>>> On 12/31/2011 05:19 AM, Walter Bright wrote:
>>>> On 12/30/2011 8:02 PM, Timon Gehr wrote:
>>>>> On 12/31/2011 04:50 AM, Walter Bright wrote:
>>>>>> Because inevitably someone will write:
>>>>>>
>>>>>> #define FOO a + FOO
>>>>>>
>>>>>> and expect it to work (the correct expansion would be "a + FOO",
>>>>>> not a
>>>>>> stack overflow). The C preprocessor works this way, as do makefile
>>>>>> macros, as Ddoc does.
>>>>>
>>>>> Makes sense, but why is it an issue if expansion is explicit?
>>>>>
>>>>> enum FOO = q{a + FOO};
>>>>>
>>>>> mixin(FOO);
>>>>
>>>> Because the expanded text is then rescanned for further macro
>>>> replacement.
>>>>
>>>
>>> Yes, but in q{a + FOO} there is none.
>>
>> #define FOO a+Foo
>> FOO;
>>
>> What is the text after macro expansion?
>
> Blast, I meant
>
> #define FOO a+FOO
> FOO;

FOO; -> a + FOO;

mixin(FOO~";"); -> a + FOO;

The two do the same thing.
January 02, 2012
"maarten van damme" <maartenvd1994@gmail.com> wrote in message news:mailman.1985.1325157846.24802.digitalmars-d@puremagic.com...
>I think it would be an object oriented language, I'm a believer in the
> string theory :)

I heard on the Science Channel that M-theory was becoming favored over string therory. (Not that I would actually know.)

> I have actually thought of the whole universe as one big simulation, would really explain how light waves without medium (like a math function).
>

I came across a book one time that talked about the 'verse basically being one big quantum computer. I didn't actually red through it though, and I can't remember what it was called... :(

> If I were god I would def use object oriented because it makes for easy
> describing of different particles and strings. and I'm pretty sure there
> is
> no garbage collector included in gods language :p
>

If I were god, then I'd presumably be omnipotent, and if I were omnipotent, then I'd be able to do it all in something like FuckFuck, or that shakesperian language, or that lolcat language without any difficulty. And I could just fix any limitations in the implementation. So that would seem the best option :)


January 02, 2012
On Thursday, December 29, 2011 12:23:47 maarten van damme wrote:
> I think it would be an object oriented language, I'm a believer in the string theory :)

Well, if you want to discuss string theory...

http://xkcd.com/171/
http://xkcd.com/397/

:)

- Jonathan M Davis
January 02, 2012
"Andrei Alexandrescu" <SeeWebsiteForEmail@erdani.org> wrote in message news:jdilar$k66$1@digitalmars.com...
> On 12/29/11 2:29 PM, Walter Bright wrote:
>> On 12/29/2011 11:47 AM, Walter Bright wrote:
>>> On 12/29/2011 3:19 AM, Vladimir Panteleev wrote:
>>>> I'd like to invite you to translate Daniel Vik's C memcpy implementation to D: http://www.danielvik.com/2010/02/fast-memcpy-in-c.html
>>>
>>> Challenge accepted.
>>
>> Here's another version that uses string mixins to ensure inlining of the COPY functions. There are no call instructions in the generated code. This should be as good as the C version using the same code generator.
> [snip]
>
> In other news, TAB has died with Kim-Jong Il. Please stop using it.
>

Tab is indeed evil when certain people insist it should be size 8  ;)


January 02, 2012
On Thu, 29 Dec 2011 21:08:29 +0100, FeepingCreature <default_357-line@yahoo.de> wrote:

> On 12/29/11 19:27, Walter Bright wrote:
>> On 12/29/2011 2:15 AM, Caligo wrote:
>>> If there is a God (I'm not saying there
>>> isn't, and I'm not saying there is), what language would he choose to create the
>>> universe?
>>
>> Mathematics.
>
> Fan of Tegmark¹, eh? :)
>
> --
>
> ¹http://en.wikipedia.org/wiki/Mathematical_universe_hypothesis

I love that one. My favorite is that it indicates the existence of a boolean
universe. I like to believe it is currently 'off'.
January 02, 2012
"Timon Gehr" <timon.gehr@gmx.ch> wrote in message news:jdlbpq$2b7e$1@digitalmars.com...
>
> What the template 'X' currently achieves is an improvement in syntax:
>
> string generated = "foo!\""~x~"\"(\""~bar(y)~"\")";
>

Ewww, who in the world uses double-quote strings for code containing quotes? That's not a fair comparison. This is a better comparison:

string generated = `foo!"`~x~`"("`~bar(y)~`")`;

vs

string generated = mixin(X!q{
   foo!"@(x)"("@(bar(y))")
});



January 02, 2012
On 01/02/2012 11:07 PM, Nick Sabalausky wrote:
> "Timon Gehr"<timon.gehr@gmx.ch>  wrote in message
> news:jdlbpq$2b7e$1@digitalmars.com...
>>
>> What the template 'X' currently achieves is an improvement in syntax:
>>
>> string generated = "foo!\""~x~"\"(\""~bar(y)~"\")";
>>
>
> Ewww, who in the world uses double-quote strings for code containing quotes?
> That's not a fair comparison. This is a better comparison:
>
> string generated = `foo!"`~x~`"("`~bar(y)~`")`;
>
> vs
>
> string generated = mixin(X!q{
>     foo!"@(x)"("@(bar(y))")
> });
>
>
>

What if the code contains both " and `? Using `` strings for code that contains quotes is not a general solution.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18