Re: arrays in DMD V2

2014-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 04/18/2014 08:47 PM, steven kladitis wrote: Thanks, I am trying to understand what I am doing. The docs seem unclear to me on how to initialize these. I think there are three ways. with brackets , the other with foreach or direct assignments. -- here is a longer version -- uncomment out

Re: arrays in DMD V2

2014-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 04/19/2014 09:14 AM, steven kladitis wrote: // does not work I think you are thinking in terms of C's syntax. Unlike C, array definition syntax is consistent in D. I inserted spaces below to make it stand out: int[] [string] arr; The definition above is in the following form:

Re: Reducing an array

2014-04-19 Thread Ali Çehreli via Digitalmars-d-learn
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 variable makes this solution non-reentrant. To see an effect of this, replace the

Re: arrays in DMD V2

2014-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 04/19/2014 11:59 AM, steven kladitis wrote: I am getting a much clearer picture of arrays Great! :) a D manual or book just for D V2.0. They are all here: http://wiki.dlang.org/Books Ali

Re: Structs insted of classes for Performance

2014-04-20 Thread Ali Çehreli via Digitalmars-d-learn
My understanding is not perfect. There may be compiler and CPU optimizations that I am not aware of. On 04/20/2014 08:03 AM, Frustrated wrote: is the only argument really about performance when creating structs vs creating classes Not only creating but also when using. A class variable is a

Re: Best way to check for an element in an array?

2014-04-21 Thread Ali Çehreli via Digitalmars-d-learn
On 04/21/2014 09:22 PM, Taylor Hillegeist wrote: Question though? why doesn't canFind() work on statically allocated arrays? That's an issue all of face from time to time. (Happened to me again last week. :) ) The reason is, algorithms like canFind work with input ranges and fixed-length

The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[] result = reduce!((sum, _) = sum[])(seed, arr); writefln(%s,

Re: Named template constraints

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 07:07 AM, Tim Holzschuh via Digitalmars-d-learn wrote: read the 'More Templates' chapter of Ali's book (-- thanks for that ;) ). Yay! :) At the section 'Named constraints', there were a definition like this: template isUsable(T) { enum isUsable = is ( typeof( {

Re: The lifetime of reduce's internal seed

2014-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 11:03 AM, monarch_dodra wrote: On Tuesday, 22 April 2014 at 17:31:22 UTC, Ali Çehreli wrote: I opened the following bug before reading reduce's documentation carefully: https://issues.dlang.org/show_bug.cgi?id=12610 import std.stdio; import std.algorithm; void main() {

Re: Problem with code coverage. No .lst files?

2014-04-24 Thread Ali Çehreli via Digitalmars-d-learn
On 04/24/2014 08:32 PM, Jeremy DeHaan wrote: added the -cov switch to my unit test build Then you must execute the program. :) Ali

Re: The lifetime of reduce's internal seed

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2014 11:45 AM, monarch_dodra wrote: Reduce returns the seed. It's actually doing something more like this: int[1] foo() { int[1] sum sum = sum[]; //The lambda operates, and the //result is assigned back to the seed. return sum; //Returns the

Re: Problem with code coverage. No .lst files?

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2014 01:11 PM, Jeremy DeHaan wrote: If you compile with -cov AND use -of where the output file is in a different directory than where the build is taking place(eg, buld happens in C:/DProject/, and the command line has -ofC:/DProject/Unittest/Unittest.exe), no .lst files are

Re: storing pointers in Variants

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2014 04:08 PM, Matt wrote: I am trying to create a class that can do the following: --- int sample = 42; // myObj is an instance of the class I'm writing myObj.attach (othername, sample); myObj.set (othername, 69); writeln (myObj.get (othername), \t, sample); // should produce '69

Re: Can I circumvent nothrow?

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2014 06:39 PM, Damian Day wrote: Problem I have is inside shutdown_system() I have code that can't possibly be @nothrow because their are a lot of subsystems to shutdown. You can wrap the contents of shutdown_system() with a try-catch block and swallow all exceptions that way. Ali

