Re: Most performant way of converting int to string

2015-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 22, 2015 at 08:54:35PM +0100, Daniel Kozák via Digitalmars-d-learn wrote: > V Tue, 22 Dec 2015 09:43:00 -0800 > "H. S. Teoh via Digitalmars-d-learn" > <digitalmars-d-learn@puremagic.com> napsáno: > > > On Tue, Dec 22, 2015 at 05:23:11PM +, An

Re: Most performant way of converting int to string

2015-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via Digitalmars-d-learn wrote: [...] > for({int i; i = 0;} i < num; i++) { > //string s = to!string(i); > Customer c = Customer(i, "Customer", "", i * 2); > string result =

Re: Must ranges have value semantics?

2015-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 15, 2015 at 05:36:52PM +, Chris Wright via Digitalmars-d-learn wrote: > I noticed that some methods in Phobos will have very different > behavior with forward ranges that have reference semantics and those > that have value semantics. > > Example: > > auto range =

Re: The best way to store a structure by reference

2015-11-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 27, 2015 at 11:38:28AM +0300, drug via Digitalmars-d-learn wrote: > I need to store a struct like a reference type. Now I use pointer for > this, is it the best D way? This pointer is private and access to it > is safe, but it's just unusual for me to see pointers in D code. There's

Re: Password Storage

2015-11-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 27, 2015 at 02:51:30PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 27 November 2015 at 07:46:33 UTC, H. S. Teoh wrote: > >1) The server stores password01 in the user database. > > I still wouldn't actually store this, hash it anyway and use that as > the new

Re: Password Storage

2015-11-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 27, 2015 at 12:17:32AM +, brian via Digitalmars-d-learn wrote: > I'm starting to build a small web-based application where I would like > to authenticate users, and hence need to store passwords. > > After reading this: >

Re: Password Storage

2015-11-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 27, 2015 at 03:09:38AM +, brian via Digitalmars-d-learn wrote: > On Friday, 27 November 2015 at 02:05:49 UTC, H. S. Teoh wrote: > ... > >At no time is the password ever sent over the network, encrypted or not. > > > >--T > So, I understand what you are trying to say, but I'm stuck

Re: AA deterministic order ?

2015-11-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 25, 2015 at 08:24:24PM +, user-6431 via Digitalmars-d-learn 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

Re: Building the Docs with checked out code downoads old dmd

2015-11-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 21, 2015 at 08:29:51PM +, yawniek via Digitalmars-d-learn wrote: > i'm trying to build the docs as per > http://wiki.dlang.org/Building_DMD#Building_the_Docs > > i have a working setup to build the latest dmd/druntime/phobos but > somehow the makefile tries to download an old dmd

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

2015-11-11 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 11, 2015 at 02:26:28PM +, Andrea Fontana via Digitalmars-d-learn wrote: > On Wednesday, 11 November 2015 at 13:32:00 UTC, perlancar wrote: > >While I am quite impressed with how easy I was able to write D, I am > >not so impressed with the performance. Using rdmd (build 20151103),

Re: Providing custom formatting without importing half of phobos.

2015-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 09, 2015 at 03:09:26PM +, rumbu via Digitalmars-d-learn wrote: > Let's say that I'm a library provider and I intend to offer a > completely new data type suitable for printing with format() or > writef(). > > According to this tutorial >

Re: Why can't function expecting immutable arg take mutable input?

2015-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 16, 2015 at 04:05:19PM +0530, Shriramana Sharma via Digitalmars-d-learn wrote: > Hello. I still haven't wrapped my mind around the const/immutable > thing yet and am still stuck in C/C++ mode. :-( > > A function that takes mutable arguments cannot be called with > immutable input at

Re: Builtin array and AA efficiency questions

2015-10-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 15, 2015 at 09:00:36PM +, Random D user via Digitalmars-d-learn wrote: > Thanks for thorough answer. > > On Thursday, 15 October 2015 at 18:46:22 UTC, H. S. Teoh wrote: [...] > >The only thing I can think of is to implement this manually, e.g., by > >wrapping your AA in a type

