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!("
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;
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 =
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
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, " : ",
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
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
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
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
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
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.
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)
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
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
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
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:
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
Is there a big reason why Appender.put doesn't return this?
http://dpaste.dzfl.pl/bb840e3e349e
It would allow for convenient chaining. :
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,
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 -
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
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
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
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
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
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
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([一, 二]);
}
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
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
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),
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
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
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
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);
//
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
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.)
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?
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
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
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:
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
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;
(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
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
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
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
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
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.
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;
//
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
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
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
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
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
54 matches
Mail list logo