Re: For those ready to take the challenge

2015-01-10 Thread MattCoder via Digitalmars-d-learn
On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote: https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro From the link: "Let's show Stroustrup what small and readable program actually is." Alright, there are a lot a

Re: A nice D coding pattern

2014-11-25 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 25 November 2014 at 13:56:23 UTC, bearophile wrote: Right. So the instance data of the struct is more likely correct when you call its methods. Thanks. - Well I'd like to see more of these tips. My current code in D looks like C++ and of course I sure that I'm not extracting the p

Re: A nice D coding pattern

2014-11-25 Thread MattCoder via Digitalmars-d-learn
On Monday, 24 November 2014 at 22:50:33 UTC, bearophile wrote: And the @disable this() assures that a struct is correctly initialized by the constructor. In the statement: @disable this() May I understand that you're "disabling" the "default" constructor of the struct to use your own construct

Re: How to start with d lang.

2014-11-02 Thread MattCoder via Digitalmars-d-learn
On Sunday, 2 November 2014 at 20:49:00 UTC, Kornel wrote: What learning materials do you recommend ?? http://ddili.org/ders/d.en/ Matheus.

Re: Reflections on isPalindrome

2014-10-29 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 16:07:38 UTC, MachineCode wrote: I'm very surprise. If they either equal or fast sometimes the compiler did great optizations or it's just a multicore processor that's helping or what else? the first version (from your post, the one using ranges) change in each it

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 13:30:05 UTC, Nordlöw wrote: On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote: I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Try compiling with DMD flag -release and perhaps also -release -noboundschec

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 11:48:37 UTC, MattCoder wrote: And in my benchmark test, the first version is 3x "slower" than the second one. I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Matheus.

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
Hi, I don't know if I'm missing something but I did some tests with the popFront and popBack version: bool isPalindrome(R)(R range) if (isBidirectionalRange!(R)) { while (!range.empty){ if (range.front != range.back) return false; range.popFront();

Re: Reducing an array

2014-04-19 Thread MattCoder via Digitalmars-d-learn
On Saturday, 19 April 2014 at 17:12:10 UTC, Ali Çehreli wrote: On 04/19/2014 09:55 AM, MattCoder wrote: > On Friday, 18 April 2014 at 20:02:41 UTC, Tim Holzschuh via > Digitalmars-d-learn wrote: > void main(){ > int myfilter(int a){ > static int[] b; That static

Re: Reducing an array

2014-04-19 Thread MattCoder via Digitalmars-d-learn
On Friday, 18 April 2014 at 20:02:41 UTC, Tim Holzschuh via Digitalmars-d-learn wrote: Hi there, I try to remove all equal elements of an array, thus [2,2] --> [2]. I thought this maybe would be possible with std.algorithm.reduce, but at least the way I tried it doesn't work: arr.reduce(

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
On Friday, 28 June 2013 at 19:43:37 UTC, Simen Kjaeraas wrote: import std.stdio; import std.typecons : tuple; auto foo(int x, int y){ writeln(x, y); return tuple(3, 4); } void main(){ foo(foo(1,2).tupleof); } Hi Simen, Thanks for your help too, it worked!

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
On Friday, 28 June 2013 at 19:39:41 UTC, Ellery Newcomer wrote: However, they can return std.typecons.Tuple, so you could do this: auto foo(int i, int j) { writeln(i, " ", j); return tuple(3,4); } void main() { foo(foo(1,2).field); } Hi Ellery, Thanks for your help, it works nic

[Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
Hi, I would like to know if it's possible to pass the return of a function as argument to another function as below: import std.stdio; auto foo(int x, int y){ writeln(x, y); return 3, 4; } void main(){ foo(foo(1,2)); } I would like to print: 1 2 3 4 PS: I tried retu

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: [Sharing]Tuple to variables (My Function)

2013-06-14 Thread MattCoder
On Saturday, 15 June 2013 at 00:47:01 UTC, bearophile wrote: You have to verify in the function constraint that the lengths match. In fact that was intentional, because sometimes I just want few items from a tuple not all. For example: auto RGB = tuple(255, 125, 50); Variant r,g; tupleToVar

[Sharing]Tuple to variables (My Function)

2013-06-14 Thread MattCoder
Hi, Sooner I asked about this ([Doubt] Variadic arguments as reference (Possible?) - - http://forum.dlang.org/thread/jwujjhjizkovvmbeg...@forum.dlang.org). In fact my intend was to recreate a feature that I like in Python, where you can assign variables from a tuple, e.g.: pos = (10, 20) x

Re: [Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread MattCoder
On Friday, 14 June 2013 at 13:20:26 UTC, Regan Heath wrote: import std.stdio; import std.conv; void sum(double value, double*[] numbers ...){ foreach(ref num; numbers) *num = *num + value; } void main(){ double a = 1, b = 2, c = 3; sum(10, &a, &b, &c);

[Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread MattCoder
Hi, I want to know if there is a way to pass variadic arguments as reference? DMD says no! I wrote the snippet code below, but what I want to do in fact is assign the sum back to respective variables to use somewhere else. http://dpaste.dzfl.pl/515edfb8 or import std.stdio; import std.con

Re: Check/Compare a value using "in"

2012-11-03 Thread MattCoder
Hi, I would like to say thanks to "Adam D. Ruppe" and "Ali Çehreli", since they answered straight to the point! Thanks again, Matheus.

Check/Compare a value using "in"

2012-11-02 Thread MattCoder
Hi, I need to check if some value exists in a list (Array). To achieve that, I'm using Associative Arrays like this: // Example void main() { int[char] aa = [ '+' : 0, '-' : 1]; char ch = '+'; if(ch in aa) // doSomething()... } But I'm looking for a more simple way like: if(ch in

Re: "For" infinite loop

2012-08-13 Thread MattCoder
On Monday, 13 August 2012 at 08:18:08 UTC, Marco Leise wrote: Am Mon, 13 Aug 2012 00:53:43 +0200 schrieb "bearophile" : It looks better. But you every time you use a cast in D you need to be careful, because they are like a sharp tool with almost no safeties. Bye, bearophile So true. It ha

Re: "For" infinite loop

2012-08-12 Thread MattCoder
On Saturday, 11 August 2012 at 20:38:33 UTC, bearophile wrote: bioinfornatics: n this case why not using a while loop ? It uses less lines of code, and with the for loop you have a single place where to put the loop variable initialization, test and increment. This makes the code simpler to