Improper display of Cyrillic in `pragma (msg, ...)` on Windows

2016-08-05 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, To view Cyrillic CMD on Windows can be used `std.process.executeShell("chcp 65001 ");` and it works. What should I use to change the encoding to UTF-8 to the compiler messages in `pragma(msg, ...)` on Visual D? // import std.stdio, std.process; void

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? `Note: The ForeachTypeAttribute is implicit, and when a type is not specified, it is inferred. In that

Re: Higher Order Range Pattern

2015-06-22 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 22 June 2015 at 15:25:12 UTC, Steven Schveighoffer wrote: On 6/22/15 11:04 AM, Dennis Ritchie wrote: Hi, I recently came across the following code: http://wiki.dlang.org/Higher_Order_Range_Pattern I can't understand why the properties and methods of the structure are called in

Higher Order Range Pattern

2015-06-22 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, I recently came across the following code: http://wiki.dlang.org/Higher_Order_Range_Pattern I can't understand why the properties and methods of the structure are called in the correct order. Why are the property `back()` and the method `popBack()` are not called even once? In general,

Re: fast way to insert element at index 0

2015-06-22 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: 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

Re: How to avoid multiple spelling `import`

2015-06-16 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote: On Tue, 16 Jun 2015 11:45:22 + Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I just want to import individual features of these modules. mixin template include(w...) { mixin _include

How to avoid multiple spelling `import`

2015-06-16 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, I can write this: import std.range : chain, split; But I can not write this: import std.range : chain, split, std.algorithm : map, each; We have several times to write the word `import`: import std.range : chain, split; import std.algorithm : map, each; Does D something to solve this

Re: How to avoid multiple spelling `import`

2015-06-16 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 11:16:32 UTC, Idan Arye wrote: There is no problem to be solved here. Having to type `import` for each imported module is not big enough a burden to justify this additional syntax. No, I think it is a holdover from C++-times — to write `import` for each

Re: How to avoid multiple spelling `import`

2015-06-16 Thread Dennis Ritchie via Digitalmars-d-learn
Maybe not everyone needs these features. But, unfortunately, I often use a lot of imported modules. And use every time the word `import` very bad. version (none) { import std.math, std.conv, std.stdio, std.ascii, std.range, std.array, std.regex,

Re: appender!(dchar[]) put fail

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:32:19 UTC, kerdemdemir wrote: One more question I am asking those kind of questions to understand and not ask same stuff over and over, : auto totalStr = chain(stringB.replicate(bCount), stringC.replicate(cCount)); writeln(typeof(totalStr.array()).stringof);

Re: appender!(dchar[]) put fail

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:01:29 UTC, kerdemdemir wrote: Sorry to making the discussion longer and wasting your times. But I am looking for a way without for loops. Also looping every element one by one does not seems very efficient to me. Any advices for that? Maybe it fit? auto

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Please show an example of .dup you'd like to avoid. For example, if you need to create a five-dimensional array of strings :)

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: Do you like to write? char[][] strArray = [foo.dup, bar.dup, baz.dup]; Ok. That's all you're on about? Basically you'd like this: char[] s = foo; and this: char[][] a = [[foo]]; etc. Yes. That's right, and not otherwise :)

char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
Hello, everyone! I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply the method .dup each substring to make them work :) I

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. Do you like to write? char[][] strArray = [foo.dup, bar.dup, baz.dup]; I suggest that such an option: str[] strArray =

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Huh? You mean with string literals? That would be a rather silly reason to avoid `char[]`. Please show an example of .dup you'd like to avoid. Yes, string literals. I understand that the type of `string[]` to D is a simple data

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: I wish to propose the creation of new types of data D: str, wstr, dstr, which will be the analogs of C++ `std::vectorstd::string`. Ie str, wstr, dstr be mutable counterparts immutable strings respectively str (mutable(char[])),

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 18:15:30 UTC, Dennis Ritchie wrote: Actually, I will file issue `std.conv` in Phobos to add such specifications. It will suit me. *specializations

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:39:25 UTC, Kagamin wrote: Type is probably possible, though conversion method will be simpler. You can even try to write a specialization of `to` for multidimentional arrays if it doesn't work. It appears the problem can be solved by creating specifications

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:37:31 UTC, anonymous wrote: Please show how it is not. Seems to work just fine. OK. Still, this method works: char[][][][][][] strArr = [foo, baz], [bar, tor.to!(char[][][][][])]; But I don't want to write this `.to!(char[][][][][])`. On Saturday,

Re: Python's features, which requires D

2015-06-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 10:58:33 UTC, Kagamin wrote: On Saturday, 23 May 2015 at 02:36:14 UTC, Dennis Ritchie wrote: For example, the code in Python looks quite natural: a = [[int(j) for j in input().split()] for i in range(n)] About D-code, I can not say: auto a = stdin .byLine

Re: Reading array of integers readln performance issues

2015-06-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 11 June 2015 at 19:56:00 UTC, kerdemdemir wrote: Hi; To learn D better and challanging myself I am tring code computation's with D. There is a question which is about reading a line of integer which consist of 20 elements. My solution fails because Time limit exceeded, I

Re: Json

2015-06-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 11 June 2015 at 23:58:33 UTC, Cassio Butrico wrote: What does the .json file and how to use it? In D a file with the extension *.json is used to describe packets that are included in your project, the dependency manager DUB. For example, you can install Eclipse with DDT and

Re: Json

2015-06-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 12 June 2015 at 00:35:35 UTC, Cassio Butrico wrote: Thank you for answering me so fast , where do I get the DUB for windows ? http://code.dlang.org/download

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 17:43:36 UTC, Ali Çehreli wrote: On the other hand, if it's a manifest constant (enum, const static, etc.) then by definition it cannot be mutated. If we allowed mutation of compile-time expressions, then we would have a complicated language. Unfortunately, the

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 17:13:34 UTC, anonymous wrote: On Wednesday, 10 June 2015 at 17:00:34 UTC, Dennis Ritchie wrote: Isnt it possible to come up with the interpreter compile-time, which will determine the operating time of the program at runtime at compile time. Sounds like the

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-10 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 07:15:26 UTC, Ali Çehreli wrote: My phrasing was off: By definition, initialization happens once. :) What I meant is, once initialized, a compile-time variable cannot be reassigned. The reason is, to effect compile time evaluation, one needs to use 'enum' (or

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 7 June 2015 at 15:20:17 UTC, Ali Çehreli wrote: /* Some function that generates an AA */ Thanks. Beautiful code, but I want a little more :) /* Some function that generates an AA */ int[][int][int] initHash(int i) { /* It is nice to see that this function is not called at run

Re: Is it possible to add items to the arrays and hashes at compile time?

2015-06-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 03:38:32 UTC, Ali Çehreli wrote: The way I understand it and the way it makes sense to me, :) variables that are generated at compile time can be initialized only once. It is not possible after initialization. However, the initialization of the variable can be as

Mixin - to get to the content-type `MapResult!(__lambda1, int[]).MapResult`

2015-05-29 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, This code prints the arrays: [5] [6] [7] import std.stdio, std.algorithm; static int idx; void walk(R)(R range) { while (!range.empty) { range.front; range.popFront; ++idx; } } void main() { [5, 6, 7].map!(a = [a].writeln).walk; } How should I apply

Replacing nested loops foreach using map/each/etc

2015-05-25 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Is it possible to write such a construction that could push immediately to a conditional statement without using nested loops? Ie organize search directly in the iterator if provided by a map / each / iota and other support functions. Ie I want to write this code shorter :) import

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 25 May 2015 at 15:06:45 UTC, Alex Parrill wrote: Hint: Use `cartesianProduct` [1] with three iota ranges to replace the foreachs, and `filter` to replace the if [1] http://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct Thank you. Is it possible to replace the loop

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 25 May 2015 at 16:41:35 UTC, Meta wrote: import std.algorithm; import std.range; import std.stdio; void main() { const x = 12, y = 65, z = 50, s = 1435; auto a = iota(0, x + 1); cartesianProduct(a, a, a) .filter!(i = i[0] * (y + 3 * z) + i[1] * (y + 2

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 25 May 2015 at 19:16:04 UTC, anonymous wrote: On Monday, 25 May 2015 at 17:52:09 UTC, Dennis Ritchie wrote: But why is the solution breaks down when `s = 1` ? :) import std.stdio, std.algorithm, std.range; int c; const x = 12, y = 65, z = 50, s = 10; Which is it, now? 4

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 25 May 2015 at 17:19:27 UTC, Meta wrote: `each` doesn't support braces. There are 4 ways to write a function/delegate literal in D (with a few minor variations): Short form: function(int i) = i; (int i) = i (i) = i i = i Long form: function(int i) { return i; } (int i) { return i;

Re: Python's features, which requires D

2015-05-24 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 24 May 2015 at 02:43:47 UTC, Idan Arye wrote: I'm a fan of lisp(Clojure being my favorite. Too bad it takes about a century just to load the runtime...), and yet I find it quite ironic that Paul Graham claims lisp to be the most powerful language right after claiming that

Re: Python's features, which requires D

2015-05-24 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 24 May 2015 at 14:15:55 UTC, Idan Arye wrote: This IS ironic, because Paul Graham claims lisp to be the most powerful, but if he have ever encounter a more powerful language he couldn't accept it is more powerful than lisp due to the very same Blub Paradox he describes himself.

Re: Python's features, which requires D

2015-05-24 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 24 May 2015 at 15:53:24 UTC, Idan Arye wrote: But according to the Blub Paradox, your(Or mine. Or Paul Graham's) opinion on whether or not a stronger language than Lisp has appeared can not be trusted! Based on an article Graham about Blub Paradox, I can conclude that Blub Paradox

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 21:09:45 UTC, weaselcat wrote: After another review, I think some of these conversions to D could be expressed much easier if the built-in slice had multidimensional slicing It was added in 2.066* but I don't think there's any plans to add support for it to

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 20:44:37 UTC, cym13 wrote: Not sure what kind of meat you mean, but I really don't see much meat in ranges. Of course, this is 10 times better and easier to use than STL iterators C++. For me the most important feature D are mixins, which I, unfortunately, rarely

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 21:32:51 UTC, anonymous wrote: On Saturday, 23 May 2015 at 21:08:19 UTC, Dennis Ritchie wrote: Perhaps that's not the site, and in Windows. That's what gives me in CMD: 456 4 4 8 99 456 [[456, 4, 4, 8, 99, 456]13 546

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 19:22:40 UTC, Alex Parrill wrote: import std.algorithm; import std.range; import std.stdio; import std.conv; void main() { enum n1 = 5; writeln(stdin.byLine .map!(line = line.split( ).map!(x = to!int(x))) );

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 19:22:40 UTC, Alex Parrill wrote: You seem to be focusing on D's arrays only, but the real meat is in ranges, which are more generic. Also note that the above solution doesn't allocate any of the ranges in the heap; they're all on the stack (as opposed to Python,

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 20:57:10 UTC, anonymous wrote: On Saturday, 23 May 2015 at 20:25:18 UTC, Dennis Ritchie wrote: This does not work! enum n1 = 5; writeln(stdin.byLine .map!(line = line.split( ).map!(x = to!int(x))) ); - http://rextester.com/VGHZF81178 The code itself is

Re: Python's features, which requires D

2015-05-23 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 23 May 2015 at 10:58:33 UTC, Kagamin wrote: Well, list comprehension is built into language in python (and not in D), such level of support is definitely more streamlined. Well, what's to keep D more functions to work with slist and dlist ? In my opinion, lists in D completely

Re: Python's features, which requires D

2015-05-22 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 22 May 2015 at 05:31:38 UTC, Ali Çehreli wrote: Here is my attempt: import std.stdio; import std.algorithm; import std.conv; import std.range; void main() { // Replace 'none' with 'all' to activate. version (none) { const n = 5; auto a = stdin

Re: Python's features, which requires D

2015-05-22 Thread Dennis Ritchie via Digitalmars-d-learn
By the way, Python has deepDup :) http://rextester.com/KBFA82886

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 17:43:25 UTC, Jonathan M Davis wrote: No C-based language allows what python does, and based on operators work in C-based languages, what python is doing simply doesn't fit or make sense. What happens in C/C++/D/Java/C#/etc. land is that 4 = 5 results in a bool, at

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 21:35:22 UTC, Ali Çehreli wrote: We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what = min) (what = max); } void main() { if (5.is_between(4, 6)) { // ... } } Ali A condition is that if, for example,

Re: Python's features, which requires D

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 22 May 2015 at 01:17:17 UTC, weaselcat wrote: D doesn't have list comprehensions, so it's difficult to directly port these. I can not imagine how difficult it is to implement it in D, but I'm pretty sure that nested for loops to fill arrays (in D, you can call them differently,

Re: Python's features, which requires D

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 22 May 2015 at 02:18:23 UTC, weaselcat wrote: On Friday, 22 May 2015 at 01:52:30 UTC, Dennis Ritchie wrote: off the top of my head, the last one can easily be done with std.range.stride import std.stdio, std.range; void main() { int[] a = [ 1, 2, 3, 4, 5, 6 ];

Python's features, which requires D

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, I've collected some of Python's features. It seems to me that they are not in the D! Surely all this is in the D? :) http://rextester.com/CNQQR

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
Something I sometimes do for strictly personal projects: import std.typecons : ω = tuple; import std.typetuple : Ω = TypeTuple; void main() { auto a = 1, b = 2; Ω!(a, b) = ω(b, a); assert(a==2 b==1); } On Thursday, 21 May 2015 at 19:05:16 UTC, Steven Schveighoffer wrote: On

Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5 = 6) puts(OK); } - http://rextester.com/FICP83173 I wanted to ask what is the reason? Maybe the

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 17:17:29 UTC, Alex Parrill wrote: http://wiki.dlang.org/Language_Designs_Explained#Why_does_D_not_support_chaining_comparison_operators.3F Backward compatibility with C is nice but on the other hand it is a road to nowhere! Because of this compatibility, I'm

Re: How to create a mutable array of strings?

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 18 May 2015 at 13:14:38 UTC, Steven Schveighoffer wrote: It's annoying to have to dup each one. Yes, it's really annoying. However, the problem can be solved as follows:

The analogue of fill-pointer in D

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, In Common Lisp, there is such a thing as a fill-pointer (Example 5): http://www.tutorialspoint.com/lisp/lisp_arrays.htm Does D some equivalent?

Re: The analogue of fill-pointer in D

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 18 May 2015 at 10:14:33 UTC, Kagamin wrote: On Monday, 18 May 2015 at 08:21:38 UTC, Dennis Ritchie wrote: Hi, In Common Lisp, there is such a thing as a fill-pointer (Example 5): http://www.tutorialspoint.com/lisp/lisp_arrays.htm Does D some equivalent? Data stored in the array

Re: How to create a mutable array of strings?

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 18 May 2015 at 14:43:33 UTC, Steven Schveighoffer wrote: Right, you'd apply the map/array combo to each element: Yes, I knew it. alias m = map!(a = a.dup); // too bad can't do array as well auto s = [m([foo, baz]).array, m([bar, test]).array]; Or to get even more crazy: auto s

Re: The analogue of fill-pointer in D

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 18 May 2015 at 12:49:56 UTC, Kagamin wrote: Filling a buffer is usually done this way: http://dlang.org/phobos/std_stdio.html#.File.rawRead Here such example, the task. There is a flow stream, associated, for example, with any socket. It wrote several bytes at a time. To once

Re: The analogue of fill-pointer in D

2015-05-18 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 18 May 2015 at 17:14:46 UTC, Steven Schveighoffer wrote: capacity is analogous to the number of elements in the vector (as returned by array-dimension according to https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node162.html). arr.length is analogous to the fill pointer. example:

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:06:40 UTC, Dennis Ritchie wrote: Hi, It seems to me, or D do not create mutable array of strings? How to create a mutable equivalent of a string array? - string[] s = [foo, bar]; // s[1][1] = 't'; // immutable expression s[1][1] It's uncomfortable: -

How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, It seems to me, or D do not create mutable array of strings? How to create a mutable equivalent of a string array? - string[] s = [foo, bar]; // s[1][1] = 't'; // immutable expression s[1][1]

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
This option is also a strange: char[][] s = [foo.dup, bar.dup]; s[1][1] = 't'; In my opinion, you need to add to D keyword mutable.

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:18:15 UTC, Daniel Kozak wrote: auto s = cast(char[][])[foo, bar]; Thanks. This version I was completely satisfied.

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:24:19 UTC, anonymous wrote: On Sunday, 17 May 2015 at 09:20:17 UTC, Dennis Ritchie wrote: On Sunday, 17 May 2015 at 09:18:15 UTC, Daniel Kozak wrote: auto s = cast(char[][])[foo, bar]; Thanks. This version I was completely satisfied. Remember that Daniel Kozak

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
I remembered code Ali Çereli. It really helped: http://forum.dlang.org/thread/ulhtlyxxclihaseef...@forum.dlang.org#post-mihl6m:241che:241:40digitalmars.com - import std.stdio, std.traits, std.range, std.algorithm; auto deepDup(A)(A arr) if (isArray!A) { static if

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:36:33 UTC, anonymous wrote: On Sunday, 17 May 2015 at 09:26:15 UTC, Dennis Ritchie wrote: And no crashes on Windows :) Yeah, on windows it's even worse. void main() { auto s = cast(char[][])[foo, bar]; s[1][1] = 't'; import std.stdio;

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:37:56 UTC, Daniel Kozak wrote: So maybe this one would be ok with you too :) auto s = to!(char[][])([foo, bar]); Now it works :)

Re: How to create a mutable array of strings?

2015-05-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 17 May 2015 at 10:05:34 UTC, Daniel Kozak wrote: Ouch ignore this one :D Yes, it will not work with multidimensional arrays :)

Re: Feature or bug: print braces

2015-05-15 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 15 May 2015 at 08:44:41 UTC, Ivan Kazmenko wrote: Somehow reminds me of this lambda: https://github.com/Hackerpilot/Idiotmatic-D/blob/master/idiotmatic.d#L127-L128 Maybe it generally blocks for initialization of variables:

Re: Feature or bug: print braces

2015-05-14 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote: On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote: On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote: You told it to output a function literal, so it did. Yes, but it would be logical to deduce something

Re: Feature or bug: print braces

2015-05-14 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 14 May 2015 at 22:55:43 UTC, Ali Çehreli wrote: Yes, it is weird but that value happens to be the address of the function. Here is another test: import std.stdio; void foo() pure nothrow @nogc @safe {} void main() { void printInfo(T)(T t) { writefln(%s %s,

Re: Feature or bug: print braces

2015-05-13 Thread Dennis Ritchie via Digitalmars-d-learn
Turns out that I can put into the function writeln almost any design language: - import std.stdio; void main() { writeln( { int n = 5; } ); } - http://ideone.com/Rp7gZ2

Re: Feature or bug: print braces

2015-05-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote: You told it to output a function literal, so it did. Yes, but it would be logical to deduce something like: - writeln({}); // prints literal[{}] Or the compiler will not be able to distinguish the literal from the ordinary

Feature or bug: print braces

2015-05-13 Thread Dennis Ritchie via Digitalmars-d-learn
Why doesn't the compiler produces an error? - import std.stdio; void main() { writeln({}); } - http://ideone.com/qTZCAd

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 21:48:05 UTC, Timon Gehr wrote: Well, it is much slower due to all the allocated closures, owed to the fact that the implementations of 'fix' on that page are expected to mirror a particular famous implementation in untyped lambda calculus. In case you have a use

Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Can lambda functions or delegates in D to call themselves? Can I write something like this: - import std.stdio; void main() { auto fact = function (int x) = x * { if (x) fact(x - 1); }; assert(fact(10) == 3628800); }

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar to what I wanted :)

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 14:15:21 UTC, Ali Çehreli wrote: On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar to what I wanted :)

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 8 May 2015 at 06:30:46 UTC, Ali Çehreli wrote: In D, everything is possible and very easy. :p I called it deepDup: import std.stdio; import std.traits; import std.range; import std.algorithm; auto deepDup(A)(A arr) if (isArray!A) { static if (isArray!(ElementType!A)) {

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 8 May 2015 at 15:13:14 UTC, Ali Çehreli wrote: On 05/08/2015 08:05 AM, Dennis Ritchie wrote: why static int idx variable declared within a function deepDup takes the values 1, 1, 1, 2, 2, 3, 4, as opposed to a global variable static int idx, which receives the expected value of 1,

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 7 May 2015 at 23:13:41 UTC, PhilipDaniels wrote: On Thursday, 7 May 2015 at 23:10:26 UTC, PhilipDaniels wrote: Let's try reformatting that... ubyte r, g, b; // does not compile auto numRead = formattedRead(dropExactly(input, 4), %x/%x/%x, r, g, b); // does not compile auto

Why .dup not work with multidimensional arrays?

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Should the method .dup work with multidimensional arrays for copying? - import std.stdio; void main() { auto a = [1, 2, 3]; auto b = a.dup; b[] *= 2; writeln(a = , a); // [1, 2, 3] // OK writeln(b = , b); // [2, 4, 6] // OK auto c =

Re: Why .dup not work with multidimensional arrays?

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 8 May 2015 at 02:23:23 UTC, E.S. Quinn wrote: It's because arrays are references types, and .dup is a strictly shallow copy, so you're getting two outer arrays that reference the same set of inner arrays. You'll have to duplicated each of the inner arrays yourself if you need to make

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-05 Thread Dennis Ritchie via Digitalmars-d-learn
Realized bitmap, sorry that does not work with DMD 2.067.1: http://vlang.org/docs/Data_Types/Bits_and_Logic.html https://github.com/coverify/vlang/blob/master/src/esdl/data/bvec.d

Re: std.random question

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 09:04:07 UTC, tired_eyes wrote: On Sunday, 3 May 2015 at 08:48:52 UTC, Dennis Ritchie wrote: On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this:

Re: std.random question

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this: /usr/include/dmd/phobos/std/random.d(1188): Error: static variable initialized cannot be read at compile time

Re: Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:46:54 UTC, Meta wrote: This is not really doable right now in D. You can forward the function calls to a and b easily enough, but you can't inherit from more than one class. Once the multiple alias this patch gets merged you will be able to do this in D. On

Re: What wrong?

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: I'm not sure that it's not my fault. So I hope that will come by knowledgeable people and say Hey, buddy, your mistake is... :) OK. But if one does not come within three days :), duplicate topic in this section:

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 14:49:55 UTC, Martin Nowak wrote: On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Look at BitArray for an example

Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, How can I rewrite this code to the D? - #include string #include iostream class A { public: std::string a() { return std::string(foo); } }; class B { public: std::string b(){ return std::string(bar); } }; class C : public A, public B {};

Re: What wrong?

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE

Re: What wrong?

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of 42. :) But why is this receive breaks down? Report, please, about it (D)evepopers :) https://issues.dlang.org/

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Maybe you can somehow use bitfields. While what happened is something like this: - import std.stdio, std.bitmanip;

Re: Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:50:51 UTC, anonymous wrote: What's that supposed to do? Excuse me, what is not said. I thought that my wish will be obvious. On Friday, 1 May 2015 at 21:59:31 UTC, Ali Çehreli wrote: On 05/01/2015 02:41 PM, Dennis Ritchie wrote: immutable string[] s = [

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
Maybe someone will show a primitive packed array. I really can not imagine how to do it on D.

Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin }; immutable string[] strArr = [ fooTestMixin ]; writeln(mixin(`mixin(t.fooTestMixin)`));

Re: Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:26:20 UTC, anonymous wrote: On Friday, 1 May 2015 at 21:04:10 UTC, Dennis Ritchie wrote: hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin };

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 30 April 2015 at 11:20:55 UTC, bearophile wrote: Dennis Ritchie: There is an array of values to store each of which sufficiently 6 bits. As it is written down on the D? You can't do it directly in D. Someone has to write a packed array data structure to do it. Bye,

  1   2   3   >