One thing I've been trying to figure out is how to do the
following in D:
class foo
{
string bar();
};
void foo::bar()
{
return hello world!;
}
From what I can gather constructs like this just aren't allowed
in D, but I don't understand why, can anyone explain it please?
I know
On Monday, 10 February 2014 at 15:41:06 UTC, Adam D. Ruppe wrote:
On Monday, 10 February 2014 at 15:35:00 UTC, Patrick D. Jeeves
wrote:
[...]
Is this because it isn't possible to do such things, or
because it would be rather pointless to do so compared to
simpler approaches, (in this case
I'm trying to write a D implementation of Haskell's type level
quicksort[0], but I'm already running into problems with
std.typecons.Typedef. I have tried to translate this Haskell code:
data Zero
data Succ a
-- booleans
data True
data False
-- lists
data Nil
data Cons a b
--
Hi,
one hour trying to get a string out of LPOLESTR*.
What is the correct command to get rgszNames as string?
HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
LCID lcid, DISPID* rgDispId){}
With following command I only get the first character
On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote:
On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
Am 10.02.2014 17:53, schrieb Mike Parker:
On 2/11/2014 1:32 AM, Andre wrote:
Hi,
one hour trying to get a string out of LPOLESTR*.
What is the correct command to get
Adam D. Ruppe:
It just wasn't there but there's some people who think it would
be a good idea to add (including Walter I think) so it might be
in later.
It increases the syntactic variance of D code, and people coming
from C++ will go using it straight (and not just in the uncommon
cases
On Monday, 10 February 2014 at 15:35:00 UTC, Patrick D. Jeeves
wrote:
From what I can gather constructs like this just aren't allowed
in D, but I don't understand why, can anyone explain it please?
http://wiki.dlang.org/DIP47
There is a threadnaught related to the above DIP somewhere. I
On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote:
On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
Am 10.02.2014 17:53, schrieb Mike Parker:
On 2/11/2014 1:32 AM, Andre wrote:
Hi,
one hour trying to get a string out of LPOLESTR*.
What is the correct command to get
On Monday, 10 February 2014 at 00:44:23 UTC, Jesse Phillips wrote:
On Sunday, 9 February 2014 at 21:02:59 UTC, Jeroen Bollen wrote:
I'm building a webserver using the Vibe.d library. Whenever
the user requests a page inside my /images/ folder; I want
them to output this file.
Because there
On Monday, 10 February 2014 at 15:35:00 UTC, Patrick D. Jeeves
wrote:
One thing I've been trying to figure out is how to do the
following in D:
class foo
{
string bar();
};
void foo::bar()
{
return hello world!;
}
From what I can gather constructs like this just aren't allowed
in D,
Meta:
alias One = Typedef!(Succ!Zero);
alias Two = Typedef!(Succ!One);
alias Three = Typedef!(Succ!Two);
alias Four = Typedef!(Succ!Three);
Note that you need a cookie for those Typedefs, otherwise they
are not useful. Unless this gets implemented:
On Monday, 10 February 2014 at 17:12:11 UTC, Meta wrote:
I tried defining a static opCall in the Zero struct that
doesn't take any arguments, but that didn't make a difference.
I'm guessing this is a bug with Typedef, but does anyone have
an idea of where that bug might be?
I would say it's
On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
Am 10.02.2014 17:53, schrieb Mike Parker:
On 2/11/2014 1:32 AM, Andre wrote:
Hi,
one hour trying to get a string out of LPOLESTR*.
What is the correct command to get rgszNames as string?
HRESULT GetIDsOfNames(REFIID riid, LPOLESTR*
Am 10.02.2014 18:54, schrieb John Colvin:
On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote:
On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
Am 10.02.2014 17:53, schrieb Mike Parker:
On 2/11/2014 1:32 AM, Andre wrote:
Hi,
one hour trying to get a string out of
Note that you need a cookie for those Typedefs, otherwise
they are not useful. Unless this gets implemented:
http://d.puremagic.com/issues/show_bug.cgi?id=12100
See also:
http://d.puremagic.com/issues/show_bug.cgi?id=11828
Bye,
bearophile
There is some discussion in the Rust Reddit, as Rust since some
time has some benchmarks on the Computer Game site:
http://www.reddit.com/r/rust/comments/1xcq1q/c_gcc_vs_rust_wtf/
The source code of the Rust benchmarks is probably here:
https://github.com/mozilla/rust/tree/master/src/test/bench
On Mon, 10 Feb 2014 16:47:34 -0500, Ty Overby t...@pre-alpha.com wrote:
So I'm using a std.container.Array for storing systems in my program,
and I need to search through the array to find the system that I want to
remove and then shift from that.
In Java I'd write
ArrayListSystem
I'm writing a freelist for storing structs in which memory is
kept around after it is explicitly freed by the client. I'm
using std.conv.emplace with manual memory management, but I need
to call the destructor on the memory right when the caller tries
to free.
So I'm using a std.container.Array for storing systems in my
program, and I need to search through the array to find the
system that I want to remove and then shift from that.
In Java I'd write
ArrayListSystem systems;
systems.remove(system);
And in D I was hoping to write
On Monday, February 10, 2014 12:21:20 Dicebot wrote:
I was speaking about _both_ scoped and selective imports.
Well, personally, I'd _never_ use a scoped selective import. At that point,
you have the whole function body in front of you, so it should be obvious what
was being used from the
On Monday, 10 February 2014 at 17:54:14 UTC, John Colvin wrote:
Or if you're sure you don't have any wide characters:
auto rgszNamesStr = to!string(rgszNames[0][0 ..
wcslen(rgszNames[0])]);
to!string on a well-formed UTF-16 string is always safe. It will
transcode to UTF-8.
On 02/10/2014 02:02 PM, Ty Overby wrote:
I'm writing a freelist for storing structs in which memory is kept
around after it is explicitly freed by the client. I'm using
std.conv.emplace with manual memory management, but I need to call the
destructor on the memory right when the caller tries to
Wow! This is GREAT stuff. My use-case is slightly more complex,
and I'm not sure how to best apply this knowledge. The retro
reverses the array which is problematic in itself as well as
losing the starting index location. I have an array that I'd like
to elegantly rotate. Best way I can show
On Mon, 10 Feb 2014 16:54:58 -0500, Steven Schveighoffer
schvei...@yahoo.com wrote:
Typically in STL, you use partition and then delete the partitioned
elements.
Sorry, I think it's remove (the STL function).
-Steve
On Monday, 10 February 2014 at 21:47:35 UTC, Ty Overby wrote:
I have to be missing something really basic. It couldn't
possibly be this hard to remove an element from an array.
I think the correct solution is:
systems.linearRemove(systems[].find(system)[0 .. 1]);
Usually containers have an
If I define a struct, and I want to pass a string to a function
with a parameter of type that very struct, is there any way to
arrange that an implicit conversion occurs, assuming a function
that maps a string to that struct type exists?
struct data { }
void f( data x) { }
On Tuesday, 11 February 2014 at 03:45:30 UTC, Carl Sturtivant
wrote:
If I define a struct, and I want to pass a string to a function
with a parameter of type that very struct, is there any way to
arrange that an implicit conversion occurs, assuming a function
that maps a string to that struct
On Tuesday, 11 February 2014 at 03:53:05 UTC, Nick Sabalausky
wrote:
I don't suppose there's a way to change the default exception
handler without using a modified druntime
I'm pretty sure there used to be, but not anymore looking at the
source. The d_run_main function has a hardcoded catch
I don't suppose there's a way to change the default exception handler
without using a modified druntime? I'm not seeing one in the docs, but I
could have overlooked something.
Replacing a druntime function at link-time wouldn't be ideal because
then druntime's handler couldn't be called as a
Jesse Phillips wrote in message
news:vaatltklsmbmdnabo...@forum.dlang.org...
Wish it would work with @safe and nothrow too, granted writeln should
eventually be @safe/trusted anyway.
I just travelled back in time and granted your wish!
int x;
int* p;
void main() pure nothrow @safe
{
auto data = [1,2,3];
assert( data.cycle.rotate(2) == [3,1,2] );
assert( data.cycle.rotate(-2) == [2,3,1] );
It's not of immediate help, but it might trigger other answers.
Matlab offers this for multi-dimensional arrays:
http://www.mathworks.nl/help/matlab/ref/circshift.html
On 2/10/2014 10:57 PM, Adam D. Ruppe wrote:
On Tuesday, 11 February 2014 at 03:53:05 UTC, Nick Sabalausky wrote:
I don't suppose there's a way to change the default exception handler
without using a modified druntime
I'm pretty sure there used to be, but not anymore looking at the source.
The
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more complex,
and I'm not sure how to best apply this knowledge. The retro
reverses the array which is problematic in itself as well as
losing the starting index location. I
On Tuesday, 11 February 2014 at 09:10:16 UTC, Andrea Fontana
wrote:
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more
complex, and I'm not sure how to best apply this knowledge.
The retro reverses the array which is
Things like this should just work..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line; range.take(4)) //Error: cannot infer argument types
{
..etc..
}
range.popFront();
}
Tried adding 'int' and 'char[]' or 'auto' .. no dice.
On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
Things like this should just work..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line; range.take(4)) //Error: cannot infer
argument types
{
..etc..
}
On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
Things like this should just work..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line; range.take(4)) //Error: cannot infer
argument types
{
..etc..
}
On Monday, 10 February 2014 at 22:06:14 UTC, Jakob Ovrum wrote:
On Monday, 10 February 2014 at 17:54:14 UTC, John Colvin wrote:
Or if you're sure you don't have any wide characters:
auto rgszNamesStr = to!string(rgszNames[0][0 ..
wcslen(rgszNames[0])]);
to!string on a well-formed UTF-16
On Tue, 11 Feb 2014 10:52:39 -, Tobias Pankrath tob...@pankrath.net
wrote:
Further, the naive solution of adding .array gets you in all sorts of
trouble :p (The whole byLine buffer re-use issue).
This should be simple and easy, dare I say it trivial.. or am I just
being dense here.
On Tue, 11 Feb 2014 10:58:17 -, Tobias Pankrath tob...@pankrath.net
wrote:
On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
Things like this should just work..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line;
On Tuesday, 11 February 2014 at 13:00:19 UTC, Regan Heath wrote:
import std.stdio;
struct S1 {
private int[] elements = [9,8,7];
int opApply (int delegate (ref uint, ref int) block) {
foreach (uint i, int n ; this.elements)
block(i, n);
return 0;
}
}
void
On Tuesday, 11 February 2014 at 03:45:30 UTC, Carl Sturtivant
wrote:
If I define a struct, and I want to pass a string to a function
with a parameter of type that very struct, is there any way to
arrange that an implicit conversion occurs, assuming a function
that maps a string to that
On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
Things like this should just work..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line; range.take(4)) //Error: cannot infer
argument types
{
..etc..
}
On Tuesday, 11 February 2014 at 03:50:16 UTC, Adam D. Ruppe wrote:
On Tuesday, 11 February 2014 at 03:45:30 UTC, Carl Sturtivant
wrote:
If I define a struct, and I want to pass a string to a
function with a parameter of type that very struct, is there
any way to arrange that an implicit
With a class you can do this:
class Data
{
string s;
this(string s)
{
this.s = s;
}
}
void f(Data x ...)
{
import std.stdio;
writeln(x.s);
}
void main()
{
f(hello); //convert argument implicitly to type `data`.
}
See Typesafe
On Tuesday, 11 February 2014 at 16:26:06 UTC, Rene Zwanenburg
wrote:
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more
complex, and I'm not sure how to best apply this knowledge.
The retro reverses the array which is
On Tuesday, 11 February 2014 at 05:09:13 UTC, Nick Sabalausky
wrote:
mixin(handleFail!(() = {
...user code...
}));
BTW the ()= there is unnecessary; when there's no arguments, you
can just write { code } and it will be recognized as a
function/delegate. So this would work
On Tuesday, 11 February 2014 at 14:47:31 UTC, Carl Sturtivant
wrote:
With a class you can do this:
class Data
{
string s;
this(string s)
{
this.s = s;
}
}
void f(Data x ...)
{
import std.stdio;
writeln(x.s);
}
void main()
{
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more complex,
and I'm not sure how to best apply this knowledge. The retro
reverses the array which is problematic in itself as well as
losing the starting index location. I
On Tuesday, 11 February 2014 at 16:30:42 UTC, Rene Zwanenburg
wrote:
On Tuesday, 11 February 2014 at 16:26:06 UTC, Rene Zwanenburg
wrote:
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more
complex, and I'm not sure how to
On 02/11/2014 06:25 AM, Rene Zwanenburg wrote:
On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
foreach (i, line; range.take(4)) //Error: cannot infer argument types
{
..etc..
}
foreach (i, line; iota(size_t.max).zip(range.take(4)))
{
}
There is also the
On Tuesday, 11 February 2014 at 10:52:40 UTC, Tobias Pankrath
wrote:
The second naive solution would be to use readText and
splitLines.
That's the sort of thing I always do because then I understand
what's going on, and when there's a bug I can find it easily!
But then I'm not writing
On 2014-02-11 06:09, Nick Sabalausky wrote:
I don't strictly *need* to. But if you're curious, here's the story:
I like to use a little custom exception (Fail) in shell script-like
stuff to bail out and exit with a given error message in an
exception-safe way. This is for expected failure
On Tuesday, 11 February 2014 at 21:16:34 UTC, Joseph Rushton
Wakeling wrote:
I take it the error is because the makefile tries to build
using ../dmd/src/dmd (which exists, I've built it) but can't
find the corresponding runtime files.
It looks for ../druntime - this is where object.di is
On Tuesday, 11 February 2014 at 22:10:21 UTC, Joseph Rushton
Wakeling wrote:
Exactly what I thought, but they _have_ been built and they are
located in the right places. That's why I was baffled by the
error message.
../dmd/src/dmd -I../druntime/src -I../phobos rdmd.d
;)
On 11/02/14 23:10, Joseph Rushton Wakeling wrote:
On 11/02/14 22:22, Dicebot wrote:
It looks for ../druntime - this is where object.di is located, not in compiler
repo. You need all of those - dmd, druntime and phobos build before tools.
Exactly what I thought, but they _have_ been built and
On 11/02/14 23:18, Dicebot wrote:
On Tuesday, 11 February 2014 at 22:10:21 UTC, Joseph Rushton Wakeling wrote:
Exactly what I thought, but they _have_ been built and they are located in the
right places. That's why I was baffled by the error message.
../dmd/src/dmd -I../druntime/src
On 11/02/14 23:33, Joseph Rushton Wakeling wrote:
On 11/02/14 23:18, Dicebot wrote:
On Tuesday, 11 February 2014 at 22:10:21 UTC, Joseph Rushton Wakeling wrote:
Exactly what I thought, but they _have_ been built and they are located in the
right places. That's why I was baffled by the error
On Tuesday, 11 February 2014 at 07:52:57 UTC, Daniel Murphy wrote:
Jesse Phillips wrote in message
news:vaatltklsmbmdnabo...@forum.dlang.org...
Wish it would work with @safe and nothrow too, granted writeln
should eventually be @safe/trusted anyway.
I just travelled back in time and
On 2/11/2014 10:00 AM, Adam D. Ruppe wrote:
So this would work too:
int handleError(void delegate() dg) {
try dg();
catch(Throwable t) return 1;
return 0;
}
int main() {
return handleError({
});
}
Oh yea, good point. That's not bad at all;
Adam D. Ruppe:
int handleError(void delegate() dg) {
try dg();
catch(Throwable t) return 1;
Is it possible to use a lazy argument there? And isn't it better
to catch Exception only?
Bye,
bearophile
On 2/11/2014 6:35 PM, Sean Kelly wrote:
Throw a static exception (maybe even derived directly from Throwable),
similar to OutOfMemory, with a custom toString. That should eliminate
the formatting you don't like and will prevent the trace from occurring
as well (see rt/deh.d in Druntime--the
Ooo.. I like the drop and take approach! I wonder if this could
be something that makes it into the standard library
(std.range?). What would be the best way to approach in
suggesting that?
Why not drop and take?
http://dpaste.dzfl.pl/0649b809c81e
On Tuesday, 11 February 2014 at 19:15:25 UTC, Philippe Sigaud
wrote:
On Tue, Feb 11, 2014 at 1:05 AM, Namespace
rswhi...@googlemail.com wrote:
static opCall(int i)(int j, int k)
{
return Foo(i+j,i+k);
}
auto bob = Foo!(1)(2,3); //Error:
On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley
wrote:
Here's the gist of what I'm trying to do:
struct Foo
{
public:
int i;
int j;
static opCall(int i)(int j, int k)
{
return Foo(i+j,i+k);
}
}
void main()
{
auto bob
On Tuesday, 11 February 2014 at 19:48:41 UTC, Jesse Phillips
wrote:
In case the other replies weren't clear enough. A range does
not have an index.
What do you expect 'i' to be?
In case of foreach(i, x; range) I would expect it to be iteration
number of this particular foreach. I miss it
On Wednesday, 12 February 2014 at 01:59:54 UTC, Frustrated wrote:
On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley
wrote:
Here's the gist of what I'm trying to do:
struct Foo
{
public:
int i;
int j;
static opCall(int i)(int j, int k)
{
On Wednesday, 25 December 2013 at 17:14:17 UTC, David Eagen wrote:
I've filed a bug:
https://issues.apache.org/jira/browse/THRIFT-2294
So the Thrift guys are not too excited about fixing this. The bug
was closed since it affected just the D library.
I think the problem stems from the fact
On Wednesday, 12 February 2014 at 02:27:51 UTC, David Eagen wrote:
You can convert back to the serial test harness by setting this
in configure.ac:
AM_INIT_AUTOMAKE([1.11 tar-ustar serial-tests])
I should have pointed out that using the serial-tests option with
automake 1.13 results in a
On Wednesday, 12 February 2014 at 01:07:31 UTC, Nick Sabalausky
wrote:
Oh, interesting. Is this something that can be relied on
long-term? Ie, is a static non-Exception Throwable deliberately
*supposed* to not include a stack trace, or is it potentially
more of a currently-missing feature?
On Wednesday, 12 February 2014 at 01:08:42 UTC, bearophile wrote:
Is it possible to use a lazy argument there?
I think it depends on the task. To just wrap generic code though
a delegate seems most straightforward.
And isn't it better to catch Exception only?
Perhaps, or the specific
On 2/11/2014 6:35 PM, Sean Kelly wrote:
Throw a static exception (maybe even derived directly from Throwable),
I assume then that throwing something directly derived from Throwable
would still run cleanup code (like scope guards and finally) like
throwing Exception would? Or is it like
On 2/11/2014 6:35 PM, Sean Kelly wrote:
Throw a static exception (maybe even derived directly from Throwable),
similar to OutOfMemory, with a custom toString. That should eliminate
the formatting you don't like and will prevent the trace from occurring
as well (see rt/deh.d in Druntime--the
On Wednesday, 12 February 2014 at 02:27:51 UTC, David Eagen wrote:
On Wednesday, 25 December 2013 at 17:14:17 UTC, David Eagen
wrote:
I've filed a bug:
https://issues.apache.org/jira/browse/THRIFT-2294
So the Thrift guys are not too excited about fixing this. The
bug was closed since it
74 matches
Mail list logo