Re: Static constructors inconsistency

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2014 12:10 PM, spec wrote: Hello, i'am experiencing some non consistent behavior with static constructors. I wonder if this is some bug or i just don't know enough of D (most probably!).. Code example bellow: //-- module main; import

Re: Creating Libraries Callable from C

2014-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2014 11:27 AM, Rémy Mouëza wrote: You will also have to declare 2 function for initializing and terminating D's runtime: char rt_init(long long); char rt_term(long long); call rt_init(0) before using your D functions (this will initialize D runtime - the D GC amongst

Re: 'auto' with AA

2014-04-27 Thread Ali Çehreli via Digitalmars-d-learn
fOn 04/27/2014 06:00 PM, David Held wrote: I would like to do something like this: Foo[Bar][Baz] nestedAA; auto innerAA = nestedAA[someBaz]; innerAA[someBar] = someFoo; assert(someFoo in nestedAA[someBaz]); in operator uses a key, not a value. This should work: assert(someBar in

Re: 'auto' with AA

2014-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 04/28/2014 12:12 AM, David Held wrote: Here is a compilable example which fails: void main() { double[int][string] nestedAA; nestedAA[test] = null; I think I see what's going on. The line above has almost no effect. For example, it does not populate test with an empty

Re: logging

2014-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 04/28/2014 01:16 PM, xtimoner wrote: synchronized class EventLog{ void opCall(string s){ std.file.append(logfile.txt, s); } } shared EventLog eventLog; Pleas, is it multithread safe and prefered way? Only if there is only one EventLog object. A synchronized class

Re: Is this a bug?

2014-04-29 Thread Ali Çehreli via Digitalmars-d-learn
On 04/29/2014 01:36 AM, John Colvin wrote: D dynamic arrays (better referred to as slices) can be thought of as implmented like struct Array(T) { T* ptr; size_t length; } They do not track ownership or have any reference counting. If they've been allocated with new then the

Re: Is this a bug?

2014-04-29 Thread Ali Çehreli via Digitalmars-d-learn
On 04/29/2014 10:01 AM, Meta wrote: On Tuesday, 29 April 2014 at 16:52:27 UTC, Ali Çehreli wrote: That may be misleading because there is no need to allocate with an explicit new. For example, the slice below is owned by the GC as well: int[] foo() { int[] a; a is an empty slice,

Re: Socket server + thread: cpu usage

2014-04-30 Thread Ali Çehreli via Digitalmars-d-learn
On 04/30/2014 04:24 PM, Damian Day wrote: Thread.sleep( dur!(msecs)( 20 ) ); Going off topic, the UFCS syntax makes that code much more readable. :) Thread.sleep(20.msecs); Ali

Re: Create many objects using threads

2014-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2014 10:25 AM, Ali Çehreli wrote: On 05/05/2014 10:14 AM, Caslav Sabani wrote: I want to have one array where I will store like 10 objects. But I want to use 4 threads where each thread will create 25000 objects and store them in array above mentioned. 1) If it

Re: Create many objects using threads

2014-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2014 01:38 PM, Caslav Sabani wrote: I am struggling to understand from your example where is the code that creates or spawns new thread. The .parallel in the foreach loop makes the body of the loop be executed in parallel. How do you create new thread and fill array with

Re: Create many objects using threads

2014-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2014 02:38 PM, Kapps wrote: I think that the GC actually blocks when creating objects, and thus multiple threads creating instances would not provide a significant speedup, possibly even a slowdown. Wow! That is the case. :) You'd want to benchmark this to be certain it helps. I

Re: Signals far from Slots

2014-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/04/2014 10:57 AM, Jim Hewes wrote: Is there a good way to connect signals and slots when the objects are far apart? All tutorials for signals and slots show the objects being readily accessible by the main() function. But what if they're not? Is there an elegant design? For example,

Re: Create many objects using threads

2014-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2014 04:32 PM, Caslav Sabani wrote: So basically using threads in D for creating multiple instances of class is actually slower. Not at all! That statement can be true only in certain programs. :) Ali

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 03:16 AM, Suliman wrote: When I had create instance of class in main, and create confvarible above it all worked, but when I had moved it's in module I got error. There is module 'static this()' for such runtime initialization: Config config; static this() { config = new

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 07:40 AM, Suliman wrote: Thanks! But is there any other solution? I am thinking that I am trying to specify config name by wrong way... Sorry, I don't understand what exactly you are trying to do. :( Is config file a compile-time concept? Do you want to read it at compile time?

