'!' and naming conventions

2014-06-18 Thread cym13 via Digitalmars-d-learn
Hello, I see a lot of functions and other stuff with a '!' in the name such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? In scheme, we use such a convention to warn that a function is not pure, but I don't see the point of using it that way in D as there are other way to express it.

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
EDIT: mis-formatted previous snippet import std.algorithm, std.stdio, std.range, std.conv; void main() { stdin .byLine .filter!(s = !s.empty s.front != '#’) // Filter with this lambda function .map!(s = s.to!double) // Map the strings to doubles .array //

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
On Monday, 6 April 2015 at 18:00:46 UTC, Szymon Gatner wrote: Why is that? The use case is to provide a set of convenience extension methods to a basic interface. Say, given: This is not the only use case, another (maybe even more common) use is to allow pipeline programming. Example from

Re: Replacement of std.stream

2015-06-30 Thread cym13 via Digitalmars-d-learn
On Sunday, 28 June 2015 at 05:04:48 UTC, DlangLearner wrote: I will convert a Java program into D. The original Java code is based on the class RandomeAccessFile which essentially defines a set of methods for read/write Int/Long/Float/String etc. The module std.stream seems to be a good fit

Re: Python's features, which requires D

2015-05-23 Thread cym13 via Digitalmars-d-learn
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 use. I'm waiting for new features from D: for new

Re: Python's features, which requires D

2015-05-23 Thread cym13 via Digitalmars-d-learn
(just noticed a weird typo trend with know/now %s/know/now/g)

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); The problem is that this allocates delegate,

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); To me the obvious way is to use a lambda,

Re: Appender at CTFE?

2015-08-21 Thread cym13 via Digitalmars-d-learn
On Friday, 21 August 2015 at 22:39:29 UTC, Nick Sabalausky wrote: Not at a pc, so can't test right now, but does Appender work at compile time? If not, does ~= still blow up CTFE memory usage like it used to? Any other best practice / trick for building strings in CTFE? I did two

Re: foreach multiple loop sugar

2015-08-18 Thread cym13 via Digitalmars-d-learn
On Tuesday, 18 August 2015 at 15:51:55 UTC, ixid wrote: Though sugar seems to be somewhat looked down upon I thought I'd suggest this- having seen the cartesianProduct function from std.algorithm in another thread I thought it would be an excellent piece of sugar in the language. It's not an

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:22:07 UTC, Ali Çehreli wrote: // HERE: // Error: function deneme.func @nogc function allocates //a closure with the GC @nogc auto func(uint[] arr, DelegateRef d) { return arr.map!(a = d.d(a)); } Aren't you making another delegate in the map by using

Re: Randomisation of array order

2015-08-02 Thread cym13 via Digitalmars-d-learn
On Sunday, 2 August 2015 at 09:24:12 UTC, Matt wrote: I was planning to use a dynamic array of indices to represent a deck of cards, and was wondering if there was any easy way to shuffle the arrays contents? I checked the library docs, but came to the conclusion that sorting arrays is a much

What is the order of resolution for super() calls?

2015-08-05 Thread cym13 via Digitalmars-d-learn
Hi, I just read https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ which describes how super works in python (tl;dr: it's completely different from C++, java or D's super but super cool to deal with multiple inheritance). For example, for the following inheritance tree:

Re: What is the order of resolution for super() calls?

2015-08-05 Thread cym13 via Digitalmars-d-learn
Forget it, I just remembered that we only do single inheritance, and I don't think the same problem occurs with interfaces. For reference, as the diagram was unreadable, I'll describe it here: class Adam ; class Eve ; class Abel:Adam,Eve ; class Cain:Adam,Eve ; class David:Abel,Cain ;

Re: Using rdmd to create shared object files

2015-08-05 Thread cym13 via Digitalmars-d-learn
On Sunday, 2 August 2015 at 19:04:15 UTC, Malte Kießling wrote: Hello, I am trying to use rdmd to create shared object files. The command that I am using is rdmd --build-only -shared -fPIC -defaultlib= foo.d This creates a file called foo - wich is not exactly what I expectd. However dmd