Re: Builtin array and AA efficiency questions

2015-10-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 15, 2015 at 04:47:35PM +, Random D user via Digitalmars-d-learn wrote: > So I was doing some optimizations and I came up with couple basic > questions... > > A) > What does assumeSafeAppend actually do? It adjusts the size of the allocated block in the GC so that subsequent

Re: Tree datatype

2015-10-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 14, 2015 at 03:00:51PM +, Tobias Pankrath via Digitalmars-d-learn wrote: > 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

Re: Ternary if and ~ does not work quite well

2015-10-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 12, 2015 at 05:19:38AM +, Andre via Digitalmars-d-learn wrote: > Hi, > > I am not sure, whether the output of following coding is correct: > > import std.stdio; > > void main() > { > writeln("foo "~ true ? "bar" : "baz"); > writeln("foo "~ false ? "bar" : "baz"); >

Re: Compile time and runtime grammars

2015-10-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 10, 2015 at 06:52:29PM +, DLangLearner via Digitalmars-d-learn wrote: > Only now I found that most of my confusions are with D's compile time > grammar or features. As an excuse, my confusions can be partially > attributed to the way D is presented: > > 1. There are confusing

Re: Why is the constructor of B called?

2015-09-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 23, 2015 at 03:25:04PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 09/23/2015 02:25 PM, tcak wrote: > >On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: > >>On Wednesday, 23 September 2015 at 21:08:37 UTC, tcak wrote: > >>>I wouldn't expect B's

Re: This is probably trivial or impossible Code Introspection...

2015-09-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 20, 2015 at 05:21:03AM +, WhatMeWorry via Digitalmars-d-learn wrote: [...] > Thanks. But now I have an even more fundamental problem. I keep > getting a FieldNameTuple is not defined. But I've clearly got the > import statement. I even copied the example from Phobos verbatim:

Re: bug? for(int i=0;i<1;) vs while(true)

2015-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 17, 2015 at 07:32:13PM +, ddos via Digitalmars-d-learn wrote: > http://pastebin.com/fknwgjtz > > i tried to call fibers in a loop forever, to multiplex some networking > client worker fibers and a listener fiber > it seems to work correctly with for(int i=0;i<1;) > > with

Re: Speeding up text file parser (BLAST tabular format)

2015-09-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 15, 2015 at 08:55:43AM +, Fredrik Boulund via Digitalmars-d-learn wrote: > On Monday, 14 September 2015 at 18:31:38 UTC, H. S. Teoh wrote: > >I tried implementing a crude version of this (see code below), and > >found that manually calling GC.collect() even as frequently as once >

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 14, 2015 at 02:34:41PM +, Fredrik Boulund via Digitalmars-d-learn wrote: > On Monday, 14 September 2015 at 14:18:58 UTC, John Colvin wrote: > >Range-based code like you are using leads to *huge* numbers of > >function calls to get anything done. The advantage of inlining is >

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 14, 2015 at 04:13:12PM +, Edwin van Leeuwen via Digitalmars-d-learn wrote: > On Monday, 14 September 2015 at 14:54:34 UTC, Fredrik Boulund wrote: > >[...] I tried using the built-in profiler in DMD on the D program but > >to no avail. I couldn't really make any sense of the output

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 14, 2015 at 08:07:45PM +, Kapps via Digitalmars-d-learn wrote: > On Monday, 14 September 2015 at 18:31:38 UTC, H. S. Teoh wrote: > >I decided to give the code a spin with `gdc -O3 -pg`. Turns out that > >the hotspot is in std.array.split, contrary to expectations. :-) > >Here are

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread H. S. Teoh via Digitalmars-d-learn
I decided to give the code a spin with `gdc -O3 -pg`. Turns out that the hotspot is in std.array.split, contrary to expectations. :-) Here are the first few lines of the gprof output: -snip- Each sample counts as 0.01 seconds. % cumulative self self total

Re: reading file byLine

