Re: lazy variables

2018-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/18/18 10:08 AM, aliak wrote: On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus wrote: On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: lazy S x = () {     // do some heavy stuff }(); if (condition) {   func(x.y); // heavy stuff evaluated here } auto x = () {     //

Re: lazy variables

2018-10-18 Thread aliak via Digitalmars-d-learn
On Thursday, 18 October 2018 at 16:10:04 UTC, aliak wrote: On Thursday, 18 October 2018 at 14:16:56 UTC, Simen Kjærås wrote: On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: Hi, Is there any notion of lazy vars in D (i see that there're parameters)? What the language doesn't

Re: lazy variables

2018-10-18 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: Hi, Is there any notion of lazy vars in D (i see that there're parameters)? What the language doesn't provide, it generally provides the tools to make: struct Lazy(T) { T delegate() _payload; this(lazy T t) {

Re: lazy variables

2018-10-18 Thread aliak via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 20:32:40 UTC, Ali Çehreli wrote: On 10/17/2018 12:32 AM, aliak wrote: [...] Not very clean but something like this: import std.stdio; struct LazyVar(alias exp) { alias T = typeof(exp()); T value() { static bool initialized = false;

Re: lazy variables

2018-10-18 Thread aliak via Digitalmars-d-learn
On Thursday, 18 October 2018 at 14:16:56 UTC, Simen Kjærås wrote: On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: Hi, Is there any notion of lazy vars in D (i see that there're parameters)? What the language doesn't provide, it generally provides the tools to make: struct

Re: lazy variables

2018-10-18 Thread aliak via Digitalmars-d-learn
On Thursday, 18 October 2018 at 14:11:36 UTC, Steven Schveighoffer wrote: Yes, but that's what lazy variables do. -Steve Not in Swift at least...

Re: lazy variables

2018-10-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 October 2018 at 14:08:11 UTC, aliak wrote: On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus wrote: auto x = () { // do some heavy stuff }; if (condition) { func(x().y); // heavy stuff evaluated here } That would do heavy stuff everytime i wanted to get y

Re: lazy variables

2018-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/18/18 12:11 PM, aliak wrote: On Thursday, 18 October 2018 at 14:11:36 UTC, Steven Schveighoffer wrote: Yes, but that's what lazy variables do. Not in Swift at least... Apparently so (I have not used them before), but this is D! So you should be aware that lazy parameters work that

Re: How to store unique values of array in another array

2018-10-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 October 2018 at 18:39:18 UTC, Samir wrote: which leads me to believe that the output of `uniq` is not necessarily another integer array. Right, it is actually a "range" - an object that generates the result on-demand, so it doesn't do work you don't actually need. If you

Why is dynamic array length required here?

2018-10-18 Thread Samir via Digitalmars-d-learn
I am working my way through the exercises in the "Programming in D" tutorial (http://ddili.org/ders/d.en/arrays.html). Why is the line assigning the length of the dynamic array required? /* Write a program that asks the user how many values will be entered and then reads all of them. Have

Re: Why is dynamic array length required here?

2018-10-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 19 October 2018 at 02:04:37 UTC, Samir wrote: I am working my way through the exercises in the "Programming in D" tutorial (http://ddili.org/ders/d.en/arrays.html). Why is the line assigning the length of the dynamic array required? [...] Without the line: myArray.length =

Re: Why is dynamic array length required here?

2018-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/2018 07:04 PM, Samir wrote: > myArray.length = noValues; // I get a run-time error if I comment > this out It's because the expression that reads the elements below is readf, which reads on top of an existing element. > while (i < noValues) { > write("enter value

Re: How to store unique values of array in another array

2018-10-18 Thread Samir via Digitalmars-d-learn
On Thursday, 18 October 2018 at 18:53:06 UTC, Adam D. Ruppe wrote: But, if you need to copy it into a new array, use `.array` at the end. Thanks. That did the trick. But if I may, what is the difference between uniqueArray = uniq(sort(unsortedArray)).array; and uniqueArray =

Re: Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 18, 2018 4:50:18 AM MDT Paolo Invernizzi via Digitalmars-d-learn wrote: > There's a rational behind the fact that there's not a 'shared' > version of notify/wait method in Condition? > > Thanks, > Paolo The original author of the stuff in core.sync didn't want to update it

Path.GetDirectoryName for D?

2018-10-18 Thread Dr.No via Digitalmars-d-learn
Are there a function like C#'s Path.GetDirectoryName() (https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getdirectoryname?redirectedfrom=MSDN=netframework-4.7.2#System_IO_Path_GetDirectoryName_System_String_) in D standard library or some dub package? just checking if there's one, so

Re: Path.GetDirectoryName for D?

2018-10-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 October 2018 at 19:54:59 UTC, Dr.No wrote: Are there a function like C#'s Path.GetDirectoryName() Looks the same as "dirName" from "import std.path" http://dpldocs.info/experimental-docs/std.path.dirName.1.html

How to store unique values of array in another array

2018-10-18 Thread Samir via Digitalmars-d-learn
What is the proper way to find the unique values of an array and store them in another array? When I try: import std.stdio: writeln; import std.conv; import std.algorithm; void main() { int[] unsortedArray = [5, 3, 8, 5, 2, 3, 0, 8]; int[] uniqueArray; uniqueArray =

Re: How to store unique values of array in another array

2018-10-18 Thread Samir via Digitalmars-d-learn
On Thursday, 18 October 2018 at 19:25:26 UTC, Adam D. Ruppe wrote: Which is better simply depends on which one reads better to you. Thanks again, Adam.

Re: How to store unique values of array in another array

2018-10-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 October 2018 at 19:19:53 UTC, Samir wrote: They both seem to work. Is one preferred over the other? No difference. The compile will just transform o.f into f(o) if it can. They both do the same thing and it is just a different way of writing it. Which is better simply

Re: Why is dynamic array length required here?

2018-10-18 Thread Mike Parker via Digitalmars-d-learn
On Friday, 19 October 2018 at 02:04:37 UTC, Samir wrote: I would have thought that since this is a dynamic array, I don't need to pre-assign its length. Thanks Just to expand on the previous answers, a dynamic array declaration with no initializer is an empty array: int[] arr;

Re: Documents about ddoc? and markdown in ddoc?

2018-10-18 Thread rikki cattermole via Digitalmars-d-learn
On 18/10/2018 6:38 PM, dangbinghoo wrote: hi, Is there any other documents related about ddoc usage? the only thing I can find is:  https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples But I found it never mentioned something like $(LI a  list item), is there a full ddoc

Re: Documents about ddoc? and markdown in ddoc?

2018-10-18 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 18 October 2018 at 05:59:36 UTC, rikki cattermole wrote: On 18/10/2018 6:38 PM, dangbinghoo wrote: hi, Is there any other documents related about ddoc usage? the only thing I can find is:  https://dlang.org/spec/ddoc.html#using_ddoc_to_generate_examples But I found it never

Re: Who can stop it ? Help me,thank you.

2018-10-18 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 13:48:04 UTC, FrankLike wrote: Hi,teacher: I like D lang,when I download the soft from http://www.360totalsecurity.com/en/ Contact their support: supp...@360safe.com

Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Paolo Invernizzi via Digitalmars-d-learn
There's a rational behind the fact that there's not a 'shared' version of notify/wait method in Condition? Thanks, Paolo

Re: Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 18 October 2018 at 10:50:18 UTC, Paolo Invernizzi wrote: There's a rational behind the fact that there's not a 'shared' version of notify/wait method in Condition? They were implemented before complete `shared` spec existed, which is any time between it's conception and now.

Re: Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Kagamin via Digitalmars-d-learn
On Thursday, 18 October 2018 at 10:50:18 UTC, Paolo Invernizzi wrote: There's a rational behind the fact that there's not a 'shared' version of notify/wait method in Condition? core.sync is pretty old, it was written in 2009 before default storage class for global variables became TLS.

Re: lazy variables

2018-10-18 Thread aliak via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus wrote: On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: lazy S x = () { // do some heavy stuff }(); if (condition) { func(x.y); // heavy stuff evaluated here } auto x = () { // do some heavy stuff }; if

Re: lazy variables

2018-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/18 3:32 AM, aliak wrote: Hi, Is there any notion of lazy vars in D (i see that there're parameters)? i.e: struct S {   //...   int y;   //... } /* lazy S x = () {     // do some heavy stuff }(); */ auto x() { // do some heavy stuff } if (condition) {   func(x.y); //