Re: Create many objects using threads

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 05:46 AM, hardcoremore wrote: But what does exactly means that Garbage Collector blocks? What does it blocks and in which way? I know this much: The current GC that comes in D runtime is a single-threaded GC (aka a stop-the-world GC), meaning that all threads are stopped when

Re: The writeln() function's args can't be [一 ,二]?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 04:56 PM, FrankLike wrote: On Tuesday, 6 May 2014 at 15:03:11 UTC, Regan Heath wrote: IIRC you need to type chcp 65001 and set the command prompt to the Lucida font... R No,it's error.My OS is windows 7,chcp 936. SimpleChinese. I use the 'go language' to test I don't know

Re: [Rosettacode] D code line length limit

2014-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 05/07/2014 06:25 AM, bearophile wrote: limit to about 80 chars. I've never worked at a place where the limit was not 80. So, from my point of view it is still the industry standard and I like it. :) Ali

Re: Messy code in console

2014-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 05/10/2014 07:19 PM, IceNature via Digitalmars-d-learn wrote: When there are Chinese characters in the output, the console will display messy code.I change the encoding of the source file into UTF-8 or UTF-16,but the messy code is still there... I use the dmd

Re: Configuring Phobos from the 1-click installer

2014-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 05/10/2014 07:12 PM, Moses wrote: After using the 1-click Ubuntu installer, I'm having trouble figuring out how to import standard library functions for Phobos. I get the message: Error: module io is in file 'std/std/io.d' which cannot be read Judging from the repeated stds up there I

Re: question about passing associative array to a function

2014-05-11 Thread Ali Çehreli via Digitalmars-d-learn
On 05/11/2014 07:46 AM, rbutler wrote: I have searched and can not understand something about passing AAs to a function. I have reduced the gist of the question to a tiny program below. If I put ref in the function stmt it works, i.e.: ref int[int] aa My confusion is that AAs are

Re: question about passing associative array to a function

2014-05-11 Thread Ali Çehreli via Digitalmars-d-learn
On 05/11/2014 10:00 AM, John Colvin wrote: On Sunday, 11 May 2014 at 16:54:18 UTC, Ali Çehreli wrote: On 05/11/2014 07:46 AM, rbutler wrote: I have searched and can not understand something about passing AAs to a function. I have reduced the gist of the question to a tiny program

Re: naming a variable at runtime

2014-05-12 Thread Ali Çehreli via Digitalmars-d-learn
On 05/12/2014 08:47 PM, InfinityPlusB wrote: I want to be able to name the rows, as they are built. First, no, you cannot name variables at run time because variables are concepts of source code; they don't exist in the compiled program. So when row 1 is read in I get int[] bob_1 = new

Re: Messy code in console

2014-05-13 Thread Ali Çehreli via Digitalmars-d-learn
On 05/12/2014 09:53 PM, IceNature via Digitalmars-d-learn wrote: I've just thought of a problem. Others who uses my program on their computers needs to change their setting. It is a bit troublesome. It is also possible to set the code page when the program is running:

Re: Any chance to avoid monitor field in my class?

2014-05-14 Thread Ali Çehreli via Digitalmars-d-learn
On 05/14/2014 04:15 AM, Yuriy wrote: On Wednesday, 14 May 2014 at 10:21:00 UTC, Dejan Lekic wrote: that should not compile at all. Perhaps you thought extern(C++) interface MyClass(T) ? Ok, how about this one? http://dpaste.dzfl.pl/04655ff6ddfd It doesn't compile either. extern(C++)

Re: Seg fault when calling C code

2014-05-15 Thread Ali Çehreli via Digitalmars-d-learn
On 05/15/2014 01:55 PM, Andrew Brown wrote: extern(C) { void regress(int nInd, int nCov, ref double[] x, ref double[] y, ref double[] rOut); } I don't think that should even be allowed. C functions should not know or be compatible with 'ref' D parameters. Define the arguments as simple