2015-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 04, 2015 at 12:18:14AM +, Namal via Digitalmars-d-learn wrote: [...] > That being said, when do I have to import std.array and std.string? > Every time I use std.array? I can obviously use arrays and strings > without those libs. Arrays and strings are built into the language; but

Re: reading file byLine

2015-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 03, 2015 at 11:38:54PM +, Namal via Digitalmars-d-learn wrote: > On Thursday, 3 September 2015 at 23:31:27 UTC, Jordan Wilson wrote: > >On Thursday, 3 September 2015 at 23:28:37 UTC, Namal wrote: > >>On Thursday, 3 September 2015 at 23:25:52 UTC, Jordan Wilson wrote: > >>>And also:

Re: reading file byLine

2015-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 03, 2015 at 11:22:09PM +, Namal via Digitalmars-d-learn wrote: > >Sorry, I didn't notice the "convert all the elements in it to integer" > >part. > >I think I saw reference to the to! before...that is one way to convert. > > > >auto words = file.byLine() // you've all

Re: reading file byLine

2015-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 03, 2015 at 11:28:36PM +, Namal via Digitalmars-d-learn wrote: > On Thursday, 3 September 2015 at 23:25:52 UTC, Jordan Wilson wrote: > >And also: > >import std.algorithm > > > >Sorry, I should have taken the time to answer properly and fully. > > import std.file, std.stdio,

Re: Why ElementType!(char[3]) == dchar instead of char?

2015-09-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 01, 2015 at 07:40:24PM +0300, drug via Digitalmars-d-learn wrote: [...] > I'm just trying to automatically convert D types to hdf5 types so I > guess char[..] isn't obligatory some form of UTF-8 encoded text. Or I > should treat it so? In D, char[]/wchar[]/dchar[] are intended to be

Re: observation: D getting a bit complex

2015-08-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Aug 30, 2015 at 07:36:53AM +, BBasile via Digitalmars-d-learn wrote: On Sunday, 30 August 2015 at 02:42:30 UTC, Spacen Jasset wrote: immutable(ElementEncodingType!(ElementType!Range))[] buildPath(Range)(Range segments) if (isInputRange!Range isSomeString!(ElementType!Range));

Re: Ranges - Question about desing choices

2015-08-24 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 24, 2015 at 03:16:10PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: On Monday, 24 August 2015 at 15:09:14 UTC, Michal Minich wrote: What are the advantages of current design. One advantage of the current design is you can statically determine if something is an infinite

Re: iterating through a range, operating on last few elements at a time

2015-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 14, 2015 at 02:42:26AM +, Laeeth Isharc via Digitalmars-d-learn wrote: I have a range that is an array of structs. I would like to iterate through the range, calling a function with the prior k items in the range up to that point and storing the result of the function in a new

Re: Infinity loop with dates comparison

2015-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 11, 2015 at 07:56:00PM +, Suliman via Digitalmars-d-learn wrote: [...] Date startDate = Date.fromISOExtString(2014-08-01); Date currentDate = to!(Date)(Clock.currTime()-1.days); //because current day is not finished writeln(startDate); writeln(currentDate);

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 31, 2015 at 06:01:44PM +, Dicebot via Digitalmars-d-learn wrote: On Friday, 31 July 2015 at 17:21:40 UTC, Ali Çehreli wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea

Re: Weird behavior of this in a subclass, I think?

2015-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 16, 2015 at 12:18:30AM +, seashell86 via Digitalmars-d-learn wrote: So I've been mostly just toying around with D as it seems like it will end up being a strong language for game development both now and even moreso in the future. That being said, I'm perplexed by using this

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 07, 2015 at 07:54:18PM +, jmh530 via Digitalmars-d-learn wrote: I'm not sure I understand the safety of function pointers vs. the addresses of functions. The code below illustrates the issue. Function pointers and addresses of functions are the same thing. There is no difference

Re: Same process to different results?

2015-07-01 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 01, 2015 at 02:14:49PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/1/15 1:44 PM, Steven Schveighoffer wrote: Schizophrenia of Phobos. Phobos thinks a string is a range of dchar instead of a range of char. So what cycle, take, and array all output are dchar