Re: Infinity loop with dates comparison

2015-08-11 Thread cym13 via Digitalmars-d-learn
On Tuesday, 11 August 2015 at 19:56:02 UTC, Suliman wrote: The code look very trivial, but I am getting infinity loop like: 2014-Aug-02 2014-Aug-02 2014-Aug-02 ... 2014-Aug-02 Date startDate = Date.fromISOExtString(2014-08-01); Date currentDate = to!(Date)(Clock.currTime()-1.days);

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
On Saturday, 15 August 2015 at 11:25:20 UTC, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot implicitly convert

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
On Saturday, 15 August 2015 at 11:34:01 UTC, cym13 wrote: On Saturday, 15 August 2015 at 11:25:20 UTC, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message:

Re: Removing elements from dynamic array

2015-08-09 Thread cym13 via Digitalmars-d-learn
On Sunday, 9 August 2015 at 13:22:02 UTC, Reflexive wrote: Hi I have seen that it is possible to remove an element from a associative array, but dont find any reference, including in D's specification, about any element removing in dynamic array. I can use loops for that, but isnt any way to

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread cym13 via Digitalmars-d-learn
On Thursday, 23 July 2015 at 11:15:46 UTC, Enjoys Math wrote: 1. Is the best way to hash a uint[] slice 2. How do you do it? IIRC, std.digest functions take ubyte[] as input, so to hash a uint[] I would do the following: void main(string[] args) { import std.conv;

Re: Feature for paranoids

2015-11-10 Thread cym13 via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 13:09:09 UTC, Fyodor Ustinov wrote: Hi! Is it possible when using the "-release" indicate that this one in/out/invariant/assert should not to be disabled? WBR, Fyodor. I don't quite get why you'd like to use -release if you are paranoid enough to be

Re: my first D program (and benchmark against perl)

2015-11-11 Thread cym13 via Digitalmars-d-learn
On Wednesday, 11 November 2015 at 16:02:07 UTC, H. S. Teoh wrote: If performance is a problem, my first reaction would be to try GDC or LDC. While there have been recent improvements in DMD code generation quality, it still has a ways to go to catch with GDC/LDC's optimizer. T My

Re: Multiple range enumeration

2015-11-10 Thread cym13 via Digitalmars-d-learn
On Wednesday, 11 November 2015 at 02:38:19 UTC, puming wrote: Hi, If I have multiple ranges, say: auto a = [1, 2, 3]; auto b = ["a", "b", "c"]; auto c = ["x", "y", "z"]; I'd like a composition range that enumerate all combinations of these ranges, having the same effect as a nested foreach

Re: Associative array with duplicated keys?

2015-11-06 Thread cym13 via Digitalmars-d-learn
On Thursday, 5 November 2015 at 13:08:20 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana wrote: Anyway: are duplicated keys on declaration allowed? They shouldn't be... Why? I'll admit it is something I've never even thought of using, but every

Re: Associative array with duplicated keys?

2015-11-06 Thread cym13 via Digitalmars-d-learn
On Friday, 6 November 2015 at 14:28:53 UTC, cym13 wrote: auto aa = ["a":10, "b", 42, "a":20]; This should readauto aa = ["a":10, "b":42, "a":20]; of course.

Re: conver BigInt to string

2015-11-06 Thread cym13 via Digitalmars-d-learn
On Friday, 6 November 2015 at 10:00:23 UTC, Namal wrote: On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint,

Re: Tree datatype

2015-10-14 Thread cym13 via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 14:42:31 UTC, Namal wrote: Hello, I don't remember exactly but I think when I first saw D code there was tree datatype implemented without pointers. Is it possible to make a tree struct without pointers? If it is a binary tree, sure: just put your elements

Re: Tree datatype

2015-10-14 Thread cym13 via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 18:07:25 UTC, Meta wrote: The answer is more or less no, unless you sort of fake it like in cym13's example. A tree is not possible without pointers due to its recursive nature. Even if it looks like the implementation doesn't use pointers, they're just hidden

What is the D way to map a binary file to a structure?

2015-08-29 Thread cym13 via Digitalmars-d-learn
Hi, Let's say I have a simple binary file whose structure is well-known. Here is an example which stores points: struct Point { long x; long y; long z; } struct BinFile { uintmagicNumber; // Some identifier ulong pointsNumber; Point[] points; // Array of

Re: What is the D way to map a binary file to a structure?

2015-08-29 Thread cym13 via Digitalmars-d-learn
On Saturday, 29 August 2015 at 13:56:10 UTC, drug wrote: Try, for example, MessagePack https://github.com/msgpack/msgpack-d.git Thanks, but it isn't answering the question at all. I'm not looking for a serialization method, I'm looking for the best way to read a binary file.

Re: What is the D way to map a binary file to a structure?

2015-08-29 Thread cym13 via Digitalmars-d-learn
On Saturday, 29 August 2015 at 14:52:51 UTC, drug wrote: 29.08.2015 17:17, cym13 пишет: On Saturday, 29 August 2015 at 13:56:10 UTC, drug wrote: Try, for example, MessagePack https://github.com/msgpack/msgpack-d.git Thanks, but it isn't answering the question at all. I'm not looking for a

Re: What is the D way to map a binary file to a structure?

2015-08-29 Thread cym13 via Digitalmars-d-learn
On Saturday, 29 August 2015 at 16:47:23 UTC, Laeeth Isharc wrote: Align(1) ? That should do it, thanks :)

