On Thursday, 31 October 2013 at 22:03:18 UTC, Namespace wrote:
The 'it' property is only some 'singleton' approach.
You can write:
void foo() {
auto buffer = Mallocator.allocate(42);
/// ... many code
}
And at the end of the scope buffer is cleared because
Mallocator's destructor call
On 10/31/2013 08:29 PM, Daniel Davidson wrote:
The following crashes on writeln, but looks reasonable. Is some form of
initializing ctor required for RateCurve?
import std.datetime;
import std.range;
import std.stdio;
struct DateRate {
Date date;
double value = 0.0;
}
struct RateCurve {
The following crashes on writeln, but looks reasonable. Is some
form of initializing ctor required for RateCurve?
import std.datetime;
import std.range;
import std.stdio;
struct DateRate {
Date date;
double value = 0.0;
}
struct RateCurve {
private immutable(DateRate)[] _data;
}
struct
On Thursday, 31 October 2013 at 02:45:36 UTC, Wolftein wrote:
so my question is, is it possible to build an associative array
at compile-time?
Yes, by using ctfe it's possible.
like so:
enum int[string] aa = createAA();
auto createAA()
{
int[string] aa;
aa["hello"] = 1;
On Thursday, 31 October 2013 at 23:48:19 UTC, Jonathan M Davis
wrote:
On Thursday, October 31, 2013 23:06:22 Namespace wrote:
On Thursday, 31 October 2013 at 09:53:39 UTC, Jonathan M Davis
wrote:
> On Thursday, October 31, 2013 10:15:51 Namespace wrote:
>> I'm sure we had already this conversat
On Thursday, October 31, 2013 23:06:22 Namespace wrote:
> On Thursday, 31 October 2013 at 09:53:39 UTC, Jonathan M Davis
>
> wrote:
> > On Thursday, October 31, 2013 10:15:51 Namespace wrote:
> >> I'm sure we had already this conversation but I don't find the
> >> thread.
> >>
> >> T[] buffer = n
On Thursday, October 31, 2013 14:46:29 Timothee Cour wrote:
> well it can be made to work with following rule:
>
> $ binds as follows, using the 1st pattern matched rule:
>
> very roughly:
>
> identifier [$] if typeof(a.length) => a[a.length] //likewise with s/[]/()/
> primary_expression . ident
On Thursday, 31 October 2013 at 09:53:39 UTC, Jonathan M Davis
wrote:
On Thursday, October 31, 2013 10:15:51 Namespace wrote:
I'm sure we had already this conversation but I don't find the
thread.
T[] buffer = new T[N]; assumes more space than stated (in
average
2010 elements more. See: http:
well it can be made to work with following rule:
$ binds as follows, using the 1st pattern matched rule:
very roughly:
identifier [$] if typeof(a.length) => a[a.length] //likewise with s/[]/()/
primary_expression . identifier if typeof(primary_expression.length)
=> primary_expression . identifie
The 'it' property is only some 'singleton' approach.
You can write:
void foo() {
auto buffer = Mallocator.allocate(42);
/// ... many code
}
And at the end of the scope buffer is cleared because
Mallocator's destructor call deallocateAll (if I'm not wrong).
On 10/31/2013 02:19 PM, Ali Çehreli wrote:
> Y Combinator? (No, I have not solved it yet. :) )
http://rosettacode.org/wiki/Y_combinator#D
Ok, I was actually trying to find the following one:
https://github.com/gecko0307/atrium/blob/master/dlib/functional/combinators.d
Ali
On 10/31/2013 12:09 PM, David Nadlinger wrote:
A while back, somebody raised the topic of implementing a lazy range for
traversing/flattening a tree structure on #d.
The obvious (in terms of Phobos primitives) solution would be something
along the lines of this:
---
struct Node(T) {
T val;
On Thursday, October 31, 2013 20:39:36 bearophile wrote:
> Wolftein:
> > Assertion failure: '0' on line 1215 in file 'glue.c'
> >
> > When trying to compile this:
> >
> > TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
> > _ownerList;
> >
> > Is that a compiler bug or i'm doing some
On 2013-10-31 14:47, ilya-stromberg wrote:
John, It's interesting if you can connect to the MS SQL.
Just use FreeTDS, nothing special about it. See:
http://forum.dlang.org/thread/l403bf$139g$1...@digitalmars.com#post-l4089g:241723:241:40digitalmars.com
--
/Jacob Carlborg
On Thu, Oct 31, 2013 at 01:28:13PM -0700, Ali Çehreli wrote:
> On 10/31/2013 01:10 PM, Marco Leise wrote:
> >Am Thu, 31 Oct 2013 10:42:35 +0100
> >schrieb "Namespace" :
> >
> >>On Thursday, 31 October 2013 at 09:27:11 UTC, bearophile wrote:
> >>>In Python if you append items to an array, it sovra-a
On 10/31/2013 01:10 PM, Marco Leise wrote:
Am Thu, 31 Oct 2013 10:42:35 +0100
schrieb "Namespace" :
On Thursday, 31 October 2013 at 09:27:11 UTC, bearophile wrote:
In Python if you append items to an array, it sovra-allocates,
Never heard of 'sovra'. What does it mean?
That's bearophilian f
Am Thu, 31 Oct 2013 10:42:35 +0100
schrieb "Namespace" :
> On Thursday, 31 October 2013 at 09:27:11 UTC, bearophile wrote:
> > In Python if you append items to an array, it sovra-allocates,
> Never heard of 'sovra'. What does it mean?
That's bearophilian for 'over'. :p
--
Marco
Below is a solution to get it to work as a C binding.
- Your structure should not be enclosed in the `extern (C)`
block; leave it as regular D code.
- cppcall should be declared `extern (C)` in D and `extern "C"`
in C++;
- depending on your platform, you need to link to the C++
standard lib ;
Am Thu, 31 Oct 2013 02:52:49 -0700
schrieb Jonathan M Davis :
> On Thursday, October 31, 2013 10:15:51 Namespace wrote:
> > I'm sure we had already this conversation but I don't find the
> > thread.
> >
> > T[] buffer = new T[N]; assumes more space than stated (in average
> > 2010 elements more.
alias sum(T) = curry!(reduce!q{a + b}, cast(T)0);
double euclidDistance(double[] xs, double[] ys)
in {
assert(xs.length == ys.length);
} body {
return zip(xs, ys)
.map!(xy => (xy[0] - xy[1]) ^^ 2)
.sum!double
.sqrt;
}
void main() {
auto xs = [0.0, 1.
On Thursday, 31 October 2013 at 19:48:19 UTC, Wolftein wrote:
On Thursday, 31 October 2013 at 19:39:37 UTC, bearophile wrote:
Wolftein:
Assertion failure: '0' on line 1215 in file 'glue.c'
When trying to compile this:
TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
_ownerList;
On Thursday, 31 October 2013 at 19:23:56 UTC, Philippe Sigaud
wrote:
I think reduce takes two arguments: the growing seed and the
current front.
You're trying to get (a[0]-b[0])^^2 + (a[1]-b[1])^^2 + ...,
right?
Yep. The (e[1]-e[0])*(e[1]-e[0]) bit was, I supposed was
effectively
calculating (a
Craig Dillabaugh:
I know I could use a simple foreach loop with my zip command, or
even std.numeric.euclidean( ... ), but I am trying to be cute
here!
import std.stdio, std.algorithm, std.range, std.math,
std.functional;
alias sum(T) = curry!(reduce!q{a + b}, cast(T)0);
double euclidDista
On Thursday, 31 October 2013 at 19:39:37 UTC, bearophile wrote:
Wolftein:
Assertion failure: '0' on line 1215 in file 'glue.c'
When trying to compile this:
TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
_ownerList;
Is that a compiler bug or i'm doing something that i don't
s
On Thursday, October 31, 2013 20:30:25 Wolftein wrote:
> Assertion failure: '0' on line 1215 in file 'glue.c'
>
> When trying to compile this:
>
> TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
> _ownerList;
>
> Is that a compiler bug or i'm doing something that i don't
> suppose t
Wolftein:
Assertion failure: '0' on line 1215 in file 'glue.c'
When trying to compile this:
TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
_ownerList;
Is that a compiler bug or i'm doing something that i don't
suppose to do.
It seems both a compiler bug fit for bugzilla, an
On Thursday, October 31, 2013 15:03:26 Daniel Davidson wrote:
> Given this code:
>
> import plus.tvm.rate_curve;
> struct T {
> RateCurve m;
> }
> struct S {
> const(T) rc;
> }
>
> I get this error: Error: mutable method
> plus.models.dossier.__unittestL42_1.T.__fieldPostBlit is not
> callable us
Assertion failure: '0' on line 1215 in file 'glue.c'
When trying to compile this:
TypeTuple!(void delegate(Event), EventPriority, ulong)[uint]
_ownerList;
Is that a compiler bug or i'm doing something that i don't
suppose to do.
I think reduce takes two arguments: the growing seed and the current front.
You're trying to get (a[0]-b[0])^^2 + (a[1]-b[1])^^2 + ..., right?
Try this:
module euclid;
import std.stdio;
double euclid_dist( double[] pt1, double[] pt2 ) {
assert( pt1.length == pt2.length );
import std.al
I am trying to calculate the Euclidean Distance between two
points. I currently have the following function (that doesn't
compile):
double euclid_dist( double[] pt1, double[] pt2 ) {
assert( pt1.length == pt2.length );
return sqrt(
zip(pt1, pt2).reduce!(function(e) { return
(e[1]-e[0]
On Thursday, 31 October 2013 at 18:51:46 UTC, bearophile wrote:
Maxim Fomin:
You can check whether data is on heap, stack, tls, or just
global object by inspecting pointer at runtime. Ideally there
would be such function in druntime.
This seems like a nice enhancement request for Bugzilla :-
A while back, somebody raised the topic of implementing a lazy
range for traversing/flattening a tree structure on #d.
The obvious (in terms of Phobos primitives) solution would be
something along the lines of this:
---
struct Node(T) {
T val;
Node!T[] children;
}
auto flatten(T)(Node!T
Hi, I'm new to D and stumbled on the new allocators thread. In
the help there is code like
auto buffer = Mallocator.it.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.it.deallocate(buffer);
which seems redundant and error prone.
Would it not be possible for allocate to automatically
Maxim Fomin:
You can check whether data is on heap, stack, tls, or just
global object by inspecting pointer at runtime. Ideally there
would be such function in druntime.
This seems like a nice enhancement request for Bugzilla :-) Are
you going to open it? It seems useful for me too.
It is
On Thursday, 31 October 2013 at 17:22:07 UTC, Daniel Davidson
wrote:
I'm think you may be correct... but what specifically is
incorrect about the language?
When I see __fieldPostBlit I get the feeling it is more an
implementation issue than the language.
__postblit also looks like implementa
On Thursday, 31 October 2013 at 17:34:21 UTC, Daniel Davidson
wrote:
On Thursday, 31 October 2013 at 16:16:36 UTC, bearophile wrote:
That's wrong code, you are escaping a reference to memory (of
rc variable) allocated in the stack frame of foo(). The D
compiler is not smart enough to recogniz
On Thursday, 31 October 2013 at 16:16:36 UTC, bearophile wrote:
That's wrong code, you are escaping a reference to memory (of
rc variable) allocated in the stack frame of foo(). The D
compiler is not smart enough to recognize the bug. There are
optimizations that patch and avoid this bug (lik
On Thursday, 31 October 2013 at 15:56:45 UTC, Maxim Fomin wrote:
On Thursday, 31 October 2013 at 14:03:28 UTC, Daniel Davidson
wrote:
Given this code:
import plus.tvm.rate_curve;
struct T {
RateCurve m;
}
struct S {
const(T) rc;
}
I get this error: Error: mutable method
plus.models
On Thursday, 31 October 2013 at 15:11:48 UTC, Daniel Davidson
wrote:
The following seems to work, but feels like luck. When foo
returns rc should be taken off the stack. If I recall, in C++
something like this would crash, but why not here?
This ineed runs by luck. In C++ it would not necessar
Daniel Davidson:
import std.stdio;
struct RC {
this(this) { data = data.dup; }
int[] data;
}
struct T {
const(RC) *rc;
void goo() {
writeln("Data is ", rc.data);
}
}
T foo() {
RC rc = { [1,2,3] };
return T(&rc);
}
void main() {
T t = foo();
t.goo();
}
That's wrong code,
On Thursday, 31 October 2013 at 14:03:28 UTC, Daniel Davidson
wrote:
Given this code:
import plus.tvm.rate_curve;
struct T {
RateCurve m;
}
struct S {
const(T) rc;
}
I get this error: Error: mutable method
plus.models.dossier.__unittestL42_1.T.__fieldPostBlit is not
callable
On Thursday, 31 October 2013 at 14:28:31 UTC, bearophile wrote:
Daniel Davidson:
I get this error: Error: mutable method
plus.models.dossier.__unittestL42_1.T.__fieldPostBlit is not
callable using a const object
Related:
http://d.puremagic.com/issues/show_bug.cgi?id=4867
Bye,
bearophile
T
The following seems to work, but feels like luck. When foo
returns rc should be taken off the stack. If I recall, in C++
something like this would crash, but why not here?
import std.stdio;
struct RC {
this(this) { data = data.dup; }
int[] data;
}
struct T {
const(RC) *rc;
void goo() {
Daniel Davidson:
I get this error: Error: mutable method
plus.models.dossier.__unittestL42_1.T.__fieldPostBlit is not
callable using a const object
Related:
http://d.puremagic.com/issues/show_bug.cgi?id=4867
Bye,
bearophile
Given this code:
import plus.tvm.rate_curve;
struct T {
RateCurve m;
}
struct S {
const(T) rc;
}
I get this error: Error: mutable method
plus.models.dossier.__unittestL42_1.T.__fieldPostBlit is not
callable using a const object
Is this fundamentally incorrect? I abandoned i
On Sunday, 27 October 2013 at 00:06:35 UTC, John Joyus wrote:
On 10/25/2013 04:04 AM, Gary Willoughby wrote:
1). Does D has any support for MSSQL?
See here:
http://forum.dlang.org/thread/qcxoafwuachwnnwqk...@forum.dlang.org
Thanks for the link, but what I meant by MSSQL is Microsoft SQL
Se
On Thursday, 31 October 2013 at 13:12:31 UTC, Wolftein wrote:
void delegate(Event)
void delegate(T) Where T is a class that inherits Event.
I'm trying to cast (void delegate(T)) to (void delegate(Event))
to be able to store them in a map, but when i cast them i get
null exeception.
Same thin
void delegate(Event)
void delegate(T) Where T is a class that inherits Event.
I'm trying to cast (void delegate(T)) to (void delegate(Event))
to be able to store them in a map, but when i cast them i get
null exeception.
Same thing for cast things like this
TemplateClass!Plugin
TemplateClass
On Thursday, 31 October 2013 at 13:12:31 UTC, Wolftein wrote:
void delegate(Event)
void delegate(T) Where T is a class that inherits Event.
I'm trying to cast (void delegate(T)) to (void delegate(Event))
to be able to store them in a map, but when i cast them i get
null exeception.
Same thin
Am Thu, 31 Oct 2013 11:58:18 +0100
schrieb "Andrea Fontana" :
> Check this simple code:
>
> import std.stdio;
> import std.conv;
>
> bool is_zero(T)(T i) { return to!int(i) == 0; }
>
> void main() { "0".is_zero.writeln; }
>
> This code print "true" of course.
>
> If you replace "to!int(i) ==
Andrea Fontana:
Shoudn't "0".is_zero give this error too?
Possibly yes. I put this enhancement request in Bugzilla few
months ago, but I don't remember its number now.
Bye,
bearophile
Check this simple code:
import std.stdio;
import std.conv;
bool is_zero(T)(T i) { return to!int(i) == 0; }
void main() { "0".is_zero.writeln; }
This code print "true" of course.
If you replace "to!int(i) == 0" with "i == 0" compiler gives this
error:
"Error: no property 'is_zero' for type
by changeing
T[] makeArray(T,U)(immutable U[] paramArray)
into
T[] makeArray(T,U)(const U paramArray) if (isAggregateType!(U) ||
is Array!(U))
everything works perfectly
Thanks very much
---
Uplink_Coder
On Wednesday, 30 October 2013 at 20:43:54 UTC, qznc wrote:
On Wednesday, 30 October 2013 at 00:20:12 UTC, Stephan
Schiffels wrote:
Hi,
I'd like a version of std.range.chunk that does not require
the range to have the "length" property.
As an example, consider a file that you would like parse
On Thursday, 31 October 2013 at 10:18:25 UTC, Uplink_Coder wrote:
Maybe I shuold be more specific :
for now It's:
T[] arr = makeArray!(T,U)([some,instances,of,U]);
but I would like it to be:
auto arr = makeArray!(T)([some,instances,of,U]);
void foo(T,U)(U arg){}
int a;
foo!(double)(a); //U
On Thursday, October 31, 2013 11:16:35 Namespace wrote:
> Hm, seems not very performant for a *system* language. But fine,
> thanks for your explanation. :)
I believe that C's malloc does the same thing.
- Jonathan M Davis
Maybe I shuold be more specific :
for now It's:
T[] arr = makeArray!(T,U)([some,instances,of,U]);
but I would like it to be:
auto arr = makeArray!(T)([some,instances,of,U]);
On Thursday, 31 October 2013 at 10:12:10 UTC, Jonathan M Davis
wrote:
On Thursday, October 31, 2013 10:59:48 Namespace wrote:
On Thursday, 31 October 2013 at 09:48:23 UTC, safety0ff wrote:
> On Thursday, 31 October 2013 at 09:15:53 UTC, Namespace
> wrote:
>> I'm sure we had already this convers
On Thursday, October 31, 2013 10:59:48 Namespace wrote:
> On Thursday, 31 October 2013 at 09:48:23 UTC, safety0ff wrote:
> > On Thursday, 31 October 2013 at 09:15:53 UTC, Namespace wrote:
> >> I'm sure we had already this conversation but I don't find the
> >> thread.
> >>
> >> T[] buffer = new T[
31-Oct-2013 13:28, bearophile пишет:
Wolftein:
Using --debug or --release works fine. But when i use --profile i get:
c:\Program Files
(x86)\DLang\dmd2\windows\bin\..\..\src\phobos\std\path.d(2187):
Error: balancedParens is not nothrow
c:\Program Files
(x86)\DLang\dmd2\windows\bin\..\..\src\p
On Thursday, 31 October 2013 at 09:48:23 UTC, safety0ff wrote:
On Thursday, 31 October 2013 at 09:15:53 UTC, Namespace wrote:
I'm sure we had already this conversation but I don't find the
thread.
T[] buffer = new T[N]; assumes more space than stated (in
average 2010 elements more. See:
http
On Thursday, October 31, 2013 10:15:51 Namespace wrote:
> I'm sure we had already this conversation but I don't find the
> thread.
>
> T[] buffer = new T[N]; assumes more space than stated (in average
> 2010 elements more. See: http://dpaste.dzfl.pl/af92ad22c). It
> behaves exactly like reserve an
On Thursday, October 31, 2013 02:46:32 Timothee Cour wrote:
> can we support this and similar use cases ?
>
> import std.range;
> void main(){
> auto a=[1,2,3,4];
> auto b1=a.indexed([0,a.length-1]);//OK
> auto b2=a.indexed([0,$-1]);//NG
> }
Aren't you creating new arrays to pass to indexed
On Thursday, 31 October 2013 at 09:15:53 UTC, Namespace wrote:
I'm sure we had already this conversation but I don't find the
thread.
T[] buffer = new T[N]; assumes more space than stated (in
average 2010 elements more. See:
http://dpaste.dzfl.pl/af92ad22c). It behaves exactly like
reserve a
(this is my first post so please alert me to any breaches of
forum etiquette)
Hello,
I have a problem with a helper function I'm writeting.
T[] makeArray(T,U)(immutable U[] paramArray) {
T[] result;
foreach (param;paramArray) {
result ~= T(param);
}
can we support this and similar use cases ?
import std.range;
void main(){
auto a=[1,2,3,4];
auto b1=a.indexed([0,a.length-1]);//OK
auto b2=a.indexed([0,$-1]);//NG
}
On Thursday, 31 October 2013 at 09:27:11 UTC, bearophile wrote:
Namespace:
T[] buffer = new T[N]; assumes more space than stated (in
average 2010 elements more. See:
http://dpaste.dzfl.pl/af92ad22c). It behaves exactly like
reserve and that is IMO wrong. If I reserve memory with
buffer.reser
Namespace:
T[] buffer = new T[N]; assumes more space than stated (in
average 2010 elements more. See:
http://dpaste.dzfl.pl/af92ad22c). It behaves exactly like
reserve and that is IMO wrong. If I reserve memory with
buffer.reserve(N), I want to have at least N elements. That
behaviour is cor
Wolftein:
Using --debug or --release works fine. But when i use --profile
i get:
c:\Program Files
(x86)\DLang\dmd2\windows\bin\..\..\src\phobos\std\path.d(2187):
Error: balancedParens is not nothrow
c:\Program Files
(x86)\DLang\dmd2\windows\bin\..\..\src\phobos\std\path.d(2188):
Error: b
I'm sure we had already this conversation but I don't find the
thread.
T[] buffer = new T[N]; assumes more space than stated (in average
2010 elements more. See: http://dpaste.dzfl.pl/af92ad22c). It
behaves exactly like reserve and that is IMO wrong. If I reserve
memory with buffer.reserve(N)
70 matches
Mail list logo