Re: How do I use in contract with interface?

2017-11-15 Thread Dr. Assembly via Digitalmars-d-learn
out(result) {} run fine, if foo() return 0, an exception is throw by assert() but in doesn't work. I don't know what I'm missing. It' my first time using contracts

How do I use in contract with interface?

2017-11-15 Thread Dr. Assembly via Digitalmars-d-learn
I'm learning to use interface with contracts. In below code, in isn't being "called". Can someone point out why? what am I doing wrong? void main() { C c = new C(); writeln(c.foo(1)); } interface I { int foo(int i) in { assert(i > 2); }

Re: string version of array

2017-11-14 Thread Dr. Assembly via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 08:21:59 UTC, Tony wrote: On Tuesday, 14 November 2017 at 07:56:06 UTC, rikki cattermole wrote: On 14/11/2017 7:54 AM, Tony wrote: Is there an easy way to get the string representation of an array, as would be printed by writeln(), but captured in a string?

setting file version, description, product name, etc

2017-11-11 Thread Dr. Assembly via Digitalmars-d-learn
I'm using below resource file as the following: "C:\dm\bin\rcc.exe" -32 -D__NT__ res.rc dmd -m32 -debug app.d res.res The icon is the only thing that is set. Everything else is missing from application's attributes. What am I missing? res.rc: IDI_ICON1 ICONDISCARDABLE

Re: Any book recommendation for writing a compiler?

2017-11-01 Thread Dr. Assembly via Digitalmars-d-learn
On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote: Hey guys, if I were to get into dmd's source code to play a little bit (just for fun, no commercial use at all), which books/resources do you recommend to start out? I'd like something on back-end too, for example, code

Any book recommendation for writing a compiler?

2017-11-01 Thread Dr. Assembly via Digitalmars-d-learn
Hey guys, if I were to get into dmd's source code to play a little bit (just for fun, no commercial use at all), which books/resources do you recommend to start out?

Re: "version" private word

2017-10-31 Thread Dr. Assembly via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 15:20:31 UTC, Igor Shirkalin wrote: On Tuesday, 31 October 2017 at 14:54:27 UTC, Dr. Assembly wrote: On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote: On 2017-10-31 14:46, Igor Shirkalin wrote: [...] The only alternative is to do something

Re: "version" private word

2017-10-31 Thread Dr. Assembly via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote: On 2017-10-31 14:46, Igor Shirkalin wrote: Hello! We need some conditional compilation using 'version'. Say we have some code to be compiled for X86 and X86_64. How can we do that using predefined (or other) versions? Examples:

Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread Assembly via Digitalmars-d-learn
I believe it's a design choice, if so, could someone explain why? is immutable better than C#'s readonly so that the readonly keyword isn't even needed? for example, I'd like to declare a member as readonly but I can't do it directly because immutable create a new type (since it's a type

Re: how do I create an array of objects as member of class?

2015-06-30 Thread Assembly via Digitalmars-d-learn
On Friday, 26 June 2015 at 22:14:56 UTC, Adam D. Ruppe wrote: On Friday, 26 June 2015 at 21:50:30 UTC, Assembly wrote: class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l = [a,b]; I wasn't aware about this. I'm used to have static only when I request so, like using static keyword

how do I create an array of objects as member of class?

2015-06-26 Thread Assembly via Digitalmars-d-learn
Imaginary code: class Foo { } class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l = [a,b]; } What should I use instead of to it work? Array!Foo(a,b) didn't worked either. I know this works: class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l; this() { l = [a,b]; }

How do I make my class iterable?

2015-06-22 Thread Assembly via Digitalmars-d-learn
Does D has an equivalent to C#'s iterator (https://msdn.microsoft.com/en-us/library/65zzykke.aspx)? if so, where can I find it? What I want is loop over a user-defined class/struct. In case of C#, I just implement the IEnumerable and the GetEnumerator() methods that's called by the foreach()

Re: How do I make my class iterable?

2015-06-22 Thread Assembly via Digitalmars-d-learn
On Monday, 22 June 2015 at 16:52:15 UTC, Ali Çehreli wrote: On 06/22/2015 09:37 AM, q66 wrote: use opApply. Yes. Additionally, an InputRange interface can be used: http://ddili.org/ders/d.en/foreach_opapply.html Ali I was reading exaclty this page that. I've had implmented this

Re: Does D has built-in stack structure?

2015-06-22 Thread Assembly via Digitalmars-d-learn
On Monday, 22 June 2015 at 08:18:08 UTC, Adrian Matoga wrote: On Monday, 22 June 2015 at 06:09:48 UTC, Assembly wrote: Does D has built-in stack structure (if so, which module?) or should I implement it myself? AFAIK there's no built-in, but std.array.Appender could be easily wrapped in an

Re: How do I make my class iterable?

2015-06-22 Thread Assembly via Digitalmars-d-learn
On Monday, 22 June 2015 at 17:09:16 UTC, Steven Schveighoffer wrote: On 6/22/15 1:03 PM, Assembly wrote: [...] TBH, opApply is much better suited to classes. But in order to have multiple parameters with foreach by using a range, you must return a tuple: auto front() { import

Does D has built-in stack structure?

2015-06-22 Thread Assembly via Digitalmars-d-learn
Does D has built-in stack structure (if so, which module?) or should I implement it myself?

Re: How do I make my class iterable?

2015-06-22 Thread Assembly via Digitalmars-d-learn
On Monday, 22 June 2015 at 18:07:36 UTC, Ali Çehreli wrote: On 06/22/2015 10:03 AM, Assembly wrote: foreach(int i, MyType p; places) { but I get this error: Error: cannot infer argument types, expected 1 argument, not 2 Yeah, the loop counter is automatic only for slices. You can use

Re: How do I make my class iterable?

2015-06-22 Thread Assembly via Digitalmars-d-learn
On Monday, 22 June 2015 at 20:34:00 UTC, anonymous wrote: On Monday, 22 June 2015 at 18:44:22 UTC, Assembly wrote: I'm using this, thanks for all. Can someone clarify how does opApply() works? I assume it's called every iteration and as opApply() has a loop does it means the number of

fast way to insert element at index 0

2015-06-22 Thread Assembly via Digitalmars-d-learn
What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val; t[1 .. $] = buffer; buffer = t; } I

Re: template instance template 'appender' is not defined

2015-05-31 Thread Assembly via Digitalmars-d-learn
I'm aware about format() from std.string but I have some code written which uses appender and I'm a bit affraid that this won't compile anymore