Re: Objects(from classes) at Compile time? no gc

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/15/2014 09:59 PM, Taylor Hillegeist wrote: The subject says it all really. i have this example: import core.memory; class fruit{ int value=5; public int getvalue(){ return value; } } int main(string[] args) { GC.disable; static fruit myfruit; return

Re: Seg fault when calling C code

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 08:15 AM, Andrew Brown wrote: I guess my confusion came about because in the page about interfacing with C, there's a static array example where parameters are given in terms D understands: extern (C) { void foo(ref int[3] a); // D prototype } I guess D has no problem

Re: Seg fault when calling C code

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 08:24 AM, Ali Çehreli wrote: On 05/16/2014 08:15 AM, Andrew Brown wrote: void foo(ref int[3] a); // D prototype Since we know that references are implemented as pointers, 'ref int[3] a' is passed as a.ptr. Sorry, that's confusing. Yes, it ends up being equal to a.ptr

Re: idup class

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 01:28 PM, Joshua Niehus wrote: trying to follow: http://ddili.org/ders/d.en/class.html //--- OSX 10.9 DMD 2.065 module test; class Foo { int num; this(int num) { this.num = num; } Foo dup() const { return new Foo(this.num);

Re: idup class

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 01:37 PM, Steven Schveighoffer wrote: On Fri, 16 May 2014 16:36:36 -0400, Ali Çehreli acehr...@yahoo.com wrote: Beat you by 8 seconds :) -Steve I am happy to be within one minute. :) Ali

Re: Bug with std.string.indexOf and case sensivity

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 04:52 PM, Alexandre L. wrote: Hello, I was playing around with indexOf when I noticed that the parameter CaseSensitive seems to have a weird behavior. Let's say the following code: string str = Les chemises sont sèches; write(std.string.indexOf(str, Les)); // Returns 0, as

Re: Bug with std.string.indexOf and case sensivity

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 05:55 PM, Alexandre L. wrote: I'll try to fetch git head and get everything working. Alexandre L. Nevermind that. For some reasons, the bug was happening when my main.d file looked like this: import std.stdio; //import std.string; // will work when imported int main()

Re: std.concurrency thread communication problem

2014-05-17 Thread Ali Çehreli via Digitalmars-d-learn
On 05/17/2014 12:33 PM, John Colvin wrote: On Saturday, 17 May 2014 at 18:43:25 UTC, Charles Hixson via Digitalmars-d-learn wrote: I'm building a program which I intend to have many threads that can each send messages to (and receive messages from) each other. The obvious way to do this would

Is it possible to assumeSafeAppend malloced memory?

