Jump to page: 1 2 3
Thread overview
To write such an expressive code D
Feb 09, 2015
Dennis Ritchie
Feb 09, 2015
Tobias Pankrath
Feb 09, 2015
Ali Çehreli
Feb 09, 2015
Dennis Ritchie
Feb 09, 2015
Vladimir Panteleev
Feb 09, 2015
Dennis Ritchie
Feb 09, 2015
Ali Çehreli
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
Ali Çehreli
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
Vladimir Panteleev
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
Tobias Pankrath
Feb 10, 2015
Dicebot
Feb 10, 2015
ketmar
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
bearophile
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
ketmar
Feb 10, 2015
Dennis Ritchie
Feb 10, 2015
Dennis Ritchie
Feb 11, 2015
bearophile
Feb 11, 2015
Dennis Ritchie
Feb 11, 2015
FG
February 09, 2015
Good evening.
Is it possible to D something to replace the container on the F#, which displays the values of the sine from 0 to 90 degrees with an interval of 10 degrees:
let pi = Math.PI
let sins = [for x in 0.0..pi / 2.0 / 9.0..pi / 2.0 -> sin x]
sins.Dump()

Output:
0
0,17364817766693
0,342020143325699
0,5
0,642787609686539
0,766044443118978
0,866025403784439
0,939692620785908
0,984807753012208
1

P.S. Interested in code that will be as impressive as this. In General, I would like to see something akin to D.
February 09, 2015
On Monday, 9 February 2015 at 19:40:42 UTC, Dennis Ritchie wrote:
> Good evening.
> Is it possible to D something to replace the container on the F#, which displays the values of the sine from 0 to 90 degrees with an interval of 10 degrees:
> let pi = Math.PI
> let sins = [for x in 0.0..pi / 2.0 / 9.0..pi / 2.0 -> sin x]
> sins.Dump()
>
> Output:
> 0
> 0,17364817766693
> 0,342020143325699
> 0,5
> 0,642787609686539
> 0,766044443118978
> 0,866025403784439
> 0,939692620785908
> 0,984807753012208
> 1
>
> P.S. Interested in code that will be as impressive as this. In General, I would like to see something akin to D.

iota(0, 91, 10).map!sin.writeln

or something like that.
February 09, 2015
On 02/09/2015 11:45 AM, Tobias Pankrath wrote:

> iota(0, 91, 10).map!sin.writeln
>
> or something like that.

Yes: :)

import std.math;
import std.stdio;
import std.range;
import std.algorithm;

void main()
{
    const beg = 0.0L;
    const interval = PI_2 / 9;
    const end = PI_2 + interval;

    auto sins = iota(beg, end, interval).map!sin;
    writefln("%(%.15g\n%)", sins);
}

0
0.17364817766693
0.342020143325669
0.5
0.642787609686539
0.766044443118978
0.866025403784439
0.939692620785908
0.984807753012208
1

Ali

February 09, 2015
Thank you, Tobias Pankrath and Ali Çehreli.
February 09, 2015
On Monday, 9 February 2015 at 19:57:23 UTC, Ali Çehreli wrote:
>     writefln("%(%.15g\n%)", sins);

In 2.067, you can write:

iota(0, PI/2, PI/2/9).map!sin.each!writeln;
February 09, 2015
On Monday, 9 February 2015 at 20:03:00 UTC, Vladimir Panteleev wrote:
> On Monday, 9 February 2015 at 19:57:23 UTC, Ali Çehreli wrote:
>>    writefln("%(%.15g\n%)", sins);
>
> In 2.067, you can write:
>
> iota(0, PI/2, PI/2/9).map!sin.each!writeln;

March 1!
February 09, 2015
On 02/09/2015 12:05 PM, Dennis Ritchie wrote:
> On Monday, 9 February 2015 at 20:03:00 UTC, Vladimir Panteleev wrote:
>> On Monday, 9 February 2015 at 19:57:23 UTC, Ali Çehreli wrote:
>>>    writefln("%(%.15g\n%)", sins);
>>
>> In 2.067, you can write:
>>
>> iota(0, PI/2, PI/2/9).map!sin.each!writeln;
>
> March 1!

Yes, but apparently D's default precision for output is less than F#'s so how about the following? :p

    "%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);

Just for demonstration, I would not write anything like that but the following is fine because now the format becomes the second parameter: :)

    iota(0, PI/2, PI/2/9).map!sin.writeF("%(%.15g\n%)");

void writeF(R)(R range, string format)
{
    return writefln(format, range);
}

Ali

February 10, 2015
On Monday, 9 February 2015 at 20:16:45 UTC, Ali Çehreli wrote:
> Yes, but apparently D's default precision for output is less than F#'s so how about the following? :p
>
>     "%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);
>
> Just for demonstration, I would not write anything like that but the following is fine because now the format becomes the second parameter: :)
>
>     iota(0, PI/2, PI/2/9).map!sin.writeF("%(%.15g\n%)");
>
> void writeF(R)(R range, string format)
> {
>     return writefln(format, range);
> }

Ali, and you can write it without using the function "iota()" and map?
"%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);

I just need that code was only used features of the language without using library functions. You may only use the function sin().
February 10, 2015
On 02/09/2015 08:17 PM, Dennis Ritchie wrote:

> Ali, and you can write it without using the function "iota()" and map?

No because the a..b syntax is not a D language construct that we can use anywhere that it makes sense. It only works as number ranges inside foreach loops, when indexing slices, and case value ranges.

Also no, because there is no equivalent of F#'s -> syntax, we have to use map.

> "%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);
>
> I just need that code was only used features of the language without
> using library functions. You may only use the function sin().

I am waiting to see a language solution that does not use even sin(). :o)

Ali

February 10, 2015
On Tuesday, 10 February 2015 at 06:17:17 UTC, Ali Çehreli wrote:
> On 02/09/2015 08:17 PM, Dennis Ritchie wrote:
>
> > Ali, and you can write it without using the function "iota()"
> and map?
>
> No because the a..b syntax is not a D language construct that we can use anywhere that it makes sense. It only works as number ranges inside foreach loops, when indexing slices, and case value ranges.
>
> Also no, because there is no equivalent of F#'s -> syntax, we have to use map.
>
> > "%(%.15g\n%)".writefln(iota(0, PI/2, PI/2/9).map!sin);
> >
> > I just need that code was only used features of the language
> without
> > using library functions. You may only use the function sin().
>
> I am waiting to see a language solution that does not use even sin(). :o)
>
> Ali
Thank you.
« First   ‹ Prev
1 2 3