Re: What's the current phobos way to define generic data sources and sinks?

2014-04-17 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 18, 2014 at 01:30:00AM +, Hannes Steffenhagen via Digitalmars-d-learn wrote: I've never said anything about inheriting from InputRange, just that I'd take an InputRange as a parameter. Anyway I changed my signature to Result parse(T)(T lines) if(isInputRange!T

Re: Implicit static-dynamic arr and modifying

2014-05-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 06, 2014 at 01:06:14AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: On Mon, 05 May 2014 22:16:58 -0400 Nick Sabalausky via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 5/5/2014 10:11 PM, Nick Sabalausky wrote: Is this kinds stuff a sane thing to

Re: [Rosettacode] D code line length limit

2014-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 07, 2014 at 01:25:52PM +, bearophile via Digitalmars-d-learn wrote: So far in Rosettacode D entries I've kept a line length limit of 72 or 73 chars. But now a little larger monitors are common, D UFCS chains are common, and we also have longer function signatures with pure

Re: Implicit static-dynamic arr and modifying

2014-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 07, 2014 at 06:31:15PM +, Rene Zwanenburg via Digitalmars-d-learn wrote: On Wednesday, 7 May 2014 at 15:41:19 UTC, Nick Sabalausky wrote: On 5/6/2014 6:46 PM, Rene Zwanenburg wrote: [...] struct S { @safe: string str; this(string data) { import

Re: [Rosettacode] D code line length limit

2014-05-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 08, 2014 at 01:59:58AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: On Thu, 08 May 2014 07:29:08 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Jonathan M Davis: ultimately, this sort of thing pretty much always ends up being

Re: [Rosettacode] D code line length limit

2014-05-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 08, 2014 at 02:50:54PM +, bearophile via Digitalmars-d-learn wrote: H. S. Teoh: FWIW, for very long function signatures I write it this way: const(T)[] myVeryLongFunction(T)(const(T)[] arr, intx,

Re: [Rosettacode] D code line length limit

2014-05-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 08, 2014 at 03:13:48PM +, Dicebot via Digitalmars-d-learn wrote: On Thursday, 8 May 2014 at 14:34:27 UTC, H. S. Teoh via Digitalmars-d-learn wrote: FWIW, for very long function signatures I write it this way: const(T)[] myVeryLongFunction(T)(const(T)[] arr

Re: throws Exception in method

2014-05-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 08, 2014 at 03:19:04PM +, amehat via Digitalmars-d-learn wrote: On Thursday, 8 May 2014 at 14:02:06 UTC, monarch_dodra wrote: [...] Keep in mind that D also has the concept of Error. Both Exception and Error derive from Throwable. nothrow only means the function will not

Re: enums

2014-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 30, 2014 at 07:17:15PM +0200, Philippe Sigaud via Digitalmars-d-learn wrote: In D enum can be used to define manifest constants. This means constants known at compile time. In practice for a double there isn't a lot of difference. In general you can't take the address of a

Re: dmd segfaults

2014-05-31 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 31, 2014 at 04:50:11PM +, matovitch via Digitalmars-d-learn wrote: Hi ! Does anybody knows why dmd segfaults on this code ? Should I report this as a bug ? [...] Compiler segfaults should always be reported. No matter how wrong the code may be, it is never right for the

Re: Fighting compiler - experienced programmer but D novice

2014-06-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 03, 2014 at 03:17:09AM +, Charles Parker via Digitalmars-d-learn wrote: ./graph_structures.d(124): Error: class graph_structures.node(D, E) is used as a type I have no idea what this means:( It usually means you tried to use an uninstantiated template as a type. [...]

Re: Interesting bug with std.random.uniform and dchar

2014-06-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 08, 2014 at 11:17:41AM +0200, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 08/06/14 11:02, monarch_dodra via Digitalmars-d-learn wrote: Why would we ban uniform!T from accepting dchar? I see no reason for that. Let's just fix the bug by tweaking the internal check.

Re: Cannot alias null

2014-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 12, 2014 at 03:26:13PM -0500, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; [...] 'null' is a value, not a type. Try: alias blah = typeof(null); T -- If it's green, it's biology, If it stinks, it's chemistry, If it has numbers

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

2014-06-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 13, 2014 at 08:14:11PM +0200, Andre via Digitalmars-d-learn wrote: Hi, I have a template class List which should provide generic list functionality. In my use case, using a class instead a struct is more comfortable. Following unittest fails, although the forward range

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

2014-06-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 13, 2014 at 10:02:49PM +, monarch_dodra via Digitalmars-d-learn wrote: [...] That said, you can use one of D's most powerful formating abilities: Range formating: writefln(%-(%s\n%), stdin.byLine()); And BOOM. Does what you want. I freaking love range formatting. More info

Re: what is going on with cgcs.c:351?

2014-06-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 15, 2014 at 04:44:06AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: I've bumped up against this cryptic error from time to time. I can't really pin it down to a simple self contained example as it tends to come up when I try to have template-heavy modules interact and there

Re: String cast error

2014-06-18 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 19, 2014 at 12:31:51AM +, SomeRiz via Digitalmars-d-learn wrote: Hi Justin thank you. I'm using executeShell(a); Output: ProcessOutput(0, SerialNumber\r\r\n92716002 \r\r\n\r\r\n) How do I delete ProcessOutPut, 0, SerialNumber, \r,\n text? I want to see

Re: how to store a range transformed by a range function?

2014-06-19 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 19, 2014 at 08:02:39PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: [...] For example, lets say I had a couple of managed arrays of doubles, and I had some computational path that, at some point, took these two ranges and zipped them before passing them along. At that node

Re: Contributing to D language

2014-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 23, 2014 at 04:43:30PM +, Mike via Digitalmars-d-learn wrote: I wish I could help with the development of D (either the compiler or std library). Is there a TODO list kept somewhere? Neither Phobos nor DMD have an `issues` page on Github.. [...] http://issues.dlang.org/ See

Re: Using attributes inside template instantiation

2014-06-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 25, 2014 at 05:10:06PM +, Chris Nicholson-Sauls via Digitalmars-d-learn wrote: UDA's are compile-time metadata associated with a specific declaration. So in something like: @foo int x; The @foo is attached to x, but is not part of the type. The term attribute is a bit

Re: close program by code

2014-06-26 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 26, 2014 at 01:23:17PM +, Chris Nicholson-Sauls via Digitalmars-d-learn wrote: On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote: They won't. Same for module destructors. If you need those to work, another option is to throw some custom Exception type which

Re: Enum type deduction inside templates is not working

2014-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 27, 2014 at 06:04:18AM +, Uranuz via Digitalmars-d-learn wrote: Compiler can't deduce type for template struct Pair when using it with enum argument. There is an example import std.stdio; enum Category { first, second, third }; struct Pair(F, S) { F first;

Re: Regex problem

2014-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 27, 2014 at 03:59:47PM +, seany via Digitalmars-d-learn wrote: [...] core.exception.AssertError@std.regex(5587): Assertion failure ./niarbyl(_d_assertm+0x26) [0x4e6c26] ./niarbyl() [0x4f45be] ./niarbyl(pure nothrow @property @trusted immutable(char)[]

Re: Can't modify this

2014-06-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: This doesn't work: class Foo { this() { this = new Foo; } } Error: Cannot modify 'this' However you can do this: class Foo { this() { auto p = this; *p = new Foo(); }

Re: How to forward format specifiers ?

2014-06-29 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 29, 2014 at 06:08:24PM +0200, Element 126 via Digitalmars-d-learn wrote: [...] I have used formattedWrite for months without noticing formatValue, even though it was on the wiki. Maybe I should add an example to the documentation of std.format. formatValue is present but without

Re: Can't modify this

2014-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 28, 2014 at 06:39:33PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: On 6/28/14, 6:21 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: This doesn't work: class Foo

Re: Thread-safety and lazy-initialization of libraries

2014-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 30, 2014 at 11:36:21PM +0200, Mike Wey via Digitalmars-d-learn wrote: On 06/30/2014 11:05 PM, bearophile wrote: Sergey Protko: libmpg123 has mpg123_init and mpg123_exit functions, which are not thread-safe, so we should to call them only once per process. Most of useful

Re: overloading InExpression

2014-07-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 02, 2014 at 02:35:54PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote: struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }

Re: CTFE bug or enhancement?

2014-07-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 03, 2014 at 02:09:09AM +, safety0ff via Digitalmars-d-learn wrote: On Thursday, 3 July 2014 at 02:02:19 UTC, safety0ff wrote: On Thursday, 3 July 2014 at 01:55:14 UTC, safety0ff wrote: Actually, this is an enhancement because adding: enum b = blah Makes them fail. :( The

Re: immutable/mutable aliasing

2014-07-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 03, 2014 at 09:06:11PM +, Jet via Digitalmars-d-learn wrote: There, how to distinguish between const and immutable? thank you~:) /** Const types are like immutable types, except that const forms a read-only view of data. Other aliases to that same data may change it at any

Re: std.algorithm.sort error with default predicate

2014-07-07 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 07, 2014 at 08:35:53PM +, anonymous via Digitalmars-d-learn wrote: [...] Looks like a bad bug: void main() { uint[] a = [0x22_DF_FF_FF]; uint[] b = [0xA2_DF_FF_FF]; assert(!(a b b a)); /* fails */ } This looks pretty serious. Please file a bug:

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-07 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 07, 2014 at 11:47:25PM +, Aerolite via Digitalmars-d-learn wrote: [...] So, if you would be so kind, give me a bullet list of the aspects of D you believe to be good, awesome, bad, and/or ugly. If you have the time, some code examples wouldn't go amiss either! Try not to go

Re: Tuple and tie?

2014-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 08, 2014 at 07:02:17PM +, NCrashed via Digitalmars-d-learn wrote: [...] auto tie(StoreElements...)(ref StoreElements stores) [...] Here's my take on it, that doesn't need to use pointers: import std.typecons; template TypesOf(T...) {

Re: Tuple and tie?

2014-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 08, 2014 at 07:46:14PM +, anonymous via Digitalmars-d-learn wrote: On Tuesday, 8 July 2014 at 19:40:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: template TypesOf(T...) { static if (T.length == 1) alias TypesOf = typeof(T[0

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 09, 2014 at 07:51:24AM +0200, Philippe Sigaud via Digitalmars-d-learn wrote: On Tue, Jul 8, 2014 at 7:50 AM, H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote quite a wall of text Wow, what to add to that? Maybe you scared other from participating ;-) I

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 09, 2014 at 04:24:38PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: On Wednesday, 9 July 2014 at 14:51:41 UTC, Meta wrote: One of the uglier things in D is also a long-standing problem with C and C++, in that comparison of signed and unsigned values is allowed.

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 09, 2014 at 05:43:15PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: On Wednesday, 9 July 2014 at 17:13:21 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [..] Yeah, I don't see what's the problem with comparing signed and unsigned values, as long as the result

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 09, 2014 at 11:29:06AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Jul 09, 2014 at 05:43:15PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: On Wednesday, 9 July 2014 at 17:13:21 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] Often

Re: get number of items in DList

2014-07-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: On 7/11/14, 4:46 AM, bearophile wrote: pgtkda: How can i get the number of items which are currently hold in a DList? Try (walkLength is from std.range): mydList[].walkLength Bye, bearophile

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 13, 2014 at 02:35:11AM +, dysmondad via Digitalmars-d-learn wrote: [...] So, what is the generally accepted way include unit testing? TDD is all the rage these days and I though I would try my hand at it as well as D. Just include unittest blocks in your program and compile

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 13, 2014 at 02:39:00AM +, dysmondad via Digitalmars-d-learn wrote: On Saturday, 12 July 2014 at 05:23:29 UTC, Ali Çehreli wrote: On 07/11/2014 10:08 PM, dysmondad wrote: class Velocity { [...] ref Velocity opOpAssign(string op) ( in float multiplier )

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 12, 2014 at 09:30:44PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jul 12, 2014 at 09:20:06PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] The twist here is that the OP's function returned 'this' by reference. Changing that not only not have any effect

Re: DStyle: Braces on same line

2014-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 13, 2014 at 11:32:23AM +0200, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 12/07/14 21:01, Danyal Zia via Digitalmars-d-learn wrote: I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I

Re: syntax for calling to with a getter as source argument

2014-07-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 14, 2014 at 09:12:30PM +, Klb via Digitalmars-d-learn wrote: hello what is the right syntax for this: import std.stdio, std.conv; void main(string args[]) { ubyte[3] src = [0, 1, 2]; string trg = ;

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-14 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 15, 2014 at 02:49:55AM +, WhatMeWorry via Digitalmars-d-learn wrote: Sorry if this is an incredibly naive question. I prefer to pragmatically pause my programs periodically so that I can peruse output statements. Ideally, I'd like to continue by just hitting any old key. My

Re: Regex match in for loop

2014-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 15, 2014 at 08:18:55PM +, seany via Digitalmars-d-learn wrote: Consider this: import std.stdio, std.regex, std.array, std.algorithms ; void main(string args[]) { string[] greetings = [hello, hallo, hoi, salut]; regex r = regex(hello, g); for(short i = 0; i

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 16, 2014 at 06:07:32PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: Not a direct answer, but the way I'd do this is to just use composition: class Foo { YourStruct _this; alias _this this; } boom, it'd work pretty well just like that... +1, simple answer to

Re: Generating Phobos Doc

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 05:54:21PM +, Nordlöw via Digitalmars-d-learn wrote: How do I generate the Phobos docs? My try make -f posix.mak html fails as make: *** No rule to make target `../web/phobos-prerelease/index.html', needed by `html'. Stop. You need to checkout the

Re: Binary IO

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 08:35:24PM +, seany via Digitalmars-d-learn wrote: Hello, What are the methods of unformatted binary IO in d? File.write seems to use formatted ASCII . I would like to write a binary file that I cna read in fortan. Similarly, I would like to write a file in

Re: Binary IO

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 09:01:35PM +, seany via Digitalmars-d-learn wrote: Data is a built in type? what includefile do I need? It can be any type you want, it was just an example. T -- Chance favours the prepared mind. -- Louis Pasteur

Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 17, 2014 at 11:06:30PM +, bearophile via Digitalmars-d-learn wrote: Justin Whear: What benefits would accrue from adding this? Static verification that a structure implements the specified concepts? Not just that, but also the other way around: static verification that a

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 12:55:34AM +0200, Daniel Gibson via Digitalmars-d-learn wrote: Hi, I have a variadic templated function and want to call a C varargs function. I want to be able to pass static arrays, which D2 passes by value and C by reference, so I'd like to automagically translate

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 06:36:04PM +0200, Daniel Gibson via Digitalmars-d-learn wrote: [...] However, having something like staticIota in the stdlib would probably make sense. [...] It's already in std.typecons. (Admittedly, that's not exactly the most obvious place to look for it...) T --

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 21, 2014 at 06:48:45PM +, bearophile via Digitalmars-d-learn wrote: H. S. Teoh: It's already in std.typecons. But it is not online yet? [...] Hmph. Apparently it is undocumented. :-/ It has been in Phobos since last April, but was private until November when it became

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 22, 2014 at 02:47:51AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: On Monday, 21 July 2014 at 19:02:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: functionality is desirable. Maybe we should rouse a racket on the main D forum to either make staticIota public

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 22, 2014 at 03:52:14PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: I'm just confused about how static while is supposed to work because static foreach, to my understanding, would have to work by making a new type for each iteration. I say this because, 1) runtime foreach

Re: Compile-Time Interfaces (Concepts)

2014-07-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 23, 2014 at 04:21:16PM +0200, bossfong via Digitalmars-d-learn wrote: Could we possibly have a template like the following: satisfiesInterface!(T, Interface); that would return true when T satisfies Interface and otherwise gives descriptive error messages via __pragma(error,

Re: Compile-Time Interfaces (Concepts)

2014-07-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 23, 2014 at 04:46:20PM +0200, bossfong via Digitalmars-d-learn wrote: Am 23.07.2014 16:27, schrieb H. S. Teoh via Digitalmars-d-learn: We could, though it's not quite the same as a native concepts implementation where the compiler can check templates for code that wrongly makes

Re: Compile-Time Interfaces (Concepts)

2014-07-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 23, 2014 at 05:09:54PM +, Bossfong via Digitalmars-d-learn wrote: On Wednesday, 23 July 2014 at 15:28:34 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Jul 23, 2014 at 04:46:20PM +0200, bossfong via Digitalmars-d-learn wrote: [...] Still, maybe compiler errors could

Re: Segfault games with factorials

2014-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 24, 2014 at 01:14:40PM +, Darren via Digitalmars-d-learn wrote: I have the following code in fac.d (modified from the factorial examples on RosettaCode): #!/usr/bin/rdmd import std.bigint; pure BigInt factorial(BigInt n) { static pure BigInt inner(BigInt n, BigInt

Re: D JSON (WAT?!)

2014-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 24, 2014 at 03:54:20PM +, Pavel via Digitalmars-d-learn wrote: [...] Guess what, here's a new snippet: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed =

Re: Showing a user specified error message when no overloads match

2014-07-26 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 26, 2014 at 05:14:44PM +, via Digitalmars-d-learn wrote: Hmmm... thinking about it, is this possible? 1. Remove the constraints to match anything. 2. Inside the template, have some construct that enumerates all possible overloads and UFCS functions that are visible at the

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 27, 2014 at 07:42:17PM -0700, Timothee Cour via Digitalmars-d-learn wrote: Just for clarification, I wanted 'myrange.at(i)' to be the same as `myrange.dropExactly(i).front` (so I don't assume it's a random access range). myrange.dropExactly(i).front makes it much more obvious

Re: Showing a user specified error message when no overloads match

2014-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 29, 2014 at 03:34:22AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: opDispatch behaves as though it has SFINAE. When something fails in the definition (like I am having now, some of the symbols I used in it hadn't been imported) there won't ever be an error message, I just

Re: Showing a user specified error message when no overloads match

2014-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 29, 2014 at 06:57:00PM +0200, Artur Skawina via Digitalmars-d-learn wrote: On 07/29/14 17:45, H. S. Teoh via Digitalmars-d-learn wrote: You're right, opDispatch behaves like SFINAE. I've had trouble debugging it before, because when it works, it works very well, but when you

Re: Showing a user specified error message when no overloads match

2014-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 29, 2014 at 11:30:01PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: On Tuesday, 29 July 2014 at 15:47:08 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Maybe we should file an enhancement bug to improve error reporting for opDispatch. I found this https

Re: Get the default hash function.

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 12:05:52PM +, francesco cattoglio via Digitalmars-d-learn wrote: Really simple question: how do I get the compiler-generated hash function for a given type? For example: Struct S { int i; } can be used in an associative array. That means the compiler

Re: Checked shift?

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 05:00:22PM +, bearophile via Digitalmars-d-learn wrote: Is it a good idea to add int/uint/long/ulong functions for the left shift operation here? https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d [...] What would you check for?

Re: Checked shift?

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 06:08:56PM +, bearophile via Digitalmars-d-learn wrote: H. S. Teoh: What would you check for? Shifting something that already has its high bit set? If you have a uint where the 3 most significant bits are 1, and you shift it 3 bits on the left, you lose those

Re: Checking for Callabilty of either f(x) or x.f

2014-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 01, 2014 at 02:20:53PM +, Nordlöw via Digitalmars-d-learn wrote: [...] What is the preffered (fast) way to check at compile-time if an instance x of a type T can be used *either* as f(x) or x.f? if (is(typeof(f(x))) || is(typeof(x.f))) Basically, is(X)

Re: HTP Handler

2014-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 04:10:27AM +, HUSSAIN via Digitalmars-d-learn wrote: Hi , I am new to D, I would like to build HTTP Server in D. Can any one throw some light on what are all the libraries available in D and if there is any example it would be helpful. [...] http://vibed.org/ T

Re: Associative value order

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 05:54:23PM +, Patrick via Digitalmars-d-learn wrote: I know that there is no prescribed order that the .values array will be sorted in, however I'm curious if the order is deterministic based on keys. If I have two associative arrays with strings for keys and ints

Re: Max/Min values in an associative array

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 05:57:54PM +, TJB via Digitalmars-d-learn wrote: I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that

Re: multidimensional indexing/slicing docs?

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 06:10:43PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 08:48:25 UTC, John Colvin wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? I'm curious about this as well. I've

Re: private selective imports

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 06:19:34PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Is there any way to make selective imports private? I've got a name clash from importing an all module that has a bunch of public imports, one of which is circular, it goes sort of like this: module

Re: Associative value order

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 03:33:15PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: [...] Why is a dictionary something built-in the language? It's actually one of the things I really liked about D when I was first considering it. I hated the fact that it took until C++11 to even *get* a

Re: map reduce for functioneren with two parameters

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 06:44:44PM +, Martijn Pot via Digitalmars-d-learn wrote: I was wondering whether there is a way to use map reduce to calculate e.g. the weighted mean and weighted standard deviation. These would not only need the values, but also the weights. You can probably do

Re: multidimensional indexing/slicing docs?

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 11:21:51AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] In any case, what Kenji did was basically to implement support for: arr[i,j,k,...]; // opIndex arr[i,j,k,...] = ...; // opIndexAssign arr[i1 .. i2, j1 .. j2

Re: private selective imports

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 10:07:53PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Sure, but people keep using them at the module-level, which really shouldn't be done until the bug is fixed. IMHO, we'd be better off making it illegal to use selective imports at the module-level rather

Re: private selective imports

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 10:55:14PM +, Dicebot via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 22:24:24 UTC, H. S. Teoh via Digitalmars-d-learn wrote: My guess is that it requires knowledge of dmd internals that only few people have, and those few people have other fires

Re: multidimensional indexing/slicing docs?

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 08:48:24AM +, John Colvin via Digitalmars-d-learn wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? https://github.com/D-Programming-Language/dlang.org/pull/625 --T

Re: BitArray/BitFields - Review

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 01:10:06AM +, Era Scarecrow via Digitalmars-d-learn wrote: (Moved from: What have I missed?) If this is the wrong place to ask these questions I apologize, getting back into this takes some work. Since this is about contributing to Phobos, probably a better

Re: BitArray/BitFields - Review

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 02:04:12AM +, Era Scarecrow via Digitalmars-d-learn wrote: On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. Yeah posted in my

Re: Member access of __gshared global object

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 02:00:27AM +, Puming via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: [...] Indeed, it was just what the OP suspected as the culprit. You are right, I didn't know about the AA initialization problem then. When I

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 04:49:05PM +, seany via Digitalmars-d-learn wrote: On Thursday, 7 August 2014 at 16:12:59 UTC, Justin Whear wrote: On Thu, 07 Aug 2014 16:05:16 +, seany wrote: obviously there are ways like counting the match length, and then using the maximum length, instead

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 05:33:42PM +, Justin Whear via Digitalmars-d-learn wrote: On Thu, 07 Aug 2014 10:22:37 -0700, H. S. Teoh via Digitalmars-d-learn wrote: So basically you have a file containing regex patterns, and you want to find the longest match among them

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 10:42:13AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] Hmm, you're right. I was a bit disappointed to find out that the | operator in std.regex (and also in Perl's regex) doesn't do longest-match but first-match. :-( I had always thought it did longest-match

Re: Passing Command Line Arguments to a new Thread

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 06:23:24PM +, Nordlöw via Digitalmars-d-learn wrote: What is the best way to forward a string[] as argument to a function called through std.concurrency.spawn(). I need this in the following example where I start the vibe.d event loop in the main thread (the only

Re: multidimensional indexing/slicing docs?

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 06, 2014 at 12:16:57PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 06, 2014 at 11:21:51AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] In any case, what Kenji did was basically to implement support for: arr[i,j,k,...]; // opIndex

Re: d malloc

2014-08-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 08, 2014 at 04:42:12PM +, seany via Digitalmars-d-learn wrote: consider this : struct S { /* ... */ } void main() { ulong [] u; for(// ... { S s_instance; // fillup .. S.key = value; u ~= cast(ulong)*s_instance; } } however,

Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 09, 2014 at 05:34:40AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Yep, replacing @property with auto did the trick. The lack of error messages in opDispatch is frustrating. I realize that, due to tricks like __traits(compiles, Foo.testing_for_some_function), having

Re: Multidimensional slice

2014-08-09 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 09, 2014 at 08:43:32PM +, Remi Thebault via Digitalmars-d-learn wrote: Hello D-community Sorry to dig an old post, but I have the exact same need. I have C++ background and I started to use D a few days ago only (a pity I didn't start sooner!) My needs are mostly around

Re: undefined references

2014-08-10 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 03:12:43AM +, Vlad Levenfeld via Digitalmars-d-learn wrote: [...] So, while the mistake was mine, this should be an ambiguous overload error at compile-time, instead of a linker error. I realize that everyone contributing to D has their hands more than full, and

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 05:51:11PM +, Gary Willoughby via Digitalmars-d-learn wrote: Just for a bit a fun i've implemented a simple doubly linked list and trying out some range based stuff. Whilst doing so i have some questions which you guys might be able to answer. 1. In your opinion

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 07:35:04PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via Digitalmars-d-learn wrote: If you make your linked list container the same thing as a range over it, then iterating over the range will empty

Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via Digitalmars-d-learn wrote: I mean when writing a D lexer, you necessarly reach the moment when you think: Oh no! is this feature just here to suck ? I use heredocs every now and then when I need to embed long strings in my program. It's one

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 08:22:11PM +, Gary Willoughby via Digitalmars-d-learn wrote: [...] That..is..awesome! and much more simpler than i thought. I get it now, thanks. Is this pattern repeated in phobos? This is essentially what byKey and byValue of the built-in associative arrays do.

Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 10:50:34PM +0200, Philippe Sigaud via Digitalmars-d-learn wrote: On Mon, Aug 11, 2014 at 10:09 PM, H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via Digitalmars-d-learn wrote: I mean

Re: Very vague compiler error message

2014-08-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 12, 2014 at 07:16:49AM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I recently got this error messege when building my library: dmd: cppmangle.c:154: void CppMangleVisitor::cpp_mangle_name(Dsymbol*): Assertion `0' failed. I have no idea what it means and haven't found

Re: Capture parameter identifier name in a template?

2014-08-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 12, 2014 at 05:36:40PM +, Maxime Chevalier-Boisvert via Digitalmars-d-learn wrote: In my JavaScript VM, I have a function whose purpose is to expose D/host constants to the JavaScript runtime code running inside the VM. This makes for somewhat redundant code, as follows:

  1   2   3   4   5   6   7   8   9   10   >