Re: mutable constant?

2013-06-26 Thread Namespace
You're right. I didn't read over the OP's example carefully enough. The mutation is being done to a module-level variable in an inout function, which is completely legit. I thought that what the OP thought was wrong was mutating a module-level variable in a non-mutable function (and that's perf

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Jesse Phillips
On Wednesday, 26 June 2013 at 20:51:35 UTC, Gary Willoughby wrote: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http://stackoverflow.com/questions/731832/interview-question-ffn-n Well, considering there is little to th

Re: mutable constant?

2013-06-26 Thread Jonathan M Davis
On Thursday, June 27, 2013 03:31:01 anonymous wrote: > On Thursday, 27 June 2013 at 00:53:48 UTC, Jonathan M Davis wrote: > > It looks to me like your code is fundamentally different from > > the OP's example > > rather than being a simplification of the original code. In the > > OP's example, > >

Re: mutable constant?

2013-06-26 Thread anonymous
On Thursday, 27 June 2013 at 00:53:48 UTC, Jonathan M Davis wrote: It looks to me like your code is fundamentally different from the OP's example rather than being a simplification of the original code. In the OP's example, the variable being mutated is a module-level variable, so the immutabil

Re: mutable constant?

2013-06-26 Thread Jonathan M Davis
On Thursday, June 27, 2013 01:45:22 anonymous wrote: > On Wednesday, 26 June 2013 at 15:48:42 UTC, Jonathan M Davis > > wrote: > > It doesn't break anything. It just shows the need for pure. > > Really? In the following simplified code I see mutation of an > immutable variable, which should not b

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/27/13, Andrej Mitrovic wrote: > On 6/27/13, H. S. Teoh wrote: >> Well, it's still cheating, though. :-P I think the 4-cycle algorithm is >> probably still the best one I've seen. > > What I don't understand is why the CPU is so slow that it takes ages > to go through int.min .. int.max in a

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread MattCoder
On Wednesday, 26 June 2013 at 22:43:05 UTC, David wrote: Am 26.06.2013 22:51, schrieb Gary Willoughby: I solved it ;) http://dpaste.dzfl.pl/5cd56e9d Yes, but "maybe" the interviewer is waiting just one function, since the question was: "Design a function f". So I rewrote your example: impo

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/27/13, H. S. Teoh wrote: > Well, it's still cheating, though. :-P I think the 4-cycle algorithm is > probably still the best one I've seen. What I don't understand is why the CPU is so slow that it takes ages to go through int.min .. int.max in a loop.

Re: mutable constant?