Re: Best way to count character spaces.

2015-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 30, 2015 at 06:33:32PM +, Taylor Hillegeist via Digitalmars-d-learn wrote: So I am aware that Unicode is not simple... I have been working on a boxes like project http://boxes.thomasjensen.com/ it basically puts a pretty border around stdin characters. like so:

Re: aa.byKeyValue().sort!a.key b.key

2015-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 27, 2015 at 12:22:06PM +, Nicholas Wilson via Digitalmars-d-learn wrote: How do I iterate through an AA sorted by key? I am unable to .dup the aa.byKeyValue(). Because it is a range, not an array. To turn it into an array, write: aa.byKeyValue().array.sort!a.key

Re: shouldn't this code at least trigger a warning?

2015-04-29 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 29, 2015 at 06:37:44AM +, ketmar via Digitalmars-d-learn wrote: subj. the code: void main () { import std.stdio; char ch = '!'; switch (ch) { int n = 42; case '!': writeln(n, : wow!); break; default: } } i think that such

Re: Printing an std.container.Array

2015-04-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 16, 2015 at 07:55:52PM +, Bayan Rafeh via Digitalmars-d-learn wrote: Executing this code: import std.container.array; import std.stdio; int main() { writeln(Array!int([1, 2])); return 0; } outputs the following: Array!int(RefCounted!(Payload,

Re: writefln patterns with mismatching compile-time known number of arguments

2015-04-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Apr 12, 2015 at 02:33:03PM +, ketmar via Digitalmars-d-learn wrote: On Sun, 12 Apr 2015 14:18:21 +, JR wrote: But the compiler has all the pieces of information needed to see it's wrong, doesn't it? no, it doesn't. compiler doesn't know about `std.format.format` and it's

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 31, 2015 at 11:57:49AM +, w0rp via Digitalmars-d-learn wrote: Mutual tail call optimisation doesn't work in C++ either. Because it's not a language feature in C++ or D. It is not required by the standards of either language. It's an optimisation which compilers apply. I am

Re: struct variable initialized with void.

2015-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 31, 2015 at 03:23:11PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] 3) You are initializing a private member with default construction turned off. Here, Struct s; wouldn't compile because of the disabled default constructor, but you need to set it up anyway. So you do

Re: Contributing to Phobos Documentation

2015-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 21, 2015 at 05:48:40PM +, Craig Dillabaugh via Digitalmars-d-learn wrote: Motivated by this thread: http://forum.dlang.org/thread/measc3$qic$1...@digitalmars.com I was hoping to see if I could do some work on the Phobos documentation, but I am curious to know what the

Re: Text UI for D?

2015-03-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 20, 2015 at 10:29:44AM +, DLearner via Digitalmars-d-learn wrote: Does D have a recommended package for this - like (n)curses for C? Try Adam Ruppe's excellent terminal.d -- I use it for my own TUI programs, and it's pretty good.

Re: Documentation confusion

2015-03-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Mar 08, 2015 at 09:29:28PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: Hi, I just want to be sure that I'm not missing something, as I'm a bit confused: 1. The docs at http://dlang.org/phobos/ are not complete, right? Even not complete in that all runtime / phobos modules

Re: static void arrays under garbage control?

