On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote:
wow, that's interesting :-) Is it the idiomatic approach to
initiate immutable objects lazily? Or do people use data class
with immutable fields and generate a companion builder class at
compile time?
There's no real idiomatic approach,
On Sunday, 13 July 2014 at 19:06:29 UTC, Timon Gehr wrote:
On 07/13/2014 08:51 PM, Meta wrote:
That's weird, I always assumed this worked. Was it always the
case that
numeric types can't be implicitly casted to bool?
Yes, unless their range fits into [0,2).
It seems that not even that is
On Sunday, 13 July 2014 at 11:18:05 UTC, bearophile wrote:
The idea of not making std.algorithm.among!() a predicate was
not so good:
void main() {
import std.stdio, std.algorithm;
auto s = "hello how\nare you";
s.until!(c => c.among!('\n', '\r')).writeln;
}
(A normal workaround
On Monday, 7 July 2014 at 23:47:26 UTC, Aerolite wrote:
Hey all,
I've not posted here in a while, but I've been keeping up to
speed with D's progress over the last couple of years and
remain consistently impressed with the language.
I'm part of a new computing society in the University of
N
On Tuesday, 8 July 2014 at 18:45:21 UTC, Remo wrote:
On Tuesday, 8 July 2014 at 18:29:40 UTC, Meta wrote:
On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote:
How to make something that work like std::tie in D2 ?
Tuple!(float, float) sinCos(float n) {
return tuple(cast(float)sin(n), cast(floa
On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote:
How to make something that work like std::tie in D2 ?
Tuple!(float, float) sinCos(float n) {
return tuple(cast(float)sin(n), cast(float)cos(n)); //please
note cast(float)!
}
int main(string[] argv) {
float s,c;
tie!(s,c) = sinCos(3.0f)
On Tuesday, 8 July 2014 at 12:42:44 UTC, NCrashed wrote:
Oops, I forgot shared at new. But the major issue is that
doesn't fix the problem:
```
import std.range;
class A {}
InputRange!(shared A) foo()
{
return [new shared A].inputRangeObject;
}
void bar()
{
auto res = foo.arra
On Monday, 7 July 2014 at 19:20:24 UTC, Fr wrote:
It's in the example above :
SortedRange!(MyObject[]) opSlice() {
sequence[].array.assumeSorted; }
I thought that that using ".array" would lead to instantiating
something.
Yes, this *will* instantiate an array and copy all of the items
fro
On Monday, 7 July 2014 at 09:53:22 UTC, NCrashed wrote:
I am using ranges (wrapped in InputRangeObject for use in
interfaces) of shared objects, with new beta some cases are
broken:
```
import std.range;
class A {}
InputRange!(shared A) foo()
{
return [new A].inputRangeObject;
}
void
On Monday, 7 July 2014 at 12:06:21 UTC, Frédérik wrote:
Hi all,
I'm discovering the D language that seems very nice in many
aspects, but I'm quite confused by the container and range APIs
while trying to design a very simple interface-oriented API.
Especially I can't figure out how std.containe
On Thursday, 26 June 2014 at 07:11:03 UTC, Uranuz wrote:
But if I write
@("hello") struct Hello {}
so all of the variables that have type Hello will have
attribute @("hello") like come type qualifier because attribute
is a part of declaration of Hello. Do I understand correctly?
No, it is o
On Thursday, 26 June 2014 at 09:21:28 UTC, seany wrote:
On Wednesday, 25 June 2014 at 14:17:50 UTC, Meta wrote:
If you want something like a hash table that preserves
insertion order, you could try using an array of tuples
instead. Then to "pop" the first element, just do 'arr =
arr[1..$]'.
On Wednesday, 25 June 2014 at 20:17:35 UTC, rcor wrote:
I'm trying to create a set of utility functions that cache
objects of various types loaded from json files, but having
trouble testing it. One function I'd like to test uses new to
instantiate an object based on a compile-time parameter:
On Wednesday, 25 June 2014 at 09:30:54 UTC, seany wrote:
Given an assosiative array : int[string] k, is there a way
(either phobos or tango) to pop the first element of this array
and append it to another array?
I can come up with a primitive soluiton:
int[string] k;
// populate k here
int[s
On Tuesday, 24 June 2014 at 10:11:05 UTC, bearophile wrote:
I don't think it's solved. There are probably bugs worth
reporting here.
I have not found them, sorry for the noise.
Bye,
bearophile
This looks really bad. I thought we weren't going to allow
variable templates, just enums and alia
On Monday, 23 June 2014 at 22:11:57 UTC, John Carter wrote:
On Monday, 23 June 2014 at 21:49:29 UTC, Ary Borenszweig wrote:
Union types are very common (I use them every day), and IMHO
it's very nice to have them included in the language (either
built-in or as a library solution). As a library
On Saturday, 14 June 2014 at 06:39:56 UTC, Ali Çehreli wrote:
On 06/13/2014 10:29 PM, Meta wrote:
I thought this was possible, but DMD 2.065 doesn't allow it,
saying "no
constructor for int":
int* p = new int(3);
Is something like this planned for the future? I know we can
already do:
int
I thought this was possible, but DMD 2.065 doesn't allow it,
saying "no constructor for int":
int* p = new int(3);
Is something like this planned for the future? I know we can
already do:
int n = int(3);
On Saturday, 7 June 2014 at 16:15:47 UTC, hane wrote:
At std.regex.
BTW, I found that immutable regex can be created with enum.
enum r1_ = regex("bla");
immutable r1 = r1_;
Regex struct created during compiling can be immutable?
In this case, it must be using enum to force CTFE. As fo
On Saturday, 7 June 2014 at 00:48:59 UTC, hane wrote:
On Friday, 6 June 2014 at 15:42:41 UTC, Meta wrote:
You should not do this, as it will create a new regex
everywhere you use it. Unlike const or immutable, enum in this
situation is more or less like a C macro.
#define r1 regex("bla")
I
On Friday, 6 June 2014 at 14:25:26 UTC, hane wrote:
On Friday, 6 June 2014 at 12:01:55 UTC, AntonSotov wrote:
const r1 = regex("bla");
matchFirst( "big string", r1 ); // ERROR!
immutable r2 = regex("bla"); // ERROR!
Why can I not use const/immutable regex?
I think it's a Phobos bug that c
On Thursday, 5 June 2014 at 07:19:07 UTC, timotheecour wrote:
ok I remembered we can use std.typetuple.Alias for that.
Or std.functional.unaryFun.
On Monday, 2 June 2014 at 22:18:39 UTC, bioinfornatics wrote:
Hi,
I would like store the delegate to another var but when i try i
get:
testTraitsWithDelegate.d(13): Error: expression template
__lambda2 is void and has no value
I do not want to run it only to save the «function» somewhere.
-
On Thursday, 29 May 2014 at 23:18:32 UTC, Dicebot wrote:
class Test {}
class TestChild: Test {}
class TestChildChild: TestChild {}
alias Alias(alias Symbol) = Symbol; // this does the trick
void main()
{
foreach (item; __traits(allMembers, mixin(__MODULE__)))
{
alias sym = A
I'd like to get a list of all classes in the current module, so I
came up with this code:
class Test {}
class TestChild: Test {}
class TestChildChild: TestChild {}
void main()
{
foreach (item; __traits(allMembers, mixin(__MODULE__)))
{
static if (is(mixin(item)
On Friday, 23 May 2014 at 15:14:47 UTC, Chris wrote:
The following:
import std.stdio;
void main() {
int[5] arg;
arg[10] = 3; // Compiler says (of course):
Error: array index 10 is out of bounds arg[0 .. 5]
}
import std.stdio;
void main() {
int[5] arg;
foreach (i; 0..10)
On Sunday, 18 May 2014 at 04:19:05 UTC, David Held wrote:
How do I get an array from randomSample()?
int[] source = [ ... ];
int[] sample = randomSample(source, 3);
src\main.d(30): Error: cannot implicitly convert expression
(randomSample(source, 3u)) of type RandomSample!(int[], void)
to int
On Wednesday, 14 May 2014 at 22:32:01 UTC, Jonathan M Davis via
Digitalmars-d-learn wrote:
Yeah, much as Andrei would hate to hear it (enforce was his
idea, and he quite
likes the idiom), the fact that lazy is so inefficient makes it
so that it's
arguably bad practice to use it in high performan
On Saturday, 10 May 2014 at 10:56:57 UTC, Jacob Carlborg wrote:
I know that there are templates to inspect function parameters,
like ParameterIdentifierTuple and ParameterTypeTuple. But these
don't work for templated/untyped lambdas, they're apparently
not callables. I don't expect ParameterTyp
On Saturday, 10 May 2014 at 08:42:14 UTC, FrankLike wrote:
I've been using VisualD for a long time without problems. If
it makes you nervous, you can get the source from Github and
compile it yourself.
Hello,Meta
When I compile the Visual D projects:
at first,I compile the 'build' project,
On Friday, 9 May 2014 at 01:02:39 UTC, FrankLike wrote:
Hi,everyone,
down VisulaD from
http://rainers.github.io/visuald/visuald/StartPage.html
found the virus:Win32.Troj.Undef.(kcloud)
Why?
Frank
I've been using VisualD for a long time without problems. If it
makes you nervous, you can get
On Wednesday, 7 May 2014 at 18:51:59 UTC, Meta wrote:
On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via
Digitalmars-d-learn wrote:
My eyes... Oh, how that hurts readibily.
While I agree that
pure @safe @nogc nothrow
void doSomething(int n)
{
}
is quite ugly, it is really not muc
On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via
Digitalmars-d-learn wrote:
My eyes... Oh, how that hurts readibily.
While I agree that
pure @safe @nogc nothrow
void doSomething(int n)
{
}
is quite ugly, it is really not much worse than
void doSomething(int n) pure @safe @nogc
On Wednesday, 7 May 2014 at 13:25:55 UTC, bearophile wrote:
So far in Rosettacode D entries I've kept a line length limit
of 72 or 73 chars.
But now a little larger monitors are common, D UFCS chains are
common, and we also have longer function signatures with "pure
nothrow @safe @nogc" (that
On Monday, 5 May 2014 at 04:05:35 UTC, Mark Isaacson wrote:
Something like:
unittest {
enum offsetof(string type, string field) = mixin(type ~ "." ~
field ~ ".offsetof");
struct StrToBob {
string str;
int bob;
}
writeln(offsetof!("StrToBob", "bob"));
}
?
If not that then I'
You could replace all those `op=='+'||op=='-'? ...` with
`op.among!('+', '-')? ...`.
On Friday, 2 May 2014 at 21:29:51 UTC, Mark Isaacson wrote:
Auto ref parameters seem to be just what I need. Thanks! I'd
still be curious if anyone has additional information regarding
the rationale at play (I'm spoiled, reading TDPL and having
each decision explained in text).
The C++ way wa
On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via
Digitalmars-d-learn wrote:
On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote:
template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E))
{
bool[string] allMembers; // used to detect member
collisions
mixin({
On Friday, 2 May 2014 at 13:38:39 UTC, Nordlöw wrote:
enums.d(25,46): Error: static variable allMembers cannot be
read at compile time
enums.d(25,21):while evaluating: static assert("a" in
allMembers)
Is there a solution to this problem?
Associative arrays are not CTFE-able.
On Tuesday, 29 April 2014 at 16:52:27 UTC, Ali Çehreli wrote:
That may be misleading because there is no need to allocate
with an explicit new. For example, the slice below is owned by
the GC as well:
int[] foo()
{
int[] a;
a ~= 42;// on memory owned by the GC
return a;
}
I d
On Sunday, 27 April 2014 at 20:54:02 UTC, bearophile wrote:
An Algebraic is a sum type, so you can't store two value in it,
only one, an int or a T*. But this is not going to solve your
problems...
Bye,
bearophile
Ah, you're right. I'm getting mixed up from my own initial
example. Fiddling
On Sunday, 27 April 2014 at 20:28:28 UTC, bearophile wrote:
Meta:
alias List = Algebraic!(typeof(null), Cons!(int, This));
Also your Cons seems a value type, like Algebraic itself. You
have to avoid creating an infinite-size algebraic value.
Bye,
bearophile
Yes, it's hard to figure out A
On Sunday, 27 April 2014 at 20:38:37 UTC, Meta wrote:
Is it necessary to use This[]? I tried changing it to This* and
it blew up on me.
I should specify. This did not work:
alias T = Algebraic!(int, This*);
void main() {
auto l = T(1, new T(2, new T(3, null)));
}
On Sunday, 27 April 2014 at 20:22:12 UTC, bearophile wrote:
Meta:
I'm trying to create a basic List type using Algebraic, but
the compiler keeps complaining about recursive aliasing.
As stated in its docs, Algebraic is not yet finished and good
for recursive data structures. But here I have
I'm trying to create a basic List type using Algebraic, but the
compiler keeps complaining about recursive aliasing.
import std.variant;
struct Cons(T, U: List)
{
public static opCall(T t, U u)
{
}
}
//Error
alias List = Algebraic!(typeof(null), Cons!(int, This));
void
On Friday, 25 April 2014 at 11:51:48 UTC, bearophile wrote:
They are not the same type:
void main() {
import std.typecons: Tuple;
alias T1 = const Tuple!(int, int);
alias T2 = Tuple!(const int, const int);
static assert(is(T1 == T2)); // Fails.
}
This type difference causes so
401 - 446 of 446 matches
Mail list logo