2013-06-26 Thread anonymous
On Wednesday, 26 June 2013 at 15:48:42 UTC, Jonathan M Davis wrote: It doesn't break anything. It just shows the need for pure. Really? In the following simplified code I see mutation of an immutable variable, which should not be possible, of course. That is breaking the type system, no? What

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread H. S. Teoh
On Thu, Jun 27, 2013 at 12:43:04AM +0200, David wrote: > Am 26.06.2013 22:51, schrieb Gary Willoughby: > > Just for a bit of fun, I saw this question posted on reddit the other > > day and wondered how *you* would solve this in D? > > > > http://stackoverflow.com/questions/731832/interview-questio

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Diggory
On Wednesday, 26 June 2013 at 22:43:05 UTC, David wrote: Am 26.06.2013 22:51, schrieb Gary Willoughby: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http://stackoverflow.com/questions/731832/interview-question-ffn-n I

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/26/13, Gary Willoughby wrote: > Just for a bit of fun, I saw this question posted on reddit the > other day and wondered how *you* would solve this in D? > > http://stackoverflow.com/questions/731832/interview-question-ffn-n Silly mathematicians, nobody said you had to make it performant. i

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread David
Am 26.06.2013 22:51, schrieb Gary Willoughby: > Just for a bit of fun, I saw this question posted on reddit the other > day and wondered how *you* would solve this in D? > > http://stackoverflow.com/questions/731832/interview-question-ffn-n I solved it ;) http://dpaste.dzfl.pl/5cd56e9d

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Marco Leise
> Anyway I've yet to see a solution that works for all input ;) Scratch that. -- Marco

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Marco Leise
Am Wed, 26 Jun 2013 22:52:17 +0200 schrieb "Gary Willoughby" : > The text from the question: > > Design a function f, such that: > > f(f(n)) == -n > Where n is a 32 bit signed integer; you can't use complex numbers > arithmetic. > > If you can't design such a function for the whole range of > n

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Mr. Anonymous
On Wednesday, 26 June 2013 at 20:51:35 UTC, Gary Willoughby wrote: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http://stackoverflow.com/questions/731832/interview-question-ffn-n First answer port: http://dpaste.dzfl.p

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Adam D. Ruppe
On Wednesday, 26 June 2013 at 20:51:35 UTC, Gary Willoughby wrote: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? Since they didn't say *pure* function, I'd cheat: int f(int n) { static bool isOddCall; isOddCall = !is

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Gary Willoughby
The text from the question: Design a function f, such that: f(f(n)) == -n Where n is a 32 bit signed integer; you can't use complex numbers arithmetic. If you can't design such a function for the whole range of numbers, design it for the largest range possible.

How would you solve this 'interview' question in D?

2013-06-26 Thread Gary Willoughby
Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http://stackoverflow.com/questions/731832/interview-question-ffn-n

Re: mutable constant?

2013-06-26 Thread monarch_dodra
On Wednesday, 26 June 2013 at 15:48:42 UTC, Jonathan M Davis wrote: It doesn't break anything. It just shows the need for pure. - Jonathan M Davis OO I just got it :( nevermind then...

Re: mutable constant?

2013-06-26 Thread Jonathan M Davis
On Wednesday, June 26, 2013 13:16:16 monarch_dodra wrote: > It seems safe, however, your example seems to show how to indeed > break the type system... without a cast (!): > > @property > Point* ptr() inout { > points[this.id].x = cast(int) this.x; > points[this.id].y =

Re: eof

2013-06-26 Thread lx
On Wednesday, 26 June 2013 at 13:45:41 UTC, lx wrote: On Wednesday, 26 June 2013 at 04:46:32 UTC, Ali Çehreli wrote: On 06/25/2013 09:26 PM, lx wrote: > Ctrl+z seems close the stream.So,if I want > to input another batch of data,it became impossilbe.So,how to reopen the > stream again to allow

Re: eof

2013-06-26 Thread lx
On Wednesday, 26 June 2013 at 04:46:32 UTC, Ali Çehreli wrote: On 06/25/2013 09:26 PM, lx wrote: > Ctrl+z seems close the stream.So,if I want > to input another batch of data,it became impossilbe.So,how to reopen the > stream again to allow me to input another batch of data? Making a copy of st

Re: mutable constant?

2013-06-26 Thread monarch_dodra
On Wednesday, 26 June 2013 at 07:35:08 UTC, Namespace wrote: On Tuesday, 25 June 2013 at 23:39:45 UTC, Ali Çehreli wrote: With apologies, I have unrelated comments to make. On 06/25/2013 03:07 PM, Namespace wrote: > this(T x, T y) { > this.x = x; > this.y = y; > > p

Re: Bug search: derelict3 and scope(exit)

2013-06-26 Thread Mike Parker
On Wednesday, 26 June 2013 at 07:55:29 UTC, Namespace wrote: Today Mike Parker figured out that it happens only if scope(exit) is used in combination with glPopAttrib. But That's not exactly what I was getting at. The problem isn't with scope(exit) or, I believe, glPopAttrib. It just so happen

Re: Bug search: derelict3 and scope(exit)

2013-06-26 Thread Namespace
Second workaround so far: Use something like that: scope(exit) glAvoidAE(glPopAttrib(mask)); with void glAvoidAE(lazy void Func) { Func(); } That's strange.

Bug search: derelict3 and scope(exit)

2013-06-26 Thread Namespace
Since I had a problem by using derelict3 (more precise: I get an Access Violation), Mike Parker and I were looking for the problem. Today Mike Parker figured out that it happens only if scope(exit) is used in combination with glPopAttrib. But because we have not much experience in reading assem

Re: mutable constant?

2013-06-26 Thread Namespace
On Tuesday, 25 June 2013 at 23:39:45 UTC, Ali Çehreli wrote: With apologies, I have unrelated comments to make. On 06/25/2013 03:07 PM, Namespace wrote: > this(T x, T y) { > this.x = x; > this.y = y; > > points ~= &this._point; I have seen similar designs in the