2014-05-19 Thread Ali Çehreli via Digitalmars-d-learn
We know that most of the time memory is allocated more than the requested amount. Is there a way to take advantage of that extra trailing space? (And potentially the pages that come after that.) import core.memory; void main() { const count = 1; // I think there is extra capacity

Re: Is it possible to assumeSafeAppend malloced memory?

2014-05-19 Thread Ali Çehreli via Digitalmars-d-learn
On 05/19/2014 06:55 AM, Steven Schveighoffer wrote: On Mon, 19 May 2014 09:44:44 -0400, monarch_dodra Recently, a new function in druntime was added: _d_newarrayU. Cool, I didn't know this! Thank you both! This information may be mentioned during a lightning talk at DConf. ;) Ali

Re: Modify char in string

2014-05-19 Thread Ali Çehreli via Digitalmars-d-learn
On 05/19/2014 10:07 AM, Tim wrote: I already tried: void main() { char[] sMyText = Replace the last char_; sMyText[$ - 1] = '.'; } but I always getting Error: cannot implicitly convert expression (Replace the last char_) of type string to char[].

Re: std.concurrency bug?

2014-05-20 Thread Ali Çehreli via Digitalmars-d-learn
On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: Is it a bug that an immutable struct cannot be sent to a thread? (It compiles without problem if I make all elements mutable.) Does the struct have any mutable indirection? Then it is illegal. Otherwise, can you

Re: std.concurrency bug?

2014-05-21 Thread Ali Çehreli via Digitalmars-d-learn
On 05/20/2014 05:24 PM, Charles Hixson via Digitalmars-d-learn wrote: On Tuesday, May 20, 2014 11:42:48 AM Ali Çehreli via Digitalmars-d-learn wrote: On 05/20/2014 11:38 AM, Charles Hixson via Digitalmars-d-learn wrote: Is it a bug that an immutable struct cannot be sent to a thread

Re: How to get array length

2014-05-22 Thread Ali Çehreli via Digitalmars-d-learn
On 05/22/2014 04:22 PM, kaz wrote: Is there a way to get the length of an array out of slice bracket in D? Tks. If you mean the length of the original array, no. Of course, the length of the slice is trivial: slice.length. The following article explains how slices don't know about other

Re: How to handle try-catch blocks, nothrow and logfiles

2014-05-24 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 10:09 AM, Tim wrote: I'm working on an application where I want log all exceptions but I'm not sure what's the best way to realize that. A common solution is to log it in the exception class'es constructor. We even dump the backtrace with libunwind in our C++ application.

Re: foreach over string

2014-05-24 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 09:46 AM, Kagamin wrote: foreach over string apparently iterates over chars by default instead of dchars. Didn't it prefer dchars? I don't think so. The range algorithms iterate by dchar though. string s=weiß; int i; foreach(c;s)i++; assert(i==5); Ali

Re: Creating ranges over mutable, const, or immutable data structures.

2014-05-24 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 10:02 AM, w0rp wrote: I have been writing my own hashmap which can provide forward ranges usable in @safe pure nothrow functions, because it's going to be useful for creating graph data structures with the same. I came to writing my ranges and I figured out how to do everything

Re: Creating ranges over mutable, const, or immutable data structures.

2014-05-25 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 10:02 AM, w0rp wrote: Create a mutable KeyRange over a map which forwards on the right constness for the key type, so the following must be true. HashMap!(K, V).keys.front - K const(HashMap!(K, V)).keys.front - const(K) immutable(HashMap!(K, V)).keys.front - immutable(K) I

Re: Passing a function as an argument to another function : what is this sorcery ?

2014-05-25 Thread Ali Çehreli via Digitalmars-d-learn
On 05/25/2014 02:37 AM, Derix wrote: DrawingArea da = new DrawingArea(590, 200); da.addOnDraw(onDraw); layout.put(da, 5, 30); add(layout); // Add the layout to our main window showAll(); } bool onDraw(Context c, Widget w) {

Re: next!T

2014-05-25 Thread Ali Çehreli via Digitalmars-d-learn
On 05/25/2014 05:21 PM, Andrew Edwards wrote: Hello All, I wrote the following convenience functions to aid in my studies. Unfortunately, I'm using Java books (Ali I will get to yours soon enough) so the need was necessitated by the frequency of use in the examples. Would appreciate a sanity

Re: Using custom attribute for a general parser. Is possible in D ?

2014-05-26 Thread Ali Çehreli via Digitalmars-d-learn
On 05/23/2014 09:09 AM, bioinfornatics wrote: struct A { @section( ( word ) = word[0] == '@', ( word ) = word[0] == '\n') int a; } I was able to make that work if I used function instead of delegate: import std.stdio; struct attribute { } alias MatchFunc = bool

Re: unittests D2.065.0 window 7

2014-05-26 Thread Ali Çehreli via Digitalmars-d-learn
On 05/26/2014 08:30 PM, Phillip Shelton wrote: When I compile this code with dmd -run ex43.d -w -unittest there is no output. It is the -run variable. dmd says: -run srcfile args... run resulting program, passing args So, both -w and -unittest become arguments to your compiled program,

Re: A question regarding Array capacity, length and slices

2014-05-29 Thread Ali Çehreli via Digitalmars-d-learn
On 05/29/2014 12:37 AM, Sourav wrote: the behavior totally depends upon how many elements were present initially in the array, which means, the capacity of a slice can actually introduces little surprises in the code! Is this expected behavior or am I entirely missing something here? It is

Re: Question about wrapping raw C pointers from D

2014-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/29/2014 09:38 PM, Rusty D. Shackleford wrote: Hi, in C++ I can use smart pointers to wrap raw pointers with custom deleter to automatically manage C resources. Is there anything like this in D? 1) Structs provide RAII: struct S { // ... ~this() { // cleanup } }

Re: enums

2014-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2014 08:30 AM, Russel Winder via Digitalmars-d-learn wrote: enum double p0 = 0.0045; As others have already said, p0 is a manifest constant. Interestingly, it can be thought of like a C macro, being pasted inside source code. Avoid enums for arrays and associative arrays

Re: Casting Structs

2014-05-31 Thread Ali Çehreli via Digitalmars-d-learn
On 05/31/2014 02:11 PM, Paul D Anderson wrote: I'm working on the decimal number package for D. A decimal is a struct with precision, max exponent and rounding mode parameters: Decimal!(PRECISION, MAX_EXPO, ROUNDING). I was trying to overload the opCast operator for this struct and I found that

Re: Delegate, scope and associative array

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 06/02/2014 10:40 PM, Edwin van Leeuwen wrote: On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote: On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote: As you may have guessed, a workaround is to copy the iteration variable yourself: unittest { size_t

Re: How to assign a delegate to a var ?

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 06/03/2014 05:57 AM, bioinfornatics wrote: On Tuesday, 3 June 2014 at 12:27:45 UTC, bioinfornatics wrote: I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error: expression template __lambda2 is void and has no value I do not want to

Re: Creating ranges over mutable, const, or immutable data structures.

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 11:01 AM, Ali Çehreli wrote: On 05/24/2014 10:02 AM, w0rp wrote: I have been writing my own hashmap which can provide forward ranges usable in @safe pure nothrow functions, because it's going to be useful for creating graph data structures with the same. I came to writing my

Re: how to get line number after readln

2014-06-04 Thread Ali Çehreli via Digitalmars-d-learn
On 06/04/2014 05:05 PM, Robert Hathaway wrote: I've got a program that reads a text file line by line (using std.stdio readln()) Consider using byLine() instead. (Important: byLine uses an internal buffer for the line; so, don't forget to make a copy if you want to store the line for later

Re: Writing to file problem (Kernelbase exeption)

2014-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 06/05/2014 01:39 PM, Konrad wrote: Right now I have: import file = std.file; import std.stdio; int game_change_config(string _player_spritesheet, string _flame_spritesheet) { string info = _player_spritesheet~\n~_flame_spritesheet; char[] info_table; for(int i = 0; i

Re: Separate allocation and construction?

2014-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 06/05/2014 03:47 PM, Chris Williams wrote: On Thursday, 5 June 2014 at 22:25:03 UTC, Adam D. Ruppe wrote: On Thursday, 5 June 2014 at 22:22:16 UTC, Chris Williams wrote: If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the

Re: How to sort a 2D array by column

2014-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 06/07/2014 12:18 PM, Chris Cain wrote: Also note that the examples use a string to define the predicate, but it accepts functions as well. Such as: bool myCompareFunc(AType lhs, AType rhs) { return lhs.blah rhs.blah; } //... AType[] arr; //...

Re: D aliases vs. C typedefs

2014-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 06/10/2014 01:18 PM, Tom Browder via Digitalmars-d-learn wrote: alias int[2] val5[2]; // D: a 2-dimensional array of ints? (int[2][2]) ? Pretty strange. :) pragma(msg, val5); outputs this: int[2][2] Okay, checks with my guess. alias int[4] val6[2]; // D: a

Re: D aliases vs. C typedefs

2014-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 06/10/2014 01:48 PM, monarch_dodra wrote: I am ***INCREDIBLY*** glad D's stance is simply depth first left to right. I completely agree. It *supports* C style, but unless you are copy pasting some C code, you'd have to be mad in your head to actually ever use it. Honestly, try to

Re: Basic dynamic array question. Use of new versus no new.

2014-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 06/10/2014 08:06 PM, Matt wrote: On Wednesday, 11 June 2014 at 02:30:01 UTC, WhatMeWorry wrote: int[] array; // initially empty array.length = 5; // now has 5 elements while in Mr. Alexandrescu's book, it says To create a dynamic array, use a new expression (§ 2.3.6.1 on page 51) as

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 01:26 PM, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; The dmd message are: di/test_hdr.d(10): Error: basic type expected, not null di/test_hdr.d(10): Error: semicolon expected to close alias declaration di/test_hdr.d(10): Error:

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 01:36 PM, Andrew Edwards wrote: void foo() {} alias bar = foo(); Am I just misunderstanding what is meant by types? Seems to be an old behavior. That does not compile with 2.066: Error: function declaration without return type. (Note that constructors are always named

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 02:06 PM, Tom Browder via Digitalmars-d-learn wrote: What I was really trying to do was D'ify C expressions like this: typedef ((struct t*)0) blah; Is that actually a function pointer typedef? I can't parse that line. :) So, taking your advice, I found this to work (at

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 03:38 PM, monarch_dodra wrote: Yet you can alias variables... int i; alias j = i; Initially I forgot about the fact that symbols can be alias'ed as well. So that's fine. So there's something special about null. The difference is that null is an expression. It is the same

Re: User defined forward range - foreach initializes f.r.

2014-06-13 Thread Ali Çehreli via Digitalmars-d-learn
I am making the following comment to have others confirm, as well as remind others about a potential problem. On 06/13/2014 11:14 AM, Andre wrote: unittest { auto intList = new List!int(1,2,3); [...] class List(T) { private T[] items; this(T[] items...) {

Re: Why is stdin.byLine.writeln so slow?

2014-06-13 Thread Ali Çehreli via Digitalmars-d-learn
On 06/13/2014 02:08 PM, monarch_dodra wrote: Given this input: line 1 line2 Yo! Then stdin.byLine.writeln will produce this string: [line 1, line\t2, Yo!] Do you mean writeln() first generates an array and then prints that array? I've always imagined that it used the range interface

Re: Why is stdin.byLine.writeln so slow?

2014-06-13 Thread Ali Çehreli via Digitalmars-d-learn
On 06/13/2014 03:02 PM, monarch_dodra wrote: No, it just receives a range, so it does range formating. eg: [ ~ Element ~ , ~ Element ... ]. It still looks like it could send the formatting characters as well as the elements separately to the output stream: [ Element , ... ] I am

Re: Casts and @trusted

2014-06-13 Thread Ali Çehreli via Digitalmars-d-learn
On 06/13/2014 06:56 PM, Anonymous wrote: @trusted void get_ref(TS strat=TS.cyclic)(size_t n, const(T*)[] refs) const nothrow { [...] cast(T*) refs[i] = cast(T*) _buffer[read].ptr; The left-hand side violates a promise: The function takes a slice where the elemenst

Re: Universal Construction Syntax for Pointers?

2014-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 06/13/2014 10:29 PM, Meta wrote: I thought this was possible, but DMD 2.065 doesn't allow it, saying no constructor for int: int* p = new int(3); Is something like this planned for the future? I know we can already do: int n = int(3); Those both compile with 2.066 Ali

Re: Placement of shared does not allow to set a delegate

2014-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 06/16/2014 05:35 AM, Tolga Cakiroglu wrote: In a class I defined an event attribute as follows: public void delegate( shared(SocketListener) sender ) eventWhenStarted; --- An instance of SocketListener is created. auto listener = new shared SocketListener(); --- I defined a shared

Re: Trying to sort shared data with a predicate causes 'unable to format shared objects'

2014-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 06/16/2014 07:45 PM, George Sapkin wrote: I'm trying to sort shared data with a predicate. Buy that causes 'unable to format shared objects'. Here's an example reproducing the issue without any threading code: shared class SomeClass { immutable int value; this(const int value) {

Re: Placement of shared does not allow to set a delegate

2014-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 06/16/2014 09:37 AM, Tolga Cakiroglu wrote: On Monday, 16 June 2014 at 15:25:51 UTC, Ali Çehreli wrote: Okay, now I continue with another thing. After defining the event attribute as follows public void delegate( shared(SocketListener) sender ) shared eventWhenStarted; --- I

Re: [Help]How to handle exception from dirEntries?

2014-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 06/16/2014 09:44 PM, Keqin wrote: Hi everyone, std.file.FileException@std\file.d(2519): C:\$Recycle.Bin\S-1-5-18: Access is den ied. I believe the exception comes from the following line: auto entries = dirEntries(dirpath, SpanMode.depth); Known issue:

Re: Trying to sort shared data with a predicate causes 'unable to format shared objects'

2014-06-17 Thread Ali Çehreli via Digitalmars-d-learn
On 06/17/2014 11:17 AM, George Sapkin wrote: On Tuesday, 17 June 2014 at 17:18:36 UTC, Ali Çehreli wrote: Shared data can be accessed by more than one thread. Unless it is locked, other threads may see the array in an inconsistent state. Ali But that's a local copy of it, no? If it's not,

Re: External threads calling into D code

2014-06-17 Thread Ali Çehreli via Digitalmars-d-learn
On 06/17/2014 06:43 PM, George Sapkin wrote: So, me and my threads again :) I have some threads being created by libuv using start_thread() from libpthread calling into D code. D code (after some help from this forum) has been properly shared and when called from D threads and tasks works

C++'s defaulted comparison operators proposal

2014-06-17 Thread Ali Çehreli via Digitalmars-d-learn
Can you come up with a D library solution to the following C++11 proposal: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3950.html The idea is to be able to have standard comparison behavior for structs without boilerplate. For example, if the ordering should consider all members

Re: Concurrency on Windows (spawn)

2014-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 06/18/2014 06:28 AM, Chris wrote: On Wednesday, 18 June 2014 at 11:57:06 UTC, Chris wrote: Windows: in a D-DLL I'm trying to spawn a thread. However, nothing happens auto myThread = spawn(myFunction, thisTid); send(myThread, arg); The thread is never called. Any ideas? Thanks! PS In an

Re: String cast error

2014-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 06/18/2014 06:04 PM, SomeRiz wrote: Thanks Teoh I'm trying compile but i get an error: b.d(22): Error: function b.extractSerial (string input) is not callable using ar gument types (ProcessOutput) According to its documentation, executeShell() returns a Tuple consisting of the return

Re: opAssign() calls members' postblits?

2014-06-21 Thread Ali Çehreli via Digitalmars-d-learn
On 06/21/2014 11:56 AM, Marc Schütz schue...@gmx.net wrote: import std.stdio; struct A { this(this) { writeln(A.this(this)); } B b1, b2; } struct B { this(this) { writeln(B.this(this)); }

Re: very short pipeShell program

2014-06-22 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2014 05:01 PM, WhatMeWorry wrote: After hours of reading (obviously not comprehending) std.process and looking at code samples, I still can't even do something this simple. Open a Windows command line and run miscellaneous commands. Only the first command, dir is shown in the final

Re: Passing around a list of differently typed functions

2014-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2014 11:32 PM, FreeSlave wrote: On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a,

Re: Compilation error while adding two shorts

2014-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 06/23/2014 10:03 PM, David Zaragoza wrote: Hello I'm trying to compile the following program: module main; int main(string[] argv){ short asd = 1; short qwe = asd + asd; return 0; } And the compiler gives this error: C:\Daviddmd simple simple.d(5): Error: cannot

Re: Equivalent of C++ std::function

2014-06-25 Thread Ali Çehreli via Digitalmars-d-learn
On 06/24/2014 08:33 PM, Yuushi wrote: I guess I need to do a fair bit more reading about alias. It is probably too basic for you but somebody else may find it useful: http://ddili.org/ders/d.en/lambda.html Ali

Re: Equivalent of C++ std::function

2014-06-25 Thread Ali Çehreli via Digitalmars-d-learn
On 06/24/2014 11:23 PM, Yuushi wrote: Yeah, I realised that when I went back and looked at what I'd tried: function string(string) transform; That gets me all the time! :-/ That is the long version of the function literal syntax: auto f = function string(string s) { return

  1   2   3   4   5   6   7   8   9   10   >