scope/scoped isn't broken, they're just not safe. It's better to have an
unsafe library feature than an unsafe language feature.
Is there a Phobos function to compress all spaces to just one space in a string?
E.g. foo bar
becomes: foo bar
On 02/21/2012 11:27 AM, Daniel Murphy wrote:
scope/scoped isn't broken, they're just not safe. It's better to have an
unsafe library feature than an unsafe language feature.
scope is broken because it is not enforced by the means of
flow-analysis. As a result, it is not safe. Copying it to
On 21/02/12 12:12, Timon Gehr wrote:
On 02/21/2012 11:27 AM, Daniel Murphy wrote:
scope/scoped isn't broken, they're just not safe. It's better to have an
unsafe library feature than an unsafe language feature.
scope is broken because it is not enforced by the means of
flow-analysis. As a
Andrej Mitrovic:
Is there a Phobos function to compress all spaces to just one space in a
string?
E.g. foo bar
becomes: foo bar
import std.string;
void main() {
assert( foo bar .squeeze() == fo bar );
}
Bye,
bearophile
Don Clugston:
Does the library solution actually work the same as the language solution?
Some time ago scoped worked worse than the built-in scope:
http://d.puremagic.com/issues/show_bug.cgi?id=5115
But I don't know how well scoped works now, I have never used it any more.
Bye,
bearophile
interface I {
final int foo(I other, int a, int b) {
return other.foo(a,b) + a*b;
}
int foo(int a, int b);
}
class A : I {
int foo(int a, int b) {
return a*b;
}
}
void main() {
A a = new A;
a.foo(5,5);
Hello everybody.
Today I've tested GDC (on Windows), and a simple Hello World
program results in a 5 MB exe file, while it's only about 200 KB
with DMD. Is this normal? What does GDC (GCC?) put in there, to
make it so big, and why?
Mars
21.02.2012 14:46, Joshua Reusch пишет:
interface I {
final int foo(I other, int a, int b) {
return other.foo(a,b) + a*b;
}
int foo(int a, int b);
}
class A : I {
int foo(int a, int b) {
return a*b;
}
}
void main() {
A a = new A;
a.foo(5,5);
a.I.foo(a, 5,5);
a.foo(a, 5,5); //line 22
}
Oh cool, it even takes an optional parameter. Thanks!
On 2/21/12, bearophile bearophileh...@lycos.com wrote:
Andrej Mitrovic:
Is there a Phobos function to compress all spaces to just one space in a
string?
E.g. foo bar
becomes: foo bar
import std.string;
void main() {
Have you tried to strip executable using --strip or --strip-all?
Il giorno mar, 21/02/2012 alle 13.51 +0100, Mars ha scritto:
Hello everybody.
Today I've tested GDC (on Windows), and a simple Hello World
program results in a 5 MB exe file, while it's only about 200 KB
with DMD. Is this
Using a mixin, is it possible to have it define a method based on
a string passed into the mixin?
An example of what I'm hoping to do:
mixin template make_method(string name) {
void name() { // not sure how to make it become void
bark() here
writeln(hello);
}
}
class Animal
Hi folks,
I've got a Windows service that I'd like to write in D, if possible. I
see that Andrej Mitrovic has provided a binding for the relevant parts of
the Windows API (thanks!):
https://github.com/AndrejMitrovic/DWinProgramming/blob/master/win32/
winsvc.d
Has anyone used this (or another
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote:
Using a mixin, is it possible to have it define a method based
on a string passed into the mixin?
Yeah, though you'll have to build a string of the method.
Something like this:
string make_method_string(string name) {
struct stuff {
private Exception delegate() exceptionBuilder = delegate Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error : delegate
module.stuff.__dgliteral1 function literals cannot be class members
Why is
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote:
Using a mixin, is it possible to have it define a method based
on a string passed into the mixin?
A simpler way:
mixin template MakeMethod(string name)
{
void _MakeMethod_method() { /* ... */ }
mixin(alias
On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote:
struct stuff {
private Exception delegate() exceptionBuilder = delegate
Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error : delegate
On Tuesday, 21 February 2012 at 13:19:11 UTC, Andrea Fontana
wrote:
Have you tried to strip executable using --strip or --strip-all?
Down to 1 MB, a good start, thanks. I guess that's more bearable.
Le 21/02/2012 16:32, Vladimir Panteleev a écrit :
On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote:
struct stuff {
private Exception delegate() exceptionBuilder = delegate Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error :
On 21.02.2012 7:34, James Miller wrote:
On 20 February 2012 21:34, Dmitry Olshanskydmitry.o...@gmail.com wrote:
08.02.2012 13:07, James Miller пишет:
Hi,
I am using std.regex and using the named matches. I would like to be
able to get at the names that have matched, since this is library
A possible workaround is to initialize the delegate
in the object's constructor.
Le 21/02/2012 16:48, Adam D. Ruppe a écrit :
A possible workaround is to initialize the delegate
in the object's constructor.
It is a struct. And struct don't have default constructor. It lead to
very segfault prone code (I did try that).
21.02.2012 17:24, deadalnix пишет:
struct stuff {
private Exception delegate() exceptionBuilder = delegate Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error : delegate
module.stuff.__dgliteral1 function literals cannot be class members
Why
N, it wasn't me. I keep having to tell this to people, it was
taken from http://www.dsource.org/projects/bindings/wiki/WindowsApi
but it often doesn't compile with the latest compiler version so I
keep it updated inside my project.
On Tue, 21 Feb 2012 17:35:34 +0100, Andrej Mitrovic wrote:
N, it wasn't me. I keep having to tell this to people, it was taken
from http://www.dsource.org/projects/bindings/wiki/WindowsApi but it
often doesn't compile with the latest compiler version so I keep it
updated inside my
On 2/21/12, bearophile bearophileh...@lycos.com wrote:
Andrej Mitrovic:
Is there a Phobos function to compress all spaces to just one space in a
string?
E.g. foo bar
becomes: foo bar
import std.string;
void main() {
assert( foo bar .squeeze() == fo
Lots of symbols and stuff.
You can get it down with -ffunction-sections -fdata-sections
-Wl,-s,--gc-sections
Phobos should also be compiled with -ffunction-sections -fdata-sections to
get the whole effect though.
On 2012-02-21 14:15, Mantis wrote:
21.02.2012 14:46, Joshua Reusch пишет:
interface I {
final int foo(I other, int a, int b) {
return other.foo(a,b) + a*b;
}
int foo(int a, int b);
}
class A : I {
int foo(int a, int b) {
return a*b;
}
}
void main() {
A a = new A;
a.foo(5,5);
a.I.foo(a, 5,5);
On 2012-02-21 16:55, deadalnix wrote:
Le 21/02/2012 16:48, Adam D. Ruppe a écrit :
A possible workaround is to initialize the delegate
in the object's constructor.
It is a struct. And struct don't have default constructor. It lead to
very segfault prone code (I did try that).
You can
Awesome. Thanks!
Adam D. Ruppe wrote:
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote:
Using a mixin, is it possible to have it define a method based on a
string passed into the mixin?
Yeah, though you'll have to build a string of the method.
Something like this:
string
On 02/21/2012 09:58 AM, Ali Çehreli wrote:
The reason that I think so is that when the 'I other' is moved to a
parameter location other than the first one, it works:
No, it doesn't work. Sorry for the noise.
Ali
Hello again,
Both methods work as long as the object I call the mixin within
is a struct
struct Test {
mixin MakeMethod!(bark);
}
If I switch struct to class
class Test {
mixin MakeMethod!(bark);
}
it segfaults.
What am I missing?
On Tuesday, 21 February 2012 at 15:29:49 UTC,
On Tuesday, 21 February 2012 at 18:07:34 UTC, Robert Rouse wrote:
What am I missing?
Did you remember to new the class?
class MyClass {}
MyClass a; // a is null right now
a = new MyClass(); // gotta remember this
That's different than structs (or classes in C++)
which work without being
I did not.
Trying to new it gives me a compile error since MyClass a is
not a pointer.
If I define another method without mixin and call it before the
mixin one, it works.
On Tuesday, 21 February 2012 at 18:13:30 UTC, Adam D. Ruppe wrote:
On Tuesday, 21 February 2012 at 18:07:34 UTC,
Nevermind.. I had it as struct playing around and didn't change
it back
On Tuesday, 21 February 2012 at 18:37:02 UTC, Robert Rouse wrote:
I did not.
Trying to new it gives me a compile error since MyClass a is
not a pointer.
If I define another method without mixin and call it before the
On 02/20/2012 10:33 PM, simendsjo wrote:
On Mon, 20 Feb 2012 22:26:58 +0100, Mike Wey mike-...@example.com wrote:
On 02/20/2012 09:49 PM, simendsjo wrote:
On Mon, 20 Feb 2012 21:41:45 +0100, simendsjo simend...@gmail.com
wrote:
I've tried the following using dmd 58 and trunk - both -m64 on
I decided to try using template mixin, but even the simplest program
fails. What's wrong with this code? Error list follows.
DMD64 D Compiler v2.057 OSX 10.6
import std.stdio;
mixin template helpMe()
{
writeln(Satisfying!);
}
void main()
{
mixin helpMe();
}
test.d(5): unexpected ( in
Le 21/02/2012 17:30, Mantis a écrit :
21.02.2012 17:24, deadalnix пишет:
struct stuff {
private Exception delegate() exceptionBuilder = delegate Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error : delegate
module.stuff.__dgliteral1 function
Piggy backing on my other question.
I want to be able to make the name of the method optional in the
argument list. If it doesn't exist, it should get the type name
of the passed in type and lower case it and use it instead.
I tried the following
import std.stdio, std.string;
mixin
On Tuesday, 21 February 2012 at 19:42:42 UTC, Robert Rouse wrote:
mixin(alias _method ~ toLower(typeid(T)) ~ ; );
Try using T.stringof instead of typeid(T).
typeid does a runtime lookup. T.stringof does magic to
get a string representation of the thing at compile time.
Since, in the
21.02.2012 21:42, Robert Rouse пишет:
...
mixin(alias _method ~ toLower(typeid(T)) ~ ; );
...
Try
typeid(T).toString();
or
typeof(T).stringof;
typeid does not return a string type.
On 02/21/2012 10:47 AM, Zach the Mystic wrote:
I decided to try using template mixin, but even the simplest program
fails. What's wrong with this code? Error list follows.
DMD64 D Compiler v2.057 OSX 10.6
import std.stdio;
mixin template helpMe()
{
writeln(Satisfying!);
}
void main()
stringof did it.
I'm still reading through the D programming book, so I guess I
hadn't gotten there yet. I did a search in the book and found a
reference.
I'll read more. Thanks :)
On Tuesday, 21 February 2012 at 19:48:18 UTC, Adam D. Ruppe wrote:
On Tuesday, 21 February 2012 at 19:42:42
On Tue, Feb 21, 2012 at 08:01:18PM +0100, deadalnix wrote:
[...]
But still I think the original code should be an error only if it
use data out of the delegate scope. If it doesn't, frame pointer
doesn't matter and null can be passed.
You could file an enhancement request, if one hasn't
On 2012-02-21 20:53, Ali Çehreli wrote:
On 02/21/2012 10:47 AM, Zach the Mystic wrote:
I decided to try using template mixin, but even the simplest program
fails. What's wrong with this code? Error list follows.
DMD64 D Compiler v2.057 OSX 10.6
import std.stdio;
mixin template
On 02/21/2012 01:53 PM, Ali Çehreli wrote:
According to the docs, template mixins can have only declarations but
helpMe above has a statement.
http://dlang.org/template-mixin.html
Ali
come to think of it, I've occasionally wished for statement mixins. This
would make a good enhancement
That last one looks a lot better than my solution. It's certainly a lot clearer.
One problem I discovered with using templates was that I ended up needing
virtual
functions, which means that I had to convert the template functions to mixins
and
just instantiate them for each type (at least
I apologize for what I'm sure is a very basic question. How
should I do this elegantly?
bool set[char[]];
//Stuff
char[][] words = set.keys;
It gives the error:
Error: cannot implicitly convert expression (set.keys()) of type
const(char)[][] to char[][]
and I'm not
On 22 February 2012 04:45, Dmitry Olshansky dmitry.o...@gmail.com wrote:
On 21.02.2012 7:34, James Miller wrote:
On 20 February 2012 21:34, Dmitry Olshanskydmitry.o...@gmail.com wrote:
08.02.2012 13:07, James Miller пишет:
Hi,
I am using std.regex and using the named matches. I would
If you have a const array, you can create a non-const copy of the array using
the
.dup property of the array. The reason that you need this is that dynamic-length
arrays share data when you assign them between variables, and you can't have a
non-const variable using something else's const data
BLM:
const(char)[][] words = set.keys.sort;
Converting the function's return type to const and doing this did
what I wanted elegantly, I didn't realise I could apply sort to a
const like this.
Trying to use .dup like this:
char[][] words = set.keys.dup;
gives this error
I'm working on a project where I'm using overloaded virtual methods, and I've
run into a challenge with overload sets.
My code looks something like this:
class Base {
void get(ubyte b) {};
}
class Derived: Base {
//alias Base.get get;
void get(string s) {};
}
I've tried using an alias
On Wednesday, February 22, 2012 03:07:38 ixid wrote:
BLM:
const(char)[][] words = set.keys.sort;
Converting the function's return type to const and doing this did
what I wanted elegantly, I didn't realise I could apply sort to a
const like this.
Trying to use .dup like this:
char[][]
On Wednesday, February 22, 2012 02:21:43 BLM wrote:
I'm working on a project where I'm using overloaded virtual methods, and
I've run into a challenge with overload sets.
My code looks something like this:
class Base {
void get(ubyte b) {};
}
class Derived: Base {
//alias Base.get
I tried using override and it complained that the functions weren't overriding
anything. I think that the main problem is that the alias solution was designed
to
allow derived classes to use overloads that had already been defined in the base
class, not for the derived classes to add _new_
On Tuesday, 21 February 2012 at 15:41:58 UTC, deadalnix wrote:
Le 21/02/2012 16:32, Vladimir Panteleev a écrit :
On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote:
struct stuff {
private Exception delegate() exceptionBuilder = delegate
Exception() {
return new Exception(foobar);
On Wednesday, February 22, 2012 02:50:41 BLM wrote:
I tried using override and it complained that the functions weren't
overriding anything. I think that the main problem is that the alias
solution was designed to allow derived classes to use overloads that had
already been defined in the base
On 02/21/2012 06:21 PM, BLM wrote:
I'm working on a project where I'm using overloaded virtual methods, and I've
run into a challenge with overload sets.
My code looks something like this:
class Base {
void get(ubyte b) {};
}
class Derived: Base {
//alias Base.get get;
void get(string
I've submitted it to the DMD developers. Hopefully it won't take too long to get
fixed; it looks like it would be a _fairly_ simple fix to make. (Since when is a
compiler fix simple?)
Thank you, I'll read those articles. Is there a more elegant way
than this to get the string[] out of a range after using the
algorithms sort? Ranges are a bit of a mystery.
string[] temp;
foreach(i;sort(set.keys))
temp ~= to!string(i);
I'm a little worried
class Foo
{
this(int) inout
{ }
Foo makeFoo() { return new Foo(1); }
}
void main() { }
test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
type inout(Foo) to test.Foo
Is this a bug?
Hmm... I guess I'll have to figure out why my code is behaving differently and
put
a test case together. Strange...
Thanks for fixing the semicolons. Old C++ habits die hard, even if one has
written
very little C++ :)
On Wednesday, February 22, 2012 04:42:05 ixid wrote:
Thank you, I'll read those articles. Is there a more elegant way
than this to get the string[] out of a range after using the
algorithms sort? Ranges are a bit of a mystery.
string[] temp;
foreach(i;sort(set.keys))
On 22 February 2012 17:01, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
class Foo
{
this(int) inout
{ }
Foo makeFoo() { return new Foo(1); }
}
void main() { }
test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
type inout(Foo) to test.Foo
Is this a
On 02/21/2012 07:42 PM, ixid wrote:
Ranges are a bit of a mystery.
May I shamelessly recommend the Ranges chapter of my
about-30%-translated book:
http://ddili.org/ders/d.en/ranges.html
I'm a little worried that the very basic level of my posts is spamming
the forum
Not at all! We are
Hmm nevermind. The param type had to be inout, but to do that the ctor
itself has to be inout. Somehow I managed to put the inout specifier
in the wrong place when testing, I did this:
this(inout(void*) obj) { } inout
which is not the same as this:
this(inout(void*) obj) inout { }
Damn specs.
On 2012-02-22 03:39, Jonathan M Davis wrote:
On Wednesday, February 22, 2012 02:21:43 BLM wrote:
I'm working on a project where I'm using overloaded virtual methods, and
I've run into a challenge with overload sets.
My code looks something like this:
class Base {
void get(ubyte b) {};
}
On Wednesday, February 22, 2012 08:19:09 Jacob Carlborg wrote:
He is overloading, not overriding. You have to start notice the
difference when reading these posts :)
Well, it's both. He's overriding a base class function with a different
signature. So, depending on how the compiler treats
68 matches
Mail list logo