2015-02-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 25, 2015 at 08:20:37PM -0600, captaindet via Digitalmars-d-learn wrote: [...] struct Stuff2Do{ static ubyte[1024*1024] buffer4speed = void; // even if untyped at this point // more } [...] Tangential note: be careful with putting a large static array inside a struct.

Re: Float to string with more digits?

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 08:04:04PM +, Almighty Bob via Digitalmars-d-learn wrote: Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits. What about std.format.format(%.12f, myFloat)? Or, if you like:

Re: Deprecation process documented?

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 09:55:28AM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: [...] Regardless, when a symbol is either marked as scheduled for deprecation in the docs or outright deprecated, a date is usually put in the docs for when it will be moved to the next deprecation stage,

Re: Struct inheritance

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 06:22:05PM +, ketmar via Digitalmars-d-learn wrote: On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to

Re: Error: getenv cannot be interpreted at compile time

2015-02-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 17, 2015 at 07:17:41PM +, Paul via Digitalmars-d-learn wrote: I'd like to create a Terminal using terminal.d and make it available across several source files (as a global rather than having to pass it around) but when I define it like this in global scope: Terminal Screen =

Re: Error: getenv cannot be interpreted at compile time

2015-02-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 17, 2015 at 07:56:19PM +, Paul via Digitalmars-d-learn wrote: [...] I see, thanks once again :D I don't know why the environment variable isn't accessible at compilation (from a terminal) but that's OS business I guess rather than D related. Even if you *could* access it at

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 13, 2015 at 12:28:23PM +, bearophile via Digitalmars-d-learn wrote: Dominikus Dittes Scherkl: I would recommend to use something like this: /// returns the number of the highest set bit +1 in the given value /// or 0 if no bit is set size_t bitlen(T)(const(T) a) pure

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 13, 2015 at 07:54:32PM +, via Digitalmars-d-learn wrote: On Friday, 13 February 2015 at 15:14:44 UTC, H. S. Teoh wrote: Isn't it essentially floor(log_2(a)), mathematically speaking? Maybe that could be the basis of a better name? integer log2:

Re: Ncurses deprecated ~master issue

2015-02-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 10, 2015 at 09:05:06PM +, Meta via Digitalmars-d-learn wrote: On Tuesday, 10 February 2015 at 20:50:28 UTC, Paul wrote: [...] test.o: In function `_Dmain': test.d:(.text._Dmain+0x13): undefined reference to `_D8terminal8Terminal6__initZ' test.d:(.text._Dmain+0x3c): undefined

Re: internal compiler error with immutable

2015-02-07 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 07, 2015 at 02:35:13PM +, Danny via Digitalmars-d-learn wrote: [...] cut- gdc A.d cc1d: ../../src/gcc/d/dfrontend/statement.c:293: ErrorStatement::ErrorStatement(): Assertion `global.gaggedErrors || global.errors'

Re: Check if type is from specific template?

2015-01-29 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 29, 2015 at 12:58:46PM +, Tofu Ninja via Digitalmars-d-learn wrote: [...] Incidentally, while trying to see how its used I found that a lot of the links on the std.traits doc page do not work and have no documentation. [...] Please file bugs for these. We need to fix the docs.

Re: Array List object?

2015-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 27, 2015 at 07:18:22AM +, Gan via Digitalmars-d-learn wrote: [...] Okay now I'm very confused. When I have my program fully hidden behind another window, my ram usage goes up without going down. Which my program is partly visible it goes up a few mb then returns to the past

Re: Virtual functions and inheritance

2015-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 27, 2015 at 04:38:57AM +, David Monagle via Digitalmars-d-learn wrote: Hi guys, I'm a former C++ developer and really enjoying working with D now. I have a question that I hope some of you may be able to answer. class Parent { @property string typeName() { return

Re: Array List object?

2015-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 27, 2015 at 06:02:38AM +, Gan via Digitalmars-d-learn wrote: On Tuesday, 27 January 2015 at 06:00:50 UTC, Gan wrote: On Tuesday, 27 January 2015 at 05:32:09 UTC, Gan wrote: Hey I'm using normal arrays for my project: //Declaring the array SBTile[] tiles; //Initializing the

Re: Run only unittest, skip main

2015-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 24, 2015 at 06:15:29PM +, tcak via Digitalmars-d-learn wrote: Is there any way to run only unittest codes, and ignore main function? DMD is running both of them when I use -unittest. version(unittest) { void main() {} } else { void main() { /* real main code

Re: using the full range of ubyte with iota

2015-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 24, 2015 at 08:49:01PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: Maybe I'm just too stupid, but I cannot manage to call a simple function with all 256 possible values of ubyte with iote: int foo(ubyte c); auto myRange = iota(0,256).map!foo; [...] Try:

Re: Run only unittest, skip main

2015-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 24, 2015 at 07:02:35PM +, ketmar via Digitalmars-d-learn wrote: On Sat, 24 Jan 2015 10:52:26 -0800, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jan 24, 2015 at 06:15:29PM +, tcak via Digitalmars-d-learn wrote: Is there any way to run only unittest codes

Re: byKeyValue does not exist for associative arrays

2015-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 24, 2015 at 04:32:43PM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, January 24, 2015 12:05:10 Bayan Rafeh via Digitalmars-d-learn wrote: On Saturday, 24 January 2015 at 11:18:57 UTC, ketmar wrote: On Sat, 24 Jan 2015 11:17:03 +, Bayan Rafeh wrote:

Re: iota and BigInt

2015-01-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 22, 2015 at 05:12:17PM +, Russel Winder via Digitalmars-d-learn wrote: Using reduce for factorial, seems to require iota, not a bad things per se, with ulongs: reduce!a*b(1, iota(1, n + 1)) works fine. Now switch to BigInt: reduce!a*b(one, iota(one, n +

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 14, 2015 at 07:05:16PM +, Laeeth Isharc via Digitalmars-d-learn wrote: On Tuesday, 13 January 2015 at 17:41:53 UTC, Tobias Pankrath wrote: On Tuesday, 13 January 2015 at 17:19:42 UTC, Laeeth Isharc wrote: The GC is allowed to move structs around, as I undestand it. Under

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 14, 2015 at 07:43:17PM +, via Digitalmars-d-learn wrote: On Wednesday, 14 January 2015 at 19:36:44 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Moral of the story: don't have struct fields that point to the struct itself. This is almost always a bad idea. Structs have value

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 08, 2015 at 11:29:29AM +, Laeeth Isharc via Digitalmars-d-learn wrote: this conversation is so funny: well what's wrong with this . It's a keyword... Aa Ha ha ha ha , rol. Seriously, is it so complicated to use a D editor ? I mean with syntax color... Man afraid to ask

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 08, 2015 at 07:13:28PM +, Paulo Pinto via Digitalmars-d-learn wrote: On Thursday, 8 January 2015 at 17:42:23 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] Vim supports syntax highlighting. But I don't use it either -- I find it distracts from clarity of thought. I

Re: How to prevent sensitive information is displayed when the extension 'exe' is modified to 'txt' on windows?

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 07, 2015 at 08:36:19PM +, Baz via Digitalmars-d-learn wrote: On Wednesday, 7 January 2015 at 17:57:18 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] Note that these encryption/decryption schemes can only serve as deterrent to the casual user, they do not prevent

Re: Why do the same work about 'IndexOfAny' and 'indexOf' function?

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
Try this: http://dlang.org/phobos-prerelease/std_algorithm#.findAmong T -- MACINTOSH: Most Applications Crash, If Not, The Operating System Hangs

Re: How to prevent sensitive information is displayed when the extension 'exe' is modified to 'txt' on windows?

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 07, 2015 at 05:16:13PM +, FrankLike via Digitalmars-d-learn wrote: To hide the infos you can also (I've seen people say that you can use a packer) encrypt the strings and decode them at run-time (e.g base64, a simple XOR, etc) and use the import() idiom:

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 07, 2015 at 02:52:51PM +, Laeeth Isharc via Digitalmars-d-learn wrote: Another schoolboy question. Suppose I am constructing a tree (in this case it is an AST). In C I would have a pointer for the child to find the parent, and an array or linked list of pointers to find the

Re: Can pointers to values inside associative arrays become invalid?

2015-01-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 06, 2015 at 04:18:17PM +, Idan Arye via Digitalmars-d-learn wrote: I have an associative array, and I use the `in` operator to get a reference to a value inside it and store it in a pointer: int[string] aa; aa[myKey] = 42; int* myPointer = myKey in aa; Is it

Re: Can pointers to values inside associative arrays become invalid?

2015-01-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 06, 2015 at 05:39:50PM +, Idan Arye via Digitalmars-d-learn wrote: [...] I see... quite a shame there are no built-in data structures that provide forever-valid references to their members. Arrays can be reallocated, associative arrays can be rehased, and the stuff in

Re: Can the order in associative array change when keys are not midified?

2015-01-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 01, 2015 at 04:17:39PM +, Idan Arye via Digitalmars-d-learn wrote: [...] My use case is that I have a large AA where the values are numbers and the keys are strings, and I need to send it over network again and again. The values constantly change but the keys should remain the

Re: Problem with compilation( DMD compile run failed with exit code -6 )

2014-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 17, 2014 at 03:13:27PM +, Akzwar via Digitalmars-d-learn wrote: [...] Finally compilation crashes with exit code -6: dmd: class.c:859: virtual void ClassDeclaration::semantic(Scope*): Assertion `type-ty != Tclass || ((TypeClass *)type)-sym == this' failed. [...] This is an ICE

Re: core.bitop.bt not faster than ?

2014-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 17, 2014 at 04:08:40PM +, Trollgeir via Digitalmars-d-learn wrote: On Wednesday, 17 December 2014 at 14:58:13 UTC, Adam D. Ruppe wrote: On Wednesday, 17 December 2014 at 14:12:16 UTC, Trollgeir wrote: I'd expect the bt function to be up to 32 times faster as I thought it only

Re: Asssociative Array by Key-Value-Pair

2014-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 16, 2014 at 11:56:20AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/16/14 11:47 AM, Nordlöw wrote: On Tuesday, 16 December 2014 at 16:08:09 UTC, Steven Schveighoffer wrote: I can never ever see a reason to implement 2 different ways to traverse the elements,

Re: Asssociative Array by Key-Value-Pair

2014-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 15, 2014 at 02:27:52PM +, Nordlöw via Digitalmars-d-learn wrote: Is there a combined property of AAs that combine keys and values typically .pairs() or .byPairs() I need to sort the elements of an AA by value and then retrieved corresponding keys in the order

Re: Asssociative Array by Key-Value-Pair

2014-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 15, 2014 at 06:46:20PM +, bearophile via Digitalmars-d-learn wrote: H. S. Teoh: I implemented this before, but it got rejected because people insisted that it must return a range of Tuple, but Tuple is defined in Phobos and druntime can't have dependencies on Phobos. :-(

Re: All Unordered Pairs of Elements in a Range

2014-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 13, 2014 at 10:24:50PM +, Nordlöw via Digitalmars-d-learn wrote: Is there a Phobos method/range for selecting all pairs out of a range without caring about the ordering within each pair? Example: [1,2,3] = [(1,2), (2,3), (3,1)] Sounds like:

Re: Global array

2014-12-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 12, 2014 at 03:04:21PM +, Paul via Digitalmars-d-learn wrote: On Thursday, 11 December 2014 at 21:35:43 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Dec 11, 2014 at 08:56:00PM +, Paul via Digitalmars-d-learn wrote: Is there any merit (or folly!) in storing

Re: std.bitmanip - bitshift?

2014-12-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 12, 2014 at 11:13:38AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/12/14 8:39 AM, Trollgeir wrote: http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits

Re: std.bitmanip - bitshift?

2014-12-12 Thread H. S. Teoh via Digitalmars-d-learn
Here's my implementation of = and = for BitArray: https://github.com/D-Programming-Language/phobos/pull/2797 While working with the code, I found that there are a lot of areas that need improvement. If I have some time I'll file separate PR's for them. T -- VI = Visual Irritation

Re: O(1) popAny for associative array?

2014-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 11, 2014 at 06:27:06PM +, Andrew Klaassen via Digitalmars-d-learn wrote: In theory, it should be possible to do a popFront equivalent for a hash that has O(1) average complexity, so long as you don't care about order. I.e., give me any key from the hash, I don't care which

Re: O(1) popAny for associative array?

2014-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 11, 2014 at 10:36:02AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] auto mykey = myarray.byKey().front; myarray.remove(mykey); [...] Ah, I forgot that you need to check .empty on the range returned by byKey before accessing .front. Thanks to Ali for pointing

