On Sunday, 8 August 2021 at 23:04:32 UTC, Marcone wrote:
How to divide by space keeping words with spaces inside quotes?
Well the designers of ASCII were morons who decided that open
quote and close quote would be the same damn letter, so it's a
little trickier. Basically what you have to do
On Wednesday, 5 August 2020 at 06:02:58 UTC, cy wrote:
Some way to import the compiler itself, instead of calling it
in a subprocess?
Well, I did find this:
https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/
But it's pretty advanced... probably just invoking dmd w
D's compile-time-execution is fantastic, but there are some times
when I'd like to examine the generated code, or produce code that
needs to pass through earlier phases before CTFE, or do AST
stuff. Sometimes I simply don't want to generate the code with
every compilation, so saving the generat
And OK yes I see gdc definitely does not support static foreach,
but instead there's some sort of D compiler written in D compiled
by GDC? That's just dmd, isn't it?
https://github.com/D-Programming-GDC/GDC/pull/550
He calls it "DDMD."
hunt/source/hunt/serialization/JsonSerializer.d:125:20: error:
basic type expected, not foreach
125 | static foreach (string member;
FieldNameTuple!T) {
I'm having a little trouble using the hunt library with gdc. Does
gdc not support static foreach at all? Is there some way to w
On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote:
A string *is* a pointer length pair, an immutable(char)[].
Yes, but surely there's some silly requirement, like that the
pointer must only ever point to garbage collected memory, or
something?
ubyte[] arr; // or byte/char wh
So a lovely C library does its own opaque allocation, and
provides access to the malloc'd memory, and that memory's length.
Instead of copying the results into garbage collected memory
(which would probably be smart) I was thinking about creating a
structure like:
struct WrappedString {
byt
On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote:
The plain regex function doesn't have such a requirement. It
also works with a pattern that's generated at run time, e.g.
from user input. But you can use it with a compile time
constant, too. And it works in CTFE then, but it does n
import std.algorithm.searching: startsWith, commonPrefix;
if(s1.startsWith(s2)) {...}
string prefix = commonPrefix(s1,s2);
On Tuesday, 23 August 2016 at 04:51:19 UTC, ag0aep6g wrote:
That's true, and apparently `regex("foobar")` can be evaluated
at compile time.
Then what's ctRegex in there for at all...?
On Sunday, 21 August 2016 at 21:18:11 UTC, ag0aep6g wrote:
I may be missing the point here, but just putting `auto pattern
= regex("foobar");` at module level works for me.
Really? I thought global variables could only be initialized with
static stuff available during compile time, and you ne
At seconds PER (character range) pattern, ctRegex slows down
compilation like crazy, but it's not obvious how to avoid using
it, since Regex(Char) is kind of weird for a type. So, here's
what I do. I think this is right.
in the module scope, you start with:
auto pattern = ctRegex!"foobar";
an
On Tuesday, 16 August 2016 at 21:13:38 UTC, Steven Schveighoffer
wrote:
static if(isForwardRange!(typeof(iter)))
But this may not work for any input range, since any time you
copy the range, you are copying internal state that may cache
an element or more.
Yes, that was the problem with Sec
InputRanges that are not ForwardRanges seem to lack a possibly
crucial operation. I want to start with an arbitrary range, take
1 from it, then process the rest. But there doesn't seem to be
any way to do that, because there's no way to tell whether "take"
will advance the range, or whether it
On Friday, 12 August 2016 at 15:21:22 UTC, D.Rex wrote:
I was wondering how this is achieved in D, or if D has an
alternative implementation of this.
It isn't, because C interfaces that require you to pass in
structures are inherently bad design, and usually both unstable
and extremely C spec
Here's how to do it using context switches. There ought to be a
way to manually pass specific state around to keep that from
happening, but probably not since there's no interface to pause
something writing to an OutputRange.
auto pipe(T, alias oh)()
{
import std.concurrency: Generator
I was trying to use std.regex, and it takes an output stream to
pump the result to, which is great, but I wanted to perform TWO
replacements, one with the output of the previous, with data that
might be a tricky size to cache redundantly.
So, ideally when you do something like regexp replacing
On Tuesday, 9 August 2016 at 05:33:09 UTC, Jonathan M Davis wrote:
Personally, I think that you should just make it a member
function if it's not a generic function, but to each their own,
Well, I use generics for when I have like, optional functionality
that isn't inherent to the class itself
I really like UFCS, which is to say, defining functions outside
the class/struct to operate on it, but you can still say
object.function(...) and it'll get rewritten into
function(object,...).
Only sticky point is the convenience of "this". Like I can go
struct A {
bool a;
boo
Say I have a package called "main" and a sub-package in a
"complicatedexample" directory, and my dub.json in "main" looks
sort of like:
"subPackages": [
"./complicatedexample/"
],
Let's say I do *not* have ":complicatedexample" in my
dependencies for "main", but "complicatedexample" itself
On Friday, 15 July 2016 at 19:20:52 UTC, Jacob Carlborg wrote:
Yes. Just as it's possible to call C function from D, it's
possible to implement functions in D that can be called from C.
This compatibility applies C++ and Objective-C as well.
So, it applies to member functions too (for C++)? Ju
I would never (ever) do this myself, but trying to understand
dmd, the code is absolutely packed with things like this:
extern(C++) class Package : ScopeDSymbol
{
...
override const(char)* kind() const
{
return "package";
}
...
override final inout(Package) isPackage() inout
{
On Monday, 20 June 2016 at 16:39:54 UTC, Marc Schütz wrote:
Untested:
Seems to only work if A and B are both defined in the same file
as Foos (defeating the purpose). Putting A and B in a.d and b.d
respectively gives me these errors:
a.d(2): Error: undefined identifier 'Foos'
a.d(2): Error:
On Saturday, 18 June 2016 at 07:03:25 UTC, cy wrote:
So how would you do it? Defining A.foo, B.foo, etc in one
place, and A.bar, B.bar, etc in another?
The only thing I've been able to figure is a horrible hack, where
your member functions are something like
// off in define_foos.d
template
On Saturday, 18 June 2016 at 08:41:30 UTC, Johan Engelen wrote:
Without going in too much detail, the problem is that I am not
linking to opaque .o files.
The problem is the compiler has to assume you *might* be linking
to opaque .o files, so it can't provide any introspection
capabilities. T
On Friday, 17 June 2016 at 13:53:15 UTC, Vladimir Panteleev wrote:
Geod24 on IRC suggested signalfd + createFileDescriptorEvent. I
think this would work, but isn't it possible to wrap the fd
returned by signalfd into a Vibe.d stream and read it directly?
I'm just not sure how.
Well, vibe.d s
When I define functions like:
class A {
abstract void format(...) {...}
}
class B : A {
void format(...) {...}
}
class C : A {
void format(...) {...}
}
and so on, often these different member functions all share a lot
in common. Maybe they are the only ones that require formatting
modu
On Friday, 17 June 2016 at 19:49:18 UTC, Johan Engelen wrote:
Hi all,
Is there another way to get access to Voldemort class
methods, or private class members, other than using
Voldemort data is pretty well protected though. Because unlike
protection attributes, modularizing stuff in functio
On Friday, 17 June 2016 at 20:12:53 UTC, cy wrote:
writeln("see ",wow," for any equipment you need.");
Oh, and as you can see it's important to automate that, so you
don't make any mistakes while copying.
On Friday, 17 June 2016 at 19:49:18 UTC, Johan Engelen wrote:
Hi all,
Is there another way to get access to Voldemort class
methods, or private class members, other than using
"pragma(mangle, ...)" on user symbols?
Well, I'm sure you know that's a horrible idea. Anyway, a trick I
use in C+
I don't get it. Do I have to write a separate template for arrays
specifically or something?
NonConst foo(Constant: const NonConst, NonConst)(Constant bar) {
pragma(msg,"NonConst is ",NonConst);
pragma(msg,"Constant is ",Constant);
NonConst foo = bar;
return foo;
On Thursday, 9 June 2016 at 20:53:38 UTC, tcak wrote:
(cast()mx).lock();
I was told casting away shared when there are still references to
it is a bad idea. Like, the Mutex object might get corrupted if
the garbage collector tries to move it while another thread is
using it.
So th
On Tuesday, 7 June 2016 at 22:09:58 UTC, Alex Parrill wrote:
Accessing a SQL server at compile time seems like a huge abuse
of CTFE (and I'm pretty sure it's impossible at the moment).
Why do I need to install and set up a MySQL database in order
to build your software?
Presumably you would
The other way is better, but since you asked...
On Wednesday, 8 June 2016 at 01:42:55 UTC, Carl Vogel wrote:
Now, I can use something like isCallable std.traits to make
sure the predicate is a Callable, and there are various
function traits in the module that I could combine with `is`
clauses
I can't help but notice that loadModel is not a static member
function, yet you don't seem to call it with a Model object in
your "get" function.
Also have a look at std.typecons.RefCounted if you want reference
counted data..
I was thinking of using threads in a D program (ignores unearthly
wailing) and I need 1 thread for each unique string resource
(database connection info). So I did this:
shared BackgroundDB[string] back;
I don't see any way to make less data shared there. If it weren't
shared, it would be thr
On Tuesday, 7 June 2016 at 22:17:03 UTC, ag0aep6g wrote:
You don't specify the types of the parameters of the function
literals, so you effectively have templates there. As such the
literals have no types, and can't be passed as arguments.
Yeah, I see that now. The compiler does have all the n
This program errors out, when I try to pass lambdas that take
arguments. How am I getting the syntax wrong here? Is there some
reason you can't do this?
import std.stdio;
void foo(Callable)(Callable bar) {
bar();
}
void foo2(Callable)(Callable bar, int baz) {
bar(baz);
}
void main() {
https://p0nce.github.io/d-idioms/ I wanted to mention as well, if
you like idioms. That guy has some good ideas.
On Tuesday, 24 May 2016 at 17:36:45 UTC, Ali Çehreli wrote:
Yes, a link from that page points to a book that *can* be
bought but it's available online as well:
It's worth buying, b
On Tuesday, 24 May 2016 at 15:27:45 UTC, llaine wrote:
I'm running Fedora 23 on a daily basis and the installation was
OK. Not as easy as on mac but still.
Yeah, rpm based distributions like Fedora/Redhat/etc have
historically been a real pain when it comes to installing stuff.
Depending on i
I was squinting at the std.typecons.NullableRef code and it
_looks_ like isNull is only checked at runtime (and not checked
at all in release mode!) but D has surprised me before in its
ability to pre-calculate stuff during compilation.
I was thinking of using something like this:
http://arsd
On Thursday, 19 May 2016 at 17:50:44 UTC, ciechowoj wrote:
dub build --nodeps
I tried it, doesn't seem to do anything, maybe something is
broken.
Perhaps you didn't complete "dub build" without --nodeps
beforehand? You have to do that once, and it's still as
annoyingly inefficient as anyth
On Sunday, 15 May 2016 at 02:12:38 UTC, Ann W. Griffith wrote:
use "Parameters" in the constraint or make a template that you
can reeuse.
This is what I've got going so far. Using static asserts to have
clearer errors when an incorrect callback is supplied. I'm not...
sure storage class is im
I take callbacks on occasion, and I don't really care if they're
a delegate, or a function, or a callable object, and I can assert
that in a template:
void foo(Callable)(Callable callback) if(isSomeFunction!Callable
|| isCallable!Callable) {
...
}
That works, but it doesn't show you what ar
On Monday, 7 March 2016 at 09:18:37 UTC, ciechowoj wrote:
I'm using `dub` to build project. And every time I run `dub` it
seems to check if dependencies are up to date, which takes some
time. Is there a way to switch of that checking? Or any other
way to speed up building process? It really slo
Well, just messing with it myself, the solution seems to be to
make a .a library, link with /lib/libc.a since unlike .o, .a
breaks shared linkage, and then refer to it in libs as
"$PACKAGE_DIR/libmywrapper.a"
...
"preBuildCommands": ["make -C $PACKAGE_DIR"],
"libs":
["$PACKAGE
I'm tiring of making extern (C) signatures for a million library
calls and counting out the offset of members of C structures, to
produce analagous D structures. Couldn't I just make a .c file
that had my own specialized, opaque, D friendly interface?
I don't really know how to do that. Especi
Oh, cool.
On Thursday, 31 March 2016 at 03:29:19 UTC, H. S. Teoh wrote:
Or implement manual substitution with a pipeline:
string myString = ...;
string escapedStr = myString
.chunks(1)
.map!(c => (c == "\n") ? "\\n" :
(c
On Thursday, 31 March 2016 at 03:23:52 UTC, Seb wrote:
http://dlang.org/spec/lex.html#WysiwygString
r"ab\n" or `ab\n`
Yes I know. But I mean like,
string a = r"ab\n";
writeln(escape(a)); // => ab\n
This might be a dumb question. How do I format a string so that
all the newlines print as \n and all the tabs as \t and such?
On Tuesday, 29 March 2016 at 06:21:49 UTC, Ali Çehreli wrote:
parent.prep.bind is translated to the following by the compiler:
"Call bind() for the object at address... let's calculate...
Wherever parent is, we should add the offset of prep inside
that object."
Okay, that's helpful actually.
On Monday, 28 March 2016 at 21:24:48 UTC, Adam D. Ruppe wrote:
If it didn't give the error, either you swallowed it or you
didn't actually dereference null.
Okay, so it's not actually supposed to happen. Hopefully it's
something I did wrong...
What is the db library you are using? Did you co
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote:
I invoked db.find_chapter.bindAll(8,4), when db was a null
pointer.
No, no, no it's worse than that. What I did was (db.)find_chapter
= (db.)backend.prepare("...") when backend was null, and got no
error. find_chapter was garbage of course,
I finally found the null pointer. It took a week. I was assigning
"db = db" when I should have been assigning "this.db = db".
Terrible, I know. But...
I invoked db.find_chapter.bindAll(8,4), when db was a null
pointer. There was no null pointer error. No exception raised for
dereferencing a n
On Wednesday, 23 March 2016 at 23:44:55 UTC, ag0aep6g wrote:
You got the order of arguments wrong here. Source goes first,
Oh, derp. Thanks. Right then... it works as expected.
struct Thing {
@disable this(this);
}
...
items ~= move(item); // Error: struct Thing is not copyable
because it is annotated with @disable
++items.length
move(items[$-1],item); // Error: struct Thing is not copyable
because it is annotated with @disable
appender(items).put(move(item)); //
halp
There's a module that tries to define complex operations on both
const and non-const structs, since it's the same operation for
both. So every function that invokes those operations is
copy-pasted twice, just with "const" added. Switching to inout to
eliminate that huge amount of code du
On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote:
Just to be 100% clear: you're adding to the pointer here,
No, that's what I meant to do.
b = new int(*b + 1);
Here "b" is pointing to mutable heap allocated data, which got
cast to constant.
with b = b + 1, it's still constant me
a = a + 1
a is const, a + 1 is const, yet a can't be assigned to a + 1. And
I think the reason is like...
const(int) a = 23;
while(something()) {
a = a + 1;
}
in the first iteration, a is set to 23, and the value of "a + 1"
is 24, but where is the computer gonna store that 24? It can't
st
On Monday, 21 March 2016 at 17:26:09 UTC, Karabuta wrote:
Will this work
Yes.
and is it the right approach used by video convertor front-ends?
Well, yes, provisionally. When you invoke "ffmpeg" via
spawnProcess, that isolates ffmpeg as its own process, obviously.
From a security and main
On Tuesday, 22 March 2016 at 07:17:41 UTC, Hanh wrote:
input.take(3).array;
foreach (char c; input) {
Never use an input range twice. So, here's how to use it twice:
If it's a "forward range" you can use save() to get a copy to use
later (but all the std.stdio.* ranges don't i
On Monday, 21 March 2016 at 04:58:37 UTC, cy wrote:
I also tried symlinking ../sharedViews into views/shared and
importing "shared/common.stuff" but that didn't work either.
Oh. I was editing dub.selections.json. Never mind, I'm just an
idiot.
I also tried symlinking ../sharedViews into views/shared and
importing "shared/common.stuff" but that didn't work either.
"stringImportPaths": ["../sharedViews/"]
nope...
"buildSettings": {
"stringImportPaths": ["../sharedViews/"]
}
nope...
"package": {
"name": "myownfreakingpackage",
"buildSettings": {
"stringImportPaths": ["../sharedViews/"]
}
}
nope...
"packag
I don't know, but you could always just use fcntl if you already
can assume you're on Linux.
extern (C) int fcntl(int, int, int);
C keeps the constants under lock and key of course, so you have
to specify them manually. But you could write a C program to
print them out, or generate D code I s
On Thursday, 11 February 2016 at 04:07:18 UTC, cy wrote:
A[] as = new A[2];
assert(as.length==2);
as[0].stuff = 42;
Oh, I get it. `as` is an array of 2 pointers to A objects, both
pointers set to null. So I need to say like:
as[0..$] = new A();
before accessing .stu
The following program segfaults for me, compiling it with
dmdv2.070 as well as the latest git. I must be doing it wrong.
There's a way to specify class construction, or emplace, or
something. But I can't find it! How do I deal with arrays of
objects?
class A {
int stuff;
}
void main(
On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote:
i believe you can use __traits(getMember) there.
Great! Should have refreshed before sending that reply...
I wonder if mixin("a."~member) is better or worse than
__traits(getMember,a,member)...
This is what I have so far. Using mixin(rawstring~templatearg)
for every time I access the member is kind of cludgy though.
struct A {
string up;
string down;
string left;
string right;
}
template goPlaces(string D1, string D2, string D3) {
string goPlace
object.member lets me access the member of the object, but what
if I want to access those members in a generic way, but in a
different arrangement depending on context? Like if I wanted to
first follow a tree down, and second priority would be going left
to right, but then I wanted to first go
On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:
Otherwise, it sounds like a decent enhancement request for DMD.
I know other compilers who do this warning.
It definitely does sound like a decent enhancement request. I
didn't know it wasn't implemented yet, but it should be pretty
When I factor out code from my modules, it really, really often
leaves import statements that just sit there doing nothing,
making it look like my program is more complex than it is. How do
I get warned for leaving those, and a list of which ones I can
safely remove?
On Saturday, 6 February 2016 at 14:15:04 UTC, rsw0x wrote:
I was playing around with alias templates and came across this,
I reduced it to:
---
struct A(alias C c){
auto foo(){
return c.i;
}
}
struct B{
C c;
A!c a;
}
struct C{
int i;
}
---
It gives me a "need 'this' for 'i' of
On Monday, 8 February 2016 at 03:09:53 UTC, Enjoys Math wrote:
was wondering if there's a D
native way of doing it.
That is the D native way of doing it, but you could clean up a
lot of the boilerplate with some more templates. Also, || tests
for exclusion, as in whether something is NOT in
On Saturday, 6 February 2016 at 03:57:16 UTC, Marco Leise wrote:
No, but they could have dtors because they contain malloc'd
data. E.g. string literals that don't live on the GC heap.
Character arrays allocated with glibc malloc are immutable? News
to me...
On Saturday, 6 February 2016 at 14:25:21 UTC, Ola Fosheim Grøstad
wrote:
See, even Python supports this. :-)
And D supports the "with" statement in python, in the form of
"scope()" statements. The D way is slightly less misleading too,
as
with somethingThatFails() as e:
print(e)
doesn't
On Saturday, 6 February 2016 at 10:29:32 UTC, Ola Fosheim Grøstad
wrote:
This prevents fast GC: Pointers.
Would it be possible to write a fast garbage collector that just
didn't track any pointers? Just offer a head's up that if you use
"this collector" and pointers on collectable data, you'r
On Saturday, 6 February 2016 at 08:24:59 UTC, Jakob Ovrum wrote:
foreach(chunk; File("path/to/file").byChunk(16 * 1024))
Ohh, cool so the streaming...ish logic is in std.stdio now. I
thought that module was only for text output.
I'm not clear on why you aren't allowed to allocate memory with
compile time execution, or why access to the filesystem is
restricted. (Unless you pass -J/ I think?)
On Saturday, 6 February 2016 at 06:39:27 UTC, Marco Leise wrote:
using the template multiple times with the same arguments will
always give you the first instance.
Hmm, consider that the argument was a particular line of code
though, and that's not likely to repeat. I didn't test what would
h
Let's say I have a socket, and a file, and I want to send the
contents of that file to the socket. What's the best way to do
that? Yes I'm aware that in Linux, you can use a combination of a
pipe and splice(2) to keep all buffers kernel side for that, but
I was thinking more generally. The trad
On Friday, 5 February 2016 at 12:35:14 UTC, Artur Skawina wrote:
D's std lib implementations are sometimes really awful, but in
this case it's not actually that bad:
print("hi","there");
->
fwrite("hi", 1, 2, 0x7ff68d0cb640) =
2
fwrite(" ", 1, 1, 0x7ff68d0cb6
On Friday, 5 February 2016 at 08:16:05 UTC, Ola Fosheim Grøstad
wrote:
If you can test for "uncaught_exceptions" you can implement the
equivalent of scope(failure/success) etc within destructors.
Sorry, years of python programming have made me shy of
destructors. It just looks a little less "m
On Friday, 5 February 2016 at 07:44:29 UTC, Rikki Cattermole
wrote:
That code is completely wrong anyway.
Well, obviously it's wrong. If I don't know correct code that
will do what I want, then I can't tell you what I want using
correct code.
But you could do:
alias Derp = TFoo;
Derp obj;
On Friday, 5 February 2016 at 22:18:50 UTC, Marco Leise wrote:
But when you remove items from the table you need to call a
const/immutable dtor that needs to be written for everything
that can be a hash table key.
You need to write destructors for hash keys? How would you use
string literals
I'm guessing I have to use a "mixin" mixin for this, but...
there's no way to do something like this is there?
template TFoo(T) {
struct T {
int a;
int b;
}
T obj;
}
TFoo!Derp;
Derp bar;
Neither templates, nor mixin templates seem capable of this. Easy
enough to use mixin, with tokenize
On Wednesday, 3 February 2016 at 11:09:00 UTC, Ola Fosheim
Grøstad wrote:
Is there some reliable way to detect that a destructor is
called because of exception unwinding?
I basically want to change behaviour within a destructor based
on whether the destructor is called as a result of a regular
On Thursday, 4 February 2016 at 15:32:48 UTC, Artur Skawina wrote:
void print(A...)(A a) {
foreach (N, ref e; a)
write(e, N==A.length-1?"\n":" ");
}
will be unrolled at compile time
Mind if I elaborate on this a bit? If that is unrolled, I
understand it will unroll into
88 matches
Mail list logo