Re: observation: D getting a bit complex

2015-08-30 Thread cym13 via Digitalmars-d-learn
On Sunday, 30 August 2015 at 09:55:02 UTC, Dominikus Dittes Scherkl wrote: And the constraints you need not read - unless you want to understand why your call to the function failed. C++ is just lacking without them. Having them avoids that you always have to handle ridiculous input within

Re: Ranges - Question about desing choices

2015-08-25 Thread cym13 via Digitalmars-d-learn
On Monday, 24 August 2015 at 17:59:00 UTC, Michal Minich wrote: Ok. What about this: there exactly the same 3 primitives as in D range, but popFront is requred to be called first, before calling front, or empty properties. Why current approach against this? Wouldn't that mean a null

Re: How to open a webpage in D?

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 22:21:20 UTC, Taylor Hillegeist wrote: I thought that perhaps spawing a process would work but execute("PATH TO HTML FILE",null,Config.none,size_t.max,dirName(exepath)); Didn't seem to work? any ideas? Use curl: void main(string[] args) { import std.stdio,

Re: Safe copy-paste using mixin

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) { return `string a = "` ~ a ~ `";` ~

Re: array function

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 13:17:30 UTC, cym13 wrote: On Monday, 31 August 2015 at 13:00:49 UTC, Namal wrote: Hey guys, since I am learning D arrays here, can you tell me the best way to remove an element at the end of an array or at some index i? import std.algorithm; T[] arr; arr =

Re: What is the D way to map a binary file to a structure?

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 01:01:32 UTC, mzf wrote: On Saturday, 29 August 2015 at 12:56:08 UTC, cym13 wrote: Hi, Let's say I have a simple binary file whose structure is well-known. Here is an example which stores points: struct Point { long x; long y; long z; } struct

Re: array function

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 13:00:49 UTC, Namal wrote: Hey guys, since I am learning D arrays here, can you tell me the best way to remove an element at the end of an array or at some index i? import std.algorithm; T[] arr; arr = arr.remove(index);

Re: Safe copy-paste using mixin

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 12:43:25 UTC, drug wrote: On 31.08.2015 15:28, Andrea Fontana wrote: On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like:

Re: reading file byLine

2015-09-02 Thread cym13 via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 15:04:10 UTC, cym13 wrote: On Wednesday, 2 September 2015 at 13:46:54 UTC, Namal wrote: Thx, cym. I have a question about a D strings though. In c++ I would just reuse the string buffer with the "=" how can I clear the string after i store a line in the buffer

Re: Unordered Element Pairs of a Range

2015-09-07 Thread cym13 via Digitalmars-d-learn
On Monday, 7 September 2015 at 09:06:05 UTC, Nordlöw wrote: Is there a range in Phobos for accessing all unordered combinations of a range as: foreach (const i, const a; r) { for (auto j = i + 1; j < r.length; ++j) { const b = r[j]; // Use a and b } } excluding

Re: reading file byLine

2015-09-06 Thread cym13 via Digitalmars-d-learn
On Sunday, 6 September 2015 at 21:01:09 UTC, Namal wrote: On Sunday, 6 September 2015 at 20:39:27 UTC, deed wrote: On Sunday, 6 September 2015 at 17:57:49 UTC, Namal wrote: Yeah, I just checked, it is 2.066, how can I install the new version on ubuntu with sudo apt-get? sudo apt-get

Re: reading file byLine

2015-09-06 Thread cym13 via Digitalmars-d-learn
On Sunday, 6 September 2015 at 21:18:28 UTC, Namal wrote: That should be it though... Could you try this minimal complete test? import std.stdio; import std.algorithm; void main(string[] args) { int[] arr = [1, 2, 4, 2, 3, 4, 1]; arr.sort.uniq.writeln; } // [1, 2, 3, 4] yes, it

Re: static array is no range?

2015-09-05 Thread cym13 via Digitalmars-d-learn
On Saturday, 5 September 2015 at 11:12:17 UTC, Sebastiaan Koppe wrote: ``` import std.algorithm; char[1024] buffer; buffer.find("LOCATION: "); // get error about how all the different versions of find don't match ``` ``` import std.algorithm; char[1024] buffer; buffer[0..$].find("LOCATION:

Re: What is "FilterResult" type?

2015-09-08 Thread cym13 via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 09:48:35 UTC, Bahman Movaqar wrote: From what I can gather the output of `std.algorithm.iteration : filter` is a `FilterResult` type. I need a bit of help dealing with this type: 1. Why this type is there in the first place instead of simply using the type of

Re: Can we get a video tutorial?

2015-09-01 Thread cym13 via Digitalmars-d-learn
On Tuesday, 1 September 2015 at 14:48:55 UTC, Stephen wrote: So I've been trying to install Dlang, VisualD, and Dub for the past day with little luck. I have DMD 1 and 2, and VisualD installed, but I can't get Dub working. Are you on linux or windows or...? Please, give a bit of context.

Re: reading file byLine

2015-09-02 Thread cym13 via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 13:01:31 UTC, Namal wrote: Hello, I want to read a file line by line and store each line in a string. I found this example with byLine and ranges. First of all, do I need the range lib at all to do this and if so what is the range of the end of the file?

Re: reading file byLine

2015-09-02 Thread cym13 via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 13:46:54 UTC, Namal wrote: Thx, cym. I have a question about a D strings though. In c++ I would just reuse the string buffer with the "=" how can I clear the string after i store a line in the buffer and do something with it. I also tried to append a line to

Re: RAII and Deterministic Destruction

2015-08-25 Thread cym13 via Digitalmars-d-learn
On Tuesday, 25 August 2015 at 22:35:57 UTC, Jim Hewes wrote: Although C++ can be ugly, one reason I keep going back to it rather then commit more time to reference-based languages like C# is because I like deterministic destruction so much. My question is whether D can REALLY handle this or

Re: What is "FilterResult" type?

2015-09-08 Thread cym13 via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 11:08:59 UTC, Bahman Movaqar wrote: However, I have made this a strict practice of mine to specify the full signature of my public API. I suppose, if I want to be pedantic, I have to realise the lazy value first and pass the resulting array out. Is this

Re: What is "FilterResult" type?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:06 UTC, Bahman Movaqar wrote: On Tuesday, 8 September 2015 at 18:45:33 UTC, Jonathan M Davis wrote: [...] @Jonathan, @cym13 and @Meta It's reasonable to use `auto`. However there are times when you need to pass the `auto` value to another function and

Re: What is "FilterResult" type?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 11:30:26 UTC, Bahman Movaqar wrote: For the lame example I gave, something similar occurred to me at first; but then I thought 4 `filter`s (assuming `all` is simply a `filter`) might be non-idiomatic as it might incur some performance penalty. As those are

Re: chaining chain Result and underlying object of chain

2015-09-14 Thread cym13 via Digitalmars-d-learn
On Monday, 14 September 2015 at 14:17:51 UTC, Laeeth Isharc wrote: chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead? Laeeth. std.algorithm.iteration.joiner?

Re: "if sting in string"

2015-09-16 Thread cym13 via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 12:55:13 UTC, smadus wrote: Hello Searching after hours, i give up and here is the question. ;) I will make a programm, this searching all txt files on the system or the path from user and searching a user tiped term in this file.

Re: Purity of std.conv.to!string

2015-09-26 Thread cym13 via Digitalmars-d-learn
On Saturday, 26 September 2015 at 17:08:00 UTC, Nordlöw wrote: Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:34:03 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 9 September 2015 at 20:17:44 UTC, cym13 wrote: This is subtly missing the main question: isn't C++-like memory management of D classes possible with Unique, RefCounted and Scoped? I understand the

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:05:06 UTC, ponce wrote: C++ only has a D struct equivalent so all destructors are called deterministically. It's the addition of classes that create the problems in D. C++ can also throw by value, something that D can't really do. C++ objects can be: -

What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is often mentioned along with the fact that classes use the GC. I know well the difference between structs and classes and don't want to talk about

Re: foreach automoatic counter?

2015-09-21 Thread cym13 via Digitalmars-d-learn
On Monday, 21 September 2015 at 22:24:22 UTC, French Football wrote: On Monday, 21 September 2015 at 19:23:38 UTC, cym13 wrote: On Monday, 21 September 2015 at 16:32:25 UTC, French Football wrote: [...] I had to look into phobos sources (/usr/include/dlang/dmd/std/containers/dlist.d) to

Re: foreach automoatic counter?

2015-09-21 Thread cym13 via Digitalmars-d-learn
On Monday, 21 September 2015 at 15:38:40 UTC, French Football wrote: Going through a book on coding in D, http://ddili.org/ders/d.en/foreach.html , I find the following very useful feature: When two names are specified in the names section [with a plain array], they represent an automatic

Re: Why are static arrays not ranges?

2015-09-21 Thread cym13 via Digitalmars-d-learn
On Monday, 21 September 2015 at 20:33:10 UTC, Jack Stouffer wrote: import std.range; void main() { int[6] a = [1, 2, 3, 4, 5, 6]; pragma(msg, isInputRange!(typeof(a))); pragma(msg, isForwardRange!(typeof(a))); pragma(msg, isRandomAccessRange!(typeof(a))); } $ dmd -run test.d

Re: foreach automoatic counter?

2015-09-21 Thread cym13 via Digitalmars-d-learn
On Monday, 21 September 2015 at 16:32:25 UTC, French Football wrote: On Monday, 21 September 2015 at 15:54:06 UTC, Justin Whear wrote: On Monday, 21 September 2015 at 15:58:12 UTC, cym13 wrote: Thankyou! .enumerate lets me iterate over a container with a counter. --Related tangential

Re: Comparison operator overloading

2015-12-06 Thread cym13 via Digitalmars-d-learn
On Sunday, 6 December 2015 at 14:41:01 UTC, Márcio Martins wrote: I am writing a generic numerical array struct, and I can't find a way to do element-wise comparison operators. What I had envisioned was something like the following, assuming a, b, c and m are array-like, and all operations

Re: Why does sum not work in static arrays?

2015-12-06 Thread cym13 via Digitalmars-d-learn
On Sunday, 6 December 2015 at 12:23:05 UTC, Tim K. wrote: Hi! I have the following code: int main(string[] argv) { import std.algorithm: sum; import std.stdio: writeln; uint[3] a1 = [1, 2, 3]; uint[] a2; for (int i = 1; i <= 3; ++i)

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:23:00 UTC, Tim K. wrote: On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: Is there a convenience function that allows me to remove an/all object(s) with a certain value from an array or do I need to write one myself? Here are some elements of

Re: functional way doing array stuff/ lambda functions

2015-12-13 Thread cym13 via Digitalmars-d-learn
On Sunday, 13 December 2015 at 03:08:33 UTC, Namal wrote: On Saturday, 12 December 2015 at 23:50:55 UTC, Xinok wrote: [...] I tried this, it compiles, but crashes when I try to run it: object.Exception@/usr/include/dmd/phobos/std/algorithm/iteration.d(2481): Enforcement failed

Re: D programming video tutorial

2015-12-13 Thread cym13 via Digitalmars-d-learn
On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D

Re: Why `i` not working on foreach loop if it have byLine option

2015-12-17 Thread cym13 via Digitalmars-d-learn
On Thursday, 17 December 2015 at 14:09:57 UTC, Suliman wrote: Next code produce error: foreach(i, line;fileContent.byLine) Error: cannot infer argument types, expected 1 argument, not 2 Why it's do not work? Because byLine doesn't return an array, use std.range.enumerate :

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread cym13 via Digitalmars-d-learn
On Sunday, 13 December 2015 at 00:36:29 UTC, Namal wrote: On Sunday, 13 December 2015 at 00:02:11 UTC, cym13 wrote: Now that I think about it, it's true that it would make no sense whatsoever to return a range as reduce is typically used to return a single value... At least it makes perfect

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread cym13 via Digitalmars-d-learn
On Saturday, 12 December 2015 at 23:10:21 UTC, Namal wrote: Hello guys, I am still uncertain how to do it right when it comes to lambda functions. If you are looking for the functionnal way I'd advise that you start by looking up three functions in a language-agnostic way: filter, map and

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread cym13 via Digitalmars-d-learn
On Saturday, 12 December 2015 at 23:50:55 UTC, Xinok wrote: On Saturday, 12 December 2015 at 23:36:43 UTC, cym13 wrote: ... So, in your example: int product(const ref int[] arr) { import std.array: array; import std.algorithm: reduce; arr = arr.reduce!((p, i) => p*i).array; }

Re: functional way doing array stuff/ lambda functions

2015-12-12 Thread cym13 via Digitalmars-d-learn
On Saturday, 12 December 2015 at 23:59:01 UTC, cym13 wrote: On Saturday, 12 December 2015 at 23:50:55 UTC, Xinok wrote: On Saturday, 12 December 2015 at 23:36:43 UTC, cym13 wrote: ... So, in your example: int product(const ref int[] arr) { import std.array: array; import

Re: Are there any D scripting engines for use with D?

2016-01-04 Thread cym13 via Digitalmars-d-learn
On Monday, 4 January 2016 at 18:40:03 UTC, Jason Jeffory wrote: We have many scripting engines available for use in D more or less(lua, python, etc...). Is there a D scripting engine that can be easily integrated into a D project? A sort of "exec()". Something that works at compile time and

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:03:13 UTC, Shriramana Sharma wrote: Shriramana Sharma wrote: Why is it impossible for a Regex object to be `immutable`? I find that I can't declare it as `const` either... This is most curious! I think it's because regex() only compiles the regex at

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma wrote: Aw come on. The immutability of the variable is *after* it has been created at runtime. Sure, but still... > you'll find that using ctRegex() instead will allow you to declare it immutable for example. I didn't look at

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:56:35 UTC, cym13 wrote: On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma wrote: Aw come on. The immutability of the variable is *after* it has been created at runtime. Sure, but still... > you'll find that using ctRegex() instead will allow

Re: String interpolation

2016-01-06 Thread cym13 via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 23:30:22 UTC, Guillaume Piolat wrote: Is there a fancy way to have some kind of string interpolation in D? Other than std.format.format that is?

Re: UFCS vs auto-completion support

2016-01-09 Thread cym13 via Digitalmars-d-learn
On Saturday, 9 January 2016 at 15:50:33 UTC, Jay Norwood wrote: I'm reading Jack Stouffer's documentation: http://jackstouffer.com/blog/nd_slice.html considering the UFCS example below and how it would impact auto-completion support. auto slice = sliced(iota(1000), 5, 5, 40); auto slice =

Re: Scope of D packages

2015-12-18 Thread cym13 via Digitalmars-d-learn
On Saturday, 19 December 2015 at 00:52:40 UTC, Jakob Jenkov wrote: To be exact it doesn't need the sources, it needs the function signatures and type definitions so the equivalent of C header files. If you don't want to share the full sources with your library you can generate those header

Re: Scope of D packages

2015-12-18 Thread cym13 via Digitalmars-d-learn
On Saturday, 19 December 2015 at 00:09:16 UTC, Basile B. wrote: On Friday, 18 December 2015 at 23:20:34 UTC, Jakob Jenkov wrote: I'm coming from Java where "packages" are not that much more than directories. Each class can be exposed or hidden inside a package etc. In Java it is common that

Re: Most performant way of converting int to string

2015-12-22 Thread cym13 via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my

Re: Most performant way of converting int to string

2015-12-22 Thread cym13 via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:52:52 UTC, Andrew Chapman wrote: On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: I wonder if the slowdown is caused by GC collection cycles (because calling to!string will allocate, and here you're making a very large number of small

Re: Creating D bindings for a C library

2015-11-24 Thread cym13 via Digitalmars-d-learn
On Tuesday, 24 November 2015 at 23:22:24 UTC, Joseph Rushton Wakeling wrote: On Tuesday, 24 November 2015 at 23:14:14 UTC, Joseph Rushton Wakeling wrote: I'm considering creating some D bindings for a C library. I should probably clarify that I know what to do assuming I have to write all

Re: AA deterministic order ?

2015-11-25 Thread cym13 via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 20:24:25 UTC, user-6431 wrote: I know that AA items order does not follow the additions but is the order deterministic ? For example for a given set of items, will they always be ordered in the same way ? (I mean whatever is the way I append them to the AA).

Re: AA deterministic order ?

2015-11-25 Thread cym13 via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 20:24:25 UTC, user-6431 wrote: I know that AA items order does not follow the additions but is the order deterministic ? For example for a given set of items, will they always be ordered in the same way ? (I mean whatever is the way I append them to the AA).

Re: short programme from "Programming in D" by Ali Cehreli.

2016-06-14 Thread cym13 via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 09:39:05 UTC, Nick B wrote: On Tuesday, 14 June 2016 at 09:28:18 UTC, cym13 wrote: On Tuesday, 14 June 2016 at 09:17:35 UTC, Nick B wrote: Hi, Can anyone assist me with the short D programme. It is taken straight from "Programming in D" by Ali Cehreli. The code

Re: short programme from "Programming in D" by Ali Cehreli.

2016-06-14 Thread cym13 via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 09:17:35 UTC, Nick B wrote: Hi, Can anyone assist me with the short D programme. It is taken straight from "Programming in D" by Ali Cehreli. The code below is the solution, on page 684. The Exercise is on Page 27, item 2 half way down the page. [...]

Re: Parse File at compile time, but not embedded

2016-06-14 Thread cym13 via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 04:17:05 UTC, Pie? wrote: Ok, I will assume it will be able to be removed for release. It is an easy check(just search if binary contains file info). I'm sure an easy fix could be to write 0's over the data in the binary if necessary. Binaries aren't magical

Re: Searching for a T in a T[]

2016-06-22 Thread cym13 via Digitalmars-d-learn
On Wednesday, 22 June 2016 at 08:04:34 UTC, Nordlöw wrote: Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings. I don't see why canFind isn't

Re: Initialise dynamic array in array of structures

2016-06-22 Thread cym13 via Digitalmars-d-learn
On Wednesday, 22 June 2016 at 08:06:26 UTC, ketmar wrote: On Wednesday, 22 June 2016 at 06:43:12 UTC, Paul wrote: Why is initialisation via {} bad (in simple terms please :D)? first, it is buggy. i.e. it doesn't always call postblit[1]. second, it's syntax is the same as the syntax of

Re: std.array : appender woes

2016-06-16 Thread cym13 via Digitalmars-d-learn
On Thursday, 16 June 2016 at 07:47:03 UTC, abad wrote: import std.array : appender; import std.stdio : writeln; void main() { auto app = appender!(char[]); app.put('x'); auto foo = app.data; app.clear; // done, start a new array app.put('y'); writeln(foo); } This prints

Re: Initialise dynamic array in array of structures

2016-06-21 Thread cym13 via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 19:15:56 UTC, Paul wrote: Given these structures and declaration: struct CoordList{ int x, y; } struct Part{ int x, y; CoordList[] coords; int nextNode, prevNode; string nextEnter, prevEnter; } Part[10] trackTemplates; Can

Re: Doubt - Static multidimension arrays

2016-01-18 Thread cym13 via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 02:47:04 UTC, albert wrote: Hello, I was looking over http://dlang.org/spec/arrays.html#rectangular-arrays: And I've found that D multidimensional arrays are Rectangular, so it's impossible to create non-rectangular multidimensional static array like:

Re: Error: module ctype is in file 'std/ctype.d' which cannot be read - when running dmd

2016-06-24 Thread cym13 via Digitalmars-d-learn
On Friday, 24 June 2016 at 21:01:11 UTC, Roman wrote: I should probably add that only importing std.ctype causes the error. I have a bunch of other imports: import std.stdio, std.string, std.algorithm, std.conv, std.ctype, std.regex, std.range; If I remove std.ctype, it compiles just

Re: executeShell doesn't work but system does

2016-06-26 Thread cym13 via Digitalmars-d-learn
On Sunday, 26 June 2016 at 17:56:08 UTC, Satoshi wrote: On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote: system("cls") works but executeShell doesn't. system is depreciated. What's going on? The docs say that it creates a new process. I simply want to clear the console! I

Re: print function

2016-02-04 Thread cym13 via Digitalmars-d-learn
On Thursday, 4 February 2016 at 10:18:35 UTC, ixid wrote: Do you think your knowledge and experience is a good model for how a new user who hasn't done much if any programming before would approach this? A design choice had to be made and made it was. Adding another function now (or worse,

Re: algorithm's .filter!() by range key

2016-02-09 Thread cym13 via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 20:40:44 UTC, Charles wrote: This seems to be true of any range function really... is there a way to access the key within my range? Example of what I want to do: auto x = [1,2,3,4,5]; x.filter( x_key % 2 == 1 ).sum(); // sum odd elements in array

Re: Automatic range creation for class or struct?

2016-02-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 10 February 2016 at 00:05:36 UTC, Peka wrote: Hi! I have class (or struct) which realises .length() and .opIndex(size_t) methods. It is possible to create from this class some sort of range using template from std? (I mean that internal counter, .popFront(), .empty() etc

Re: Automatic range creation for class or struct?

2016-02-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 10 February 2016 at 00:27:54 UTC, Peka wrote: I don't think anything like that exists in phobos I need definitive answer. I need a precise answer. (sorry, google translator :з) "Definitive" is good, maybe even better in the context. I should have been clearer, sorry. When I

  1   2   3   >