Re: Obtaining argument names in (variadic) functions

2016-03-20 Thread JR via Digitalmars-d-learn
On Thursday, 17 March 2016 at 14:12:38 UTC, Edwin van Leeuwen wrote: On Thursday, 17 March 2016 at 13:53:00 UTC, JR wrote: Interesting, any idea if it is possible to do assignment within template.. Either: printVars!(int abc=5,string def="58")(); or something like printVars!("

Re: No property error message

2016-03-19 Thread JR via Digitalmars-d-learn
On Saturday, 19 March 2016 at 18:36:10 UTC, ric maicle wrote: I got an error message with the following code saying: Error: no property 'length' for type 'int[string]' Shouldn't the error message say 'length()'? ~~~ import std.stdio; void main() { int[string] a; a["one"] = 1;

Re: How do I extend an enum?

2016-03-19 Thread JR via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:41:29 UTC, Lass Safin wrote: On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E =

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
On Thursday, 17 March 2016 at 11:52:13 UTC, Edwin van Leeuwen wrote: On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote: void printVars(Args...)() if (Args.length > 0) { import std.stdio : writefln; foreach (i, arg; Args) { writefln("%s\t%s:\t%s", typeof(Args

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:24:38 UTC, data pulverizer wrote: Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T x){ foreach(i, arg; x) writeln(i, " : ",

Re: Obtaining argument names in (variadic) functions

2016-03-18 Thread JR via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:43:09 UTC, jkpl wrote: I try to anticipate the reason why you want this. [...] I use something *kinda* sort of similar in my toy project to print all fields of a struct, for debugging purposes when stuff goes wrong. Getting the names of the member variables

Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread JR via Digitalmars-d-learn
On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote: On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote: [...] Basile beat me to it. Yes, ref const(Array!T) accessor. http://dpaste.dzfl.pl/cb2bc5cf9917

Re: efficient and safe way to iterate on associative array?

2016-03-04 Thread JR via Digitalmars-d-learn
On Friday, 4 March 2016 at 14:16:55 UTC, Minas Mina wrote: On Friday, 4 March 2016 at 13:53:22 UTC, aki wrote: I think what you can do is extract its contents to an array, iterate it and modify it as you like, and then insert back to another associative array. I don't think it's efficient but

New forum mobile appearance feedback

2016-01-22 Thread JR via Digitalmars-d-learn
Unsure where else to post this, since it feels like it would intrude on the more serious discussions in the main D forum. The new forum design is overall great, but it really doesn't work well on mobile devices. Coupled with field padding the font is simply too large. (This holds for the

Re: alias butAtLeast = max; 5.butAtLeast(6);

2015-12-12 Thread JR via Digitalmars-d-learn
On Saturday, 12 December 2015 at 12:43:36 UTC, SimonN wrote: DMD v2.069.2-b1 on Linux. import std.algorithm; int a = max(5, 6);// works, a == 6 int b = max!(int, int)(5, 6); // works, manual instantiation int c = 5.max(6); // works, UFCS call I would

Re: benchmark on binary trees

2015-12-05 Thread JR via Digitalmars-d-learn
On Friday, 4 December 2015 at 14:06:26 UTC, Alex wrote: [...] hoping it would be faster. This was not the case. Why? [...] Is there anything else to improve performance significantly? Profile. Profile profile profile. Callgrind. Find bottlenecks instead of guessing them.

Re: Help with Concurrency

2015-11-04 Thread JR via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: Running the following code I get 3 different tid's, multiple "sock in" messages printed, but no receives. I am supposed to get a "received!" for each "sock in", but I am getting hung up on "receiving...". [...] while (true)

Re: Help with Concurrency

2015-11-04 Thread JR via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 16:49:59 UTC, JR wrote: [...] And my indentation and brace-balancing there is wrong. Shows how dependent I've become on syntax highlighting. import core.time; import std.concurrency; bool received = receiveTimeout(1.seconds, writeln

writefln patterns with mismatching compile-time known number of arguments

2015-04-12 Thread JR via Digitalmars-d-learn
I was chatting with a friend and showed him how printf(%s) printed random memory in C, whereas writefln(%s) in D threw an Exception upon execution. It's probably not a completely fair comparison but that's a different topic. I admit to being confused as to why it passed compilation at all in

Re: printing array of strings with writefln?

2014-11-16 Thread JR via Digitalmars-d-learn
On Sunday, 16 November 2014 at 14:16:55 UTC, Artem Tarasov wrote: writefln(%(%s-%), [a, b, c]) doesn't print the intended a-b-c but surrounds each string with double quotes - a-b-c, which I find inconsistent with the fact that writefln(%s, a string) prints the string without any quotes. How

Re: how to call class' template constructor

2014-10-12 Thread JR via Digitalmars-d-learn
On Sunday, 12 October 2014 at 19:46:41 UTC, ketmar via Digitalmars-d-learn wrote: Hello. please, how to call template constructor of a class? it's completely escaped my mind. i.e. i have this class: class A { this(alias ent) (string name) { ... } } and i want to do:

Re: Template instantiation and string vs const char[]

2014-09-03 Thread JR via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 05:18:42 UTC, Jason den Dulk wrote: [...] While not really answering your question, I believe the idiomatic way is to use enum here instead of string/char[]. Conjecture: strings are final but the symbol can be redirected to point to new arrays, such as

Appender.put return value

2014-07-24 Thread JR via Digitalmars-d-learn
Is there a big reason why Appender.put doesn't return this? http://dpaste.dzfl.pl/bb840e3e349e It would allow for convenient chaining. :

Re: Insert a char in string

2014-07-11 Thread JR via Digitalmars-d-learn
On Thursday, 10 July 2014 at 19:33:15 UTC, simendsjo wrote: On 07/10/2014 06:05 PM, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = 100; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace,

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

2014-07-10 Thread JR via Digitalmars-d-learn
On Monday, 7 July 2014 at 23:47:26 UTC, Aerolite 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 in-depth to weird edge cases -

Re: stack trace output on exception

2014-07-08 Thread JR via Digitalmars-d-learn
On Tuesday, 8 July 2014 at 07:11:26 UTC, Stephan Schiffels wrote: Hi, I am using dmd with version: DMD64 D Compiler v2.065-devel-db2a73d My program throws a custom exception with a custom error message at some point. The stack trace (below) is very uninformative. Is there a way to output

Re: Capture offset of matches in std.regex.matchAll?

2014-07-08 Thread JR via Digitalmars-d-learn
On Monday, 7 July 2014 at 21:32:30 UTC, JD wrote: I'm using a compile time regex to find some tags in an input string. Is it possible to capture the offset of the matches in some way? Otherwise I have to calculate the offsets myself by iterating over the results of matchAll. Thanks, Jeroen I

Re: Permutation Sort Algorithm Very Slow

2014-06-08 Thread JR via Digitalmars-d-learn
On Sunday, 8 June 2014 at 08:44:42 UTC, monarch_dodra wrote: of. If you want to use a bad algorithm, you could also go for bogosort: void main() { auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1]; while (!isSorted(data)) randomShuffle(data); data.writeln; } I'm partial to

Re: receiveTimeout minimum reasonable timeout value?

2014-05-15 Thread JR via Digitalmars-d-learn
On Thursday, 15 May 2014 at 18:15:46 UTC, Charles Hixson via Digitalmars-d-learn wrote: Duration can be specified in nanoseconds, but does it make any sense to have a value of 1 nanosecond? 0? My desire is to check whether a message is in the queue, and then either move it local to the

Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread JR via Digitalmars-d-learn
Given that... 1. importing a module makes it compile the entirety of it, as well as whatever it may be importing in turn 2. templates are only compiled if instantiated 3. the new package.d functionality ...is there a reason *not* to make every single function/struct/class separate submodules

Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread JR via Digitalmars-d-learn
On Monday, 12 May 2014 at 09:16:53 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Well, that would be a lot of extraneous files, which would be very messy IMHO. It also makes it much harder to share private functionality, because everything is scattered across modules - you'd be force to

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

2014-05-06 Thread JR via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 09:43:10 UTC, FrankLike wrote: Hi,everyone, I find the The writeln() function's args can't be [一 ,二]? why? Thank you. Frank. The problem is that you have a wide-character comma (,) there. This works: void main() { writeln([一, 二]); }

Allocation-free message passing?

2014-05-02 Thread JR via Digitalmars-d-learn
I'm trying to impose limits upon myself to, well, learn. Currently I'm exploring ways to avoid allocations -- but my program is running in three threads with considerable amounts of message passing between them. Unless I'm misinterpreting my callgraph, std.concurrency.MessageBox contains a

Re: number formatting

2014-04-20 Thread JR via Digitalmars-d-learn
On Sunday, 20 April 2014 at 12:53:11 UTC, steven kladitis wrote: Note sure if you can edit messages once sent. $13,456.67 245,678,541 On Sunday, 20 April 2014 at 12:50:52 UTC, steven kladitis wrote: How do you format numbers to have things like. Leading $ or , or CR with or without leading

Re: Successively prepending to slices.

2014-04-10 Thread JR
It depends on your use-case, I think. How often will you be prepending? Will you be appending as well? On Thursday, 10 April 2014 at 16:10:04 UTC, Steven Schveighoffer wrote: Note, I create a deque class in dcollections which maintains 2 arrays, one for prepending (and is in reverse order),

Re: Empty array and AA literals

2014-04-09 Thread JR
On Sunday, 6 April 2014 at 20:14:41 UTC, monarch_dodra wrote: Right, but what I'm getting at, in regards to the original question: What's the syntax for a new empty dynamic array You don't new the dynamic array. Technically, you just allocate memory, and then have your *slice* reference that

Re: Empty array and AA literals

2014-04-09 Thread JR
On Wednesday, 9 April 2014 at 16:46:00 UTC, monarch_dodra wrote: I *think* there was some miscommunication here: auto arr = new int[](99); Is perfectly valid, and the recommended way to do it (provided you know how much you want to allocate when constructing). Looks like it. :) The flow of

Re: running my program with shared libraries

2014-04-08 Thread JR
On Sunday, 6 April 2014 at 02:49:15 UTC, Adam D. Ruppe wrote: LD_LIBRARY_PATH tells it where to find the shared library files. Without it, the system only searches the global directories like /usr/lib. To list said directories; ldconfig -v 2/dev/null | grep '^/' You can add your own

Re: Empty array and AA literals

2014-04-06 Thread JR
On Sunday, 6 April 2014 at 09:52:04 UTC, monarch_dodra wrote: An Dynamic Array is merelly a fat pointer that holds both pointer and length. There is no need to create or new a Dynamic Array. new allows for setting the length immediately, though. auto arr = new int[](99); //

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread JR
On Thursday, 27 March 2014 at 17:41:14 UTC, Jeremy DeHaan wrote: typeof(this) gives its fully qualified name though. I was looking for a way to get just the name of the class alone. I guess I'm confused about what 'fully qualified name' entails. For a class Foo, is Foo not just the name of

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread JR
On Friday, 28 March 2014 at 13:42:43 UTC, w0rp wrote: size_t dotIndex = qualName.retro.countUntil('.'); if (dotIndex 0) { size_t is unsigned. :3 (So ptrdiff_t -- or simply auto.)

Re: Getting a class' name, but not fully qualified?

2014-03-27 Thread JR
On Thursday, 27 March 2014 at 06:16:04 UTC, Jeremy DeHaan wrote: As the title says, I was wondering if there was a way to get the classes name at runtime, but not its fully qualified name. I want JUST the name of the class only. So for a given class Foo, you want to extract the string Foo?

What does to!someEnum(string) lower to? Comparing speed to someEnum[string] AA lookups

2014-03-01 Thread JR
In my pet project I'm casting a lot of strings to named enum members. enum Animal { Gorilla, Shark, Alien, Rambo, Dolphin } auto foo = Dolphin; auto fooAsEnum = foo.to!Animal; While micro-optimizing because it's fun, I see that it's much faster (by some factor of 3.5x) to do such

Re: tango -D2 regex

2013-12-16 Thread JR
On Monday, 16 December 2013 at 07:46:30 UTC, seany wrote: I dont find any info on backtrack on tango-D2 regex. For example, I want to match things like barFOObar or bazFOObaz so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given by \w* that was matced in the first

Re: T[] (array of generic type)

2013-11-18 Thread JR
On Monday, 18 November 2013 at 19:47:47 UTC, seany wrote: A natural choice is fuction(T)(T[] array, T var) but i dont find much info on this type on construction, is there any material introducing me to this type of construction? Ali's book has a good introduction to templates:

Re: Efficient string concatenation?

2013-11-16 Thread JR
On Friday, 15 November 2013 at 22:33:34 UTC, Brad Anderson wrote: Appender in std.array is probably what you are looking for. std.algorithm.joiner is also useful (no allocations at all even) but the use case is a bit different. Is Appender considered up to Phobos' current standards? I

Re: How to re-initialise an associative array.

2013-11-06 Thread JR
On Wednesday, 6 November 2013 at 16:15:36 UTC, Gary Willoughby wrote: A simple request but i'm failing hard. How do i re-init an associative array? This is obviously not the way: import std.stdio; void main(string[] args) { int[string] x;

pitfalls of enum

2013-11-02 Thread JR
(TL;DR: when to avoid enum?) From the dlang.org page on enums; Enum declarations are used to define a group of constants. They come in these forms: Named enums, which have an EnumTag. Anonymous enums, which do not have an EnumTag. Manifest constants. Quoth Dmitry Olshansky in my thread on

Re: std.parallelism amap not scaling?

2013-10-08 Thread JR
On Monday, 7 October 2013 at 21:13:53 UTC, safety0ff wrote: I think I've found the culprit: Memory managment / GC, disabling the GC caused the program to eat up all my memory. I'll have to look into this later. From what I've gathered from

Re: Regex matching cause lots of _d_arrayliteralTX calls

2013-09-27 Thread JR
On Friday, 27 September 2013 at 14:37:05 UTC, Dmitry Olshansky wrote: 27-Sep-2013 02:00, JR пишет: And the answer is - don't use ENUM with ctRegex. The problem is that ctRegex returns you a pack of datastructures (=arrays). Using them with enum makes it behave as if you pasted them as array

Regex matching cause lots of _d_arrayliteralTX calls

2013-09-26 Thread JR
I'm working on a toy IRC bot. Much of the logic involved is translating the incoming raw IRC string into something that makes sense (so now I have two problems, etc). But I managed to cook up a regex that so far seems to work well. Time for callgrind! Grouped by source file, most time is

Re: Regex matching cause lots of _d_arrayliteralTX calls

2013-09-26 Thread JR
On Thursday, 26 September 2013 at 23:04:22 UTC, bearophile wrote: I am not sure how a IRC bot could consume more than a tiny fraction of the CPU time of a modern multi-GHz processor. Nor does it bite into my 8 gigabytes of ram. Forgive me, but the main culprit in all of this is still me doing

Re: Large (32 byte) concurrency messages

2013-08-17 Thread JR
On Saturday, 10 August 2013 at 15:12:39 UTC, Ali Çehreli wrote: On 08/10/2013 08:04 AM, JR wrote: This project made it very simple for me: https://github.com/carlor/dlang-workspace My belated thanks; this worked great.

Re: Large (32 byte) concurrency messages

2013-08-10 Thread JR
On Friday, 9 August 2013 at 15:45:51 UTC, Ali Çehreli wrote: How about passing by-value? The following seems to work. (I used v2.064-devel-4203c06 but I don't know whether it is different on older compilers.) // Receives by value: mixin MessageReaction.Print!(IrcEvent) immEvtPtr; //

Re: Large (32 byte) concurrency messages

2013-08-09 Thread JR
On Thursday, 8 August 2013 at 21:11:06 UTC, Ali Çehreli wrote: An immutable on the receiving side is a request to the caller that the data must be immutable. If you are casting data with mutable indirection to immutable, anything can happen. immutable data is by nature not synchronized

Re: Large (32 byte) concurrency messages

2013-08-09 Thread JR
On Thursday, 8 August 2013 at 21:16:36 UTC, David Nadlinger wrote: On Thursday, 8 August 2013 at 20:08:11 UTC, JR wrote: I put together http://dpaste.dzfl.pl/d7322971 earlier to demonstrate some of these errors, though I didn't mention the raciness of passing pointers there. To test that race

Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread JR
On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote: To get rid of the cast: [...] Instantiating the template with a function parameter causes a compilation error when actually calling the function; -- asdf.d:13: Error: variable asdf.MatrixWalker!(@system void(string

Re: Arrays of functions, function signatures and template instantiation

2013-04-30 Thread JR
On Tuesday, 30 April 2013 at 09:18:56 UTC, anonymous wrote: On Tuesday, 30 April 2013 at 08:42:57 UTC, JR wrote: On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote: Don't know what's going wrong there. It works for me: http://dpaste.dzfl.pl/5c71f80e My bad, I switched the wrong

Arrays of functions, function signatures and template instantiation

2013-04-29 Thread JR
I'm piecing together a small IRC bot as my second pet project, and next up is splitting the socket-listening/event handling into a separate thread. TL;DR: skip to the link at the bottom -- can't it be done neater? Raw IRC commands are strings whose format differs depending on the *type* of