Re: Global array

2014-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 11, 2014 at 08:56:00PM +, Paul via Digitalmars-d-learn wrote: Is there any merit (or folly!) in storing a large array, that frequently needs to be accessed globally, within a class like so: public class classMap{ public static int[MAPSIZE][MAPSIZE] map; }

Allocating aligned memory blocks?

2014-12-11 Thread H. S. Teoh via Digitalmars-d-learn
Hi all, I'm working on a very large associative array implementation that stores most of the data on disk, and I need to allocate a number of cache areas for keeping hot disk pages in RAM. Is there a way to allocate GC memory blocks in D that are guaranteed to fall on OS page boundaries? Or

Re: Accented Characters and Counting Syllables

2014-12-07 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 07, 2014 at 02:30:13PM +, Nordlöw via Digitalmars-d-learn wrote: On Saturday, 6 December 2014 at 23:11:49 UTC, H. S. Teoh via Digitalmars-d-learn wrote: This is a Unicode issue. What you want is neither byCodeUnit nor byCodePoint, but byGrapheme. A grapheme is the Unicode

Re: Accented Characters and Counting Syllables

2014-12-06 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 06, 2014 at 10:37:17PM +, Nordlöw via Digitalmars-d-learn wrote: Given the fact that static assert(é.length == 2); I was surprised that static assert(é.byCodeUnit.length == 2); static assert(é.byCodePoint.length == 2); Isn't there a way to iterate over

