April 13, 2006
full ack
April 13, 2006
Bruno Medeiros wrote:
> Derek Parnell wrote:
>> On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote:
>>> dennis luehring wrote:
>>>
>>>> if( x ==  10 && x == 20 && x == 30 )
>>>> simplified:
>>>> if( x == [10 && 20 && 30] )
>>>>
[...]
>>>
>>> hmm, come to think of it, maybe it can already be implemented with templates.
>>>
>>> so,
>>>
>>> if( x == 10 || x == 20 || x == 30 )
>>>
>>> becomes:
>>> if( equals!(x).anyOf( 10, 20, 30 ) )
>>>
> In the template example? Why did both of you think a template was necessary? One can do this with plain old functions. Well, with typesafe variadic functions that is:
>   equalsAny( x + y, 10, b, c)
> also possible (but somewhat weird..) :
>   equals(x + y).AnyOf(10, b, c)
> 
> Or am I missing something terribly obvious? :o
> 
> 

templates insure inlining and provide more options for optimization. not terribly critical but...
April 14, 2006
On Fri, 14 Apr 2006 05:58:54 +1000, Bruno Medeiros <brunodomedeirosATgmail@SPAM.com> wrote:

> One can do this with plain old functions. Well, with typesafe variadic functions that is:
>    equalsAny( x + y, 10, b, c)
> also possible (but somewhat weird..) :
>    equals(x + y).AnyOf(10, b, c)
>
> Or am I missing something terribly obvious? :o

You are missing nothing ... we can do lots of stuff using functions.

   equals(result, add(x,y))

or

  result = x + y;

Why do we have such syntax sugar?

-- 
Derek Parnell
Melbourne, Australia
April 14, 2006
Bruno Medeiros wrote:
> Derek Parnell wrote:
> 
>> On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote:
>>
>>> dennis luehring wrote:
>>>
>>>> for example how often do we use constructs like
>>>>
>>>> if( x ==  10 && x == 20 && x == 30 )
>>>>
>>>> simplified:
>>>> if( x == [10 && 20 && 30] )
>>>>
>>>> if( a >= h && b >= h && c >= h )
>>>>
>>>> simplified:
>>>> if( [a && b && c] >= h )
>>>>
>>>> (just an idea)
>>>>
>>>> ciao dennis
>>>
>>> I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
>>>
>>> hmm, come to think of it, maybe it can already be implemented with templates.
>>>
>>> so,
>>>
>>> if( x == 10 || x == 20 || x == 30 )
>>>
>>> becomes:
>>> if( equals!(x).anyOf( 10, 20, 30 ) )
>>>
>>> or something like that!
>>>
>>> any template guru up to it?
>>>
>>> On a side note: the expression( x == 10 && x == 20 && x == 30 ) is rediclious, it's always false ;)
>>
>>
>> Try not using literals ... ;-)
>>
> In the template example? Why did both of you think a template was necessary? One can do this with plain old functions. Well, with typesafe variadic functions that is:
>   equalsAny( x + y, 10, b, c)
> also possible (but somewhat weird..) :
>   equals(x + y).AnyOf(10, b, c)
> 
> Or am I missing something terribly obvious? :o
> 
> 

Sure you can do them with functions, it just adds a bit of unnecessary overhead.

I don't usually care much if a nice structure/design adds a small runtime overhead, but I noticed that alot of D'ers do care, so that's why I pospsed a templated solution.
April 14, 2006
In ECMAScript itself, you can write code like:

a && a.doSomething();
or
a = a || defaultValue;

It feels so much better than:

if(a) a.doSomething();
if(!a) a = defaultValue;

Maybe because it doesn't need indentation.  Maybe because it falsely makes me feel better about branching.  Maybe it's 'cause logicals are just sexy.


April 14, 2006
Derek Parnell wrote:
> On Fri, 14 Apr 2006 05:58:54 +1000, Bruno Medeiros <brunodomedeirosATgmail@SPAM.com> wrote:
> 
>> One can do this with plain old functions. Well, with typesafe variadic functions that is:
>>    equalsAny( x + y, 10, b, c)
>> also possible (but somewhat weird..) :
>>    equals(x + y).AnyOf(10, b, c)
>>
>> Or am I missing something terribly obvious? :o
> 
> You are missing nothing ... we can do lots of stuff using functions.
> 
>    equals(result, add(x,y))
> 
> or
> 
>   result = x + y;
> 
> Why do we have such syntax sugar?
> 
> --Derek Parnell
> Melbourne, Australia

I wasn't saying we should use functions, I was just saying they were more adequate here than a template.


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
April 15, 2006
Dan wrote:
> In ECMAScript itself, you can write code like:
> 
> a && a.doSomething();
> or
> a = a || defaultValue;
> 
> It feels so much better than:
> 
> if(a) a.doSomething();
> if(!a) a = defaultValue;
> 
> Maybe because it doesn't need indentation.  Maybe because it falsely makes me
> feel better about branching.  Maybe it's 'cause logicals are just sexy.
> 
> 

[code]
import std.stdio;

int main ( char [][] args )
{
	uint a = 10;
	uint b = 0;

	b |= a;
	writefln(b);
	a |= b;
	writefln(a);

	return 0;
}
[/code]

Output:
:!./test
10
10

Works quite fine for me.
April 18, 2006
Hasan Aljudy skrev:
> dennis luehring wrote:
<SNIP>
> I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
> 
This problem domain and and then some is easily solved with sets, as I have proposed at many occasions in the past :).

As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well.

The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing.

Only some more fancy C/D like syntax is needed.

// Fredrik Olsson
April 18, 2006
Fredrik Olsson schrieb:
> Hasan Aljudy skrev:
>> dennis luehring wrote:
> <SNIP>
>> I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
>>
> This problem domain and and then some is easily solved with sets, as I have proposed at many occasions in the past :).
> 
> As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well.
> 
> The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing.
> 
> Only some more fancy C/D like syntax is needed.
> 
> // Fredrik Olsson

how would you write these example in your in syntax?

if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c )

if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) )

ciao dennis

April 19, 2006
dennis luehring skrev:
> Fredrik Olsson schrieb:
>> Hasan Aljudy skrev:
>>> dennis luehring wrote:
>> <SNIP>
>>> I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
>>>
>> This problem domain and and then some is easily solved with sets, as I have proposed at many occasions in the past :).
>>
>> As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well.
>>
>> The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing.
>>
>> Only some more fancy C/D like syntax is needed.
>>
>> // Fredrik Olsson
> 
> how would you write these example in your in syntax?
> 
Not that easy as sets is mostly not a simple solution for complex conditions, but a simple solution to complex set problems.

> if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c )
> 
> if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) )
> 
These are not good examples of where sets strength lies, this is a better example:

if (x == [a || b || c]) --> if (x == a || x == b || x == c)
would be
if (x in <a, b, c>)

But the true power lies in what can be done with sets, unions, intersections, etc.


regards
// Fredrik Olsson