December 09, 2005
In article <dnc9qi$23js$1@digitaldaemon.com>, Bruno Medeiros says...
>
<SNIP>
>
>That invariant in the middle of the typedef declaration seems a bit out
>of place. What if typedefs had a body, where you could put many
>invariants, unittests (not sure about the usefulness of this one) and
>even methods!
>Like:
>
>   enum weekday_enum { MON, TUE, WED, THU, FRI, SAT, SUN };
>   typedef weekday_enum weekday
>   {
>     invariant { assert(this >= MON && this <= SUN); }
>     bool isWeekDay() { return (this >= MON && this <= FRI); }
>     char[] toString() { ... // returns "Monday", "Tuesday", etc. }
>   }
>
>   ...
>
>   weekday wday;
>   wday = weekday.MON;
>   writefln( wday.toString() );
>
>
>-- 
>Bruno Medeiros - CS/E student
>"Certain aspects of D are a pathway to many abilities some consider to
>be... unnatural."

I like the idea. It has my vote. For trivial types that need math ops it's lots better than structs.


December 10, 2005
Fredrik Olsson wrote:
> David Medlock skrev:
> 
>> Fredrik Olsson wrote:
>>
>>> Ranges and sets :).
> 
> <snip>
> 
>> This is no slight on you, but its amusing to see programmers wish for features available on a language developed in 1970.. hee hee.
>>
>> (A Pascal fan)
>> -DavidM
>>
> 
> No coincident at all :). I am a Pascal fan as well, and Lisp fan, and Ruby fan and sql fan, and etc. I am simply choose what I feel is the best tool for the task at hand. For the general case Pascal tended to be it, before I found D. So naturally I want D to fill the few gaps I miss from my former #1.
> 
> //Fredrik
> 
> 

You actually /LIKE/ SQL?

http://orlyowl.com/omg.jpg
December 10, 2005
James Dunne wrote:
> Fredrik Olsson wrote:
> 
>> David Medlock skrev:
>>
>>> Fredrik Olsson wrote:
>>>
>>>> Ranges and sets :).
>>
>>
>> <snip>
>>
>>> This is no slight on you, but its amusing to see programmers wish for features available on a language developed in 1970.. hee hee.
>>>
>>> (A Pascal fan)
>>> -DavidM
>>>
>>
>> No coincident at all :). I am a Pascal fan as well, and Lisp fan, and Ruby fan and sql fan, and etc. I am simply choose what I feel is the best tool for the task at hand. For the general case Pascal tended to be it, before I found D. So naturally I want D to fill the few gaps I miss from my former #1.
>>
>> //Fredrik
>>
>>
> 
> You actually /LIKE/ SQL?
> 
> http://orlyowl.com/omg.jpg

SQL is reasonably laid out, and can be readily optimized since it is a declarative language, but its predecessor I like quite a lot more:

http://en.wikipedia.org/wiki/IBM_BS12


-DavidM
December 10, 2005
In article <dn6re3$ckq$1@digitaldaemon.com>, Fredrik Olsson says...
>
>Ranges and sets :).
>
>This is me more or less having a fantasy. Ranges and sets are without competition the two data types I use the most...

I find ranges and sets and tuples and other such Lispy datatypes extremely useful, too. Many popular recent languages include them and I'd like to see them in D to the extent possible.

>
>For example:
>	range minute 0..59;  // Static range
>	minute = 61;  // Exception if compiling with range checks
>
>	range slice: uint; // Dynamic range;
>	int[12] foo;
>	slice = 2..foo.length-2;
>	int[] bar = foo[slice];

>
>Naturally the operator in should be able to work with ranges so that one
>could do for example:
>	if (mychar in 'a'..'z') { ... }
>	while (somenumber in 1..42) { ... }

And let's not forget:
for (int i: 0..9) { ... }

I think that's a lot nicer than:
for (int i=0; i<9; i++) { ... }

and the compiler could easily generate the same code for both.

>
>And then sets:
>

>For example:
>	set alfa {'A'..'Z', 'a'..'z'};
>	set alfanum { alfa, '0'-'9' };
>
>	enum weekday { MON, TUE, WED, THU, FRI, SAT, SUN };
>	set weekdays weekday;
>	weekdays freedays = [TUE..THU, SAT];
>	if (selectedday in freedays) { ... }
>
>I mean how many of us have not written:
>	if (tolower(ch) >= 'a' && tolower(ch) <= 'z' &&
>	    ch >= '0' && ch <= '9') { ... }
>And even longer when writing for non English. This is much nicer:
>	if (toupper(ch) in ['A'..'Z', '0'..'9']) { ... }
>And a compiler can optimize easy to just test bits.

and again, something like:
for ( Day day : [MON..THU, SAT] ) { ... }

Python ran into some trouble with the concept of ranges because it was calculating all of the members first before using any of them. It then added the "xrange" feature, which is related to "generators" or "continuations". Each element in an xrange is calculated on a just-in-time basis rather than all up front. You can then use infinite sets (such as all prime numbers) the same way you use small finite sets.

You could then have something roughly like:
int generator primes = primeGenerator();
for (int i : primes) { ... }

primeGenerator would be a "generator" function that acted like a set of int's but would stay active on the stack between calls generating successive values (not "returning" values and leaving the stack between calls like a regular function, but staying loaded and "yielding" the next value each time it was called).

After writing the generator function "primeGenerator()", the programmer could then simply think of "primes" as the set of all prime numbers and use it like any other set.





December 13, 2005
> Bruno Medeiros wrote:
> And yes, the similarity to structs is something worth to note. Hum..

Right, it's like a struct that inherits from a basic type, isn't it?

struct weekday : weekday_enum
{
//...
}

or the same could be achieved by an anonimous member, or perhaps like with templates: member with the same name.

struct weekday
{
    weekday_enum    weekday;
}

which would make a weekday implicitely castable to a weekday_enum?

L.


December 14, 2005
David Medlock skrev:
> James Dunne wrote:
>> Fredrik Olsson wrote:
>>
>>> David Medlock skrev:
>>>
>>>> Fredrik Olsson wrote:
>>>>
>>>>> Ranges and sets :).
<snip>
>>>
>>
>> You actually /LIKE/ SQL?
>>
>> http://orlyowl.com/omg.jpg
> 
> SQL is reasonably laid out, and can be readily optimized since it is a declarative language, but its predecessor I like quite a lot more:
> 
> http://en.wikipedia.org/wiki/IBM_BS12
> 

SQL appeals to me because of it's small set of functionally that allows for so much to be done. I can not help it, but sometimes I chuckle for minutes after completing a particularly ingenious query :).

Combine with pl/SQL or PostgreSQL's pl/pgSQL and you pretty much have what you need. My company's current project is pretty much an server written in "PostgreSQL" with a dummy web GUI in PHP.

// Fredrik
1 2
Next ›   Last »