Re: threading issues with D - C - Python

2014-12-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 04, 2014 at 10:11:53PM +, Michael via Digitalmars-d-learn wrote: On Thursday, 4 December 2014 at 03:22:05 UTC, Ellery Newcomer wrote: dustmite? Not sure what went wrong with dustmite, but every time I tried it it just started deleting all the files in the directory and

Re: Learning D for a non computer science background person : pre-requisite knowledge?

2014-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 02, 2014 at 04:38:33PM +, Mayuresh Kathe via Digitalmars-d-learn wrote: While I have been a programmer for close to 23 years, it's been mostly API level code cobbling work. Would like to learn D, but am a bit intimidated by the fact that I don't have much of a grasp over the

Re: Adding days to std.datetime.Date

2014-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 02, 2014 at 05:21:27PM +, via Digitalmars-d-learn wrote: On Thursday, 7 April 2011 at 19:10:40 UTC, Piotr Szturmaj wrote: Is it possible to add a particular number of days to a Date? I have number of days since 1 Jan 2000 and I want to convert it to Date: int days =

Re: Learning D for a non computer science background person : pre-requisite knowledge?

2014-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 02, 2014 at 05:46:04PM +, Mayuresh Kathe via Digitalmars-d-learn wrote: On Tuesday, 2 December 2014 at 17:33:18 UTC, Gary Willoughby wrote: On Tuesday, 2 December 2014 at 17:15:28 UTC, Mayuresh Kathe wrote: Okay, if that is the case, I'll dive into Mr. Alexandrescu's book as

Re: Adding days to std.datetime.Date

2014-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 02, 2014 at 06:49:54PM +, via Digitalmars-d-learn wrote: But still, why this method http://dlang.org/phobos/std_datetime.html#.Date.add only supports month or years while this one http://dlang.org/phobos/std_datetime.html#.Date.roll does ? But still, why this method

Re: Transform a sorted range to a range of ranges of equal elements

2014-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 01, 2014 at 06:37:13PM +, Tobias Pankrath via Digitalmars-d-learn wrote: Basically I need std.algorithm.uniq or std.algorithm.group, but instead of a single element or an element and a number I want ranges that each contain consecutive elements considered equal. Example:

Re: general questions on reference types versus value types...

2014-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 01, 2014 at 08:22:59PM +, Suliman via Digitalmars-d-learn wrote: Could anybody explain why there is opinion that stack is fast and the heap is slow. All of them are located in the same memory. So the access time should be equal. That may be true 15 years ago, it's not true

<    9   10   11   12   13   14   15   16   >