Re: To write such an expressive code D

2015-02-10 Thread FG via Digitalmars-d-learn
On 2015-02-11 at 01:56, bearophile wrote: Alternative solution closer to the F# code: import std.stdio, std.algorithm, std.typecons; int f(T)(T t) if (isTuple!T) { return t.predSwitch( tuple(0, 0, 0), 0, tuple(0, 1, 1), 0, tuple(1, 0, 1), 0, tuple(1, 1,

Re: To write such an expressive code D

2015-02-10 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 04:17:48 UTC, Dennis Ritchie wrote: I just need that code was only used features of the language without using library functions. You may only use the function sin(). Why is that? Although D has a lot of language features, D tries to push functionality into

Re: To write such an expressive code D

2015-02-10 Thread Dicebot via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 08:40:38 UTC, Dennis Ritchie wrote: Because I was arguing with one quiet a stubborn person who does not like D, on this forum: http://www.cyberforum.ru/holywars/thread1367892-page13.html He asked me to write such a program using only the language features and

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 08:12:00 UTC, Vladimir Panteleev wrote: Why is that? Потому что я спорил с одним упёртым человеком, которому не нравится D, на этом форуме: http://www.cyberforum.ru/holywars/thread1367892-page13.html Он просил меня написать такую программу с использованием

Re: To write such an expressive code D

2015-02-10 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 08:40:38 UTC, Dennis Ritchie wrote: On Tuesday, 10 February 2015 at 08:12:00 UTC, Vladimir Panteleev wrote: Why is that? Потому что я спорил с одним упёртым человеком, которому не нравится D, на этом форуме:

Re: To write such an expressive code D

2015-02-10 Thread ketmar via Digitalmars-d-learn
On Tue, 10 Feb 2015 08:40:36 +, Dennis Ritchie wrote: On Tuesday, 10 February 2015 at 08:12:00 UTC, Vladimir Panteleev wrote: Why is that? Потому что я спорил с одним упёртым человеком, которому не нравится D, на этом

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 11:33:54 UTC, bearophile wrote: Dennis Ritchie: Please help. This starts to look like homework :-) Bye, bearophile This is not homework - this is a war of code on C#/F# and D. I've been programming in D, my opponent on F#/C#.

Re: To write such an expressive code D

2015-02-10 Thread ketmar via Digitalmars-d-learn
On Tue, 10 Feb 2015 11:33:54 +, bearophile wrote: Dennis Ritchie: Please help. This starts to look like homework :-) it's much worse: meaningless pseudocomparison of different languages for nothing. signature.asc Description: PGP signature

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
Please help. import std.stdio; import std.stdio; void main() { /* return (a xor b xor c) */ int nobitxor(int a, int b, int c) { return (a + b + c == 2 || a + b + c == 0) ? 0 : 1; } int a, b, c; a = b = c = 0;

Re: To write such an expressive code D

2015-02-10 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: Please help. This starts to look like homework :-) Bye, bearophile

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 10 February 2015 at 11:41:20 UTC, ketmar wrote: On Tue, 10 Feb 2015 11:33:54 +, bearophile wrote: Dennis Ritchie: Please help. This starts to look like homework :-) it's much worse: meaningless pseudocomparison of different languages for nothing. This task

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
F#: let f = function | 0 , 0 , 0 - 0 | 0 , 1 , 1 - 0 | 1 , 0 , 1 - 0 | 1 , 1 , 0 - 0 | _ - 1 for a in 0..1 do for b in 0..1 do for c in 0..1 do printfn %i xor %i xor %i = %i a b c (f (a, b, c)) Output: 0 xor 0 xor 0 = 0 0 xor 0 xor 1 = 1 0

Re: To write such an expressive code D

2015-02-10 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: Output: 0 xor 0 xor 0 = 0 0 xor 0 xor 1 = 1 0 xor 1 xor 0 = 1 0 xor 1 xor 1 = 0 1 xor 0 xor 0 = 1 1 xor 0 xor 1 = 0 1 xor 1 xor 0 = 0 1 xor 1 xor 1 = 1 This man again took advantage of the fact that in D there is no such operation - (analog switch). A natural solution in D:

Re: To write such an expressive code D

2015-02-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 00:56:03 UTC, bearophile wrote: Dennis Ritchie: Output: 0 xor 0 xor 0 = 0 0 xor 0 xor 1 = 1 0 xor 1 xor 0 = 1 0 xor 1 xor 1 = 0 1 xor 0 xor 0 = 1 1 xor 0 xor 1 = 0 1 xor 1 xor 0 = 0 1 xor 1 xor 1 = 1 This man again took advantage of the fact that in D there

Re: To write such an expressive code D

2015-02-09 Thread Ali Çehreli via Digitalmars-d-learn
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,

Re: To write such an expressive code D

2015-02-09 Thread Dennis Ritchie via Digitalmars-d-learn
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

Re: To write such an expressive code D

2015-02-09 Thread Dennis Ritchie via Digitalmars-d-learn
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

Re: To write such an expressive code D

2015-02-09 Thread Dennis Ritchie via Digitalmars-d-learn
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!

Re: To write such an expressive code D

2015-02-09 Thread Tobias Pankrath via Digitalmars-d-learn
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 /

Re: To write such an expressive code D

2015-02-09 Thread Ali Çehreli via Digitalmars-d-learn
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;

Re: To write such an expressive code D

2015-02-09 Thread Ali Çehreli via Digitalmars-d-learn
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!

To write such an expressive code D

2015-02-09 Thread Dennis Ritchie via Digitalmars-d-learn
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

Re: To write such an expressive code D

2015-02-09 Thread Dennis Ritchie via Digitalmars-d-learn
Thank you, Tobias Pankrath and Ali Çehreli.

Re: To write such an expressive code D

2015-02-09 Thread Vladimir Panteleev via Digitalmars-d-learn
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;