On Monday, 12 October 2015 at 15:39:15 UTC, TheFlyingFiddle wrote:
How does this compile?
{
string str = "hello";
foreach (n; [32, 119, 111, 114, 108, 100, 33]) str ~= n;
import std.stdio : writeln;
str.writeln;// prints "hello world!"
writeln(true == 1); /
On Sunday, 10 April 2016 at 16:19:51 UTC, Lucien wrote:
Hello,
Is there the possibility to set the cursor position in a file ?
Example:
void main()
{
File myFile = File("myFile.txt");
showFile(myFile);
// set cursor pos to 0
showFile(myFile);
}
void showFile(Fil
Often I find myself wanting to alias an expression, such as
verbose fields, possibly nested. AFAIK, the with statement makes
it easier, but not as good as it could have been. What I'd like
to express is for example something like this:
with( a = instanceA.verboseFieldA.verboseFieldB,
b
On Friday, 22 April 2016 at 01:42:11 UTC, Yuxuan Shui wrote:
Maybe use something like:
auto a = () => instanceA.verboseFieldA.verboseFieldB;
You can certainly declare temporaries and rely on the compiler
optimizing those away:
auto a = instanceA.verboseFieldA.verboseFieldB;
auto b = instanc
struct Foo {
Bars bars;
...
}
struct Foos {
Foo[] arr;
Foo opIndex (size_t idx) { return arr[idx]; }
...
}
struct Bar {
// No Car[] cars;
...
}
struct Bars {
Bar[] arr;
Bar opIndex (size_t idx) { return arr[idx]; }
...
}
struct Car {
...
}
Foos foos
On Monday, 9 May 2016 at 22:33:37 UTC, John Colvin wrote:
There are lots of ways to approach this. Here's one possibility:
auto cars(Bar bar)
{
static struct Res
{
Bar bar;
Car opIndex(size_t i)
{
return /* e.g. getCar(bar, i); */
}
}
r
struct Vector (T)
{
T[]arr;
void opSliceAssign (T[] a) { arr[] = a[]; }
}
unittest
{
auto v = Vector!double([1, 2]);
double[] d1 = [11, 12];
double[] d2 = [21, 22];
double[] d3 = new double[](2);
d3[] = d1[] + d2[];
assert (d3 == [11.+21., 12.+22.]);
assert (is(typeof(d1[] + d2[]
Hi!
struct Vector (T)
{
T[]arr;
T[] opSlice() { return arr; }
}
Vector!double v;
double[] d;
v[][] = d[] + d[];
//first [] call opSlise, second [] for array syntax
Best Regards,
Ilya
Thanks for your suggestion. It's not as attractive though, it
would be the same as v.arr[] =
// DMD v2.066.0
// All asserts pass (!)
import std.math : sin, cos, tan, asin, acos, atan,
sinh, cosh, tanh, asinh, acosh, atanh;
alias F = double;
immutable F a = 3, b = 5;
F fmul (F a) pure { return a * b; }
F fsin (F a) pure { return sin(a); }
struct Smul { F value; this
--
Why bother?
import std.algorithm : max;
F fun (F a, F b) { return max(a,b) + 1.; }
unittest { assert (gun(1, 2) == gun(2, 1)); } // Passes
F pun (F a, F b) { return sin(max(a,b)); }
unittest { assert (fun(1, 2) == fun(2, 1)); } // Fails
// Fun, gun, pun...
unittest { assert (fun(1, 2) =
assert (fasin(a) != fasin(a)); // ?
assert (facos(a) != facos(a)); // ?
Too quick there.. But:
assert (fasin(0.5) != fasin(0.5)); // ?
assert (facos(0.5) != facos(0.5)); // ?
Using equality is not a good idea with floating point.
The compiler will on a whim, or depending on whether it can
inline or not, use higher precision floats, changing the
outcome slightly.
I cannot say for certain whether this explains all the issues
you have, the very last one seems troubl
On Thursday, 23 October 2014 at 18:26:53 UTC, Steven
Schveighoffer wrote:
On 10/23/14 2:18 PM, deed wrote:
Using equality is not a good idea with floating point.
The compiler will on a whim, or depending on whether it can
inline or
not, use higher precision floats, changing the outcome
slight
A similar problem was recently (about 2-3 weeks ago IIRC) seen
in one of
the Phobos PR's. It appears to be related to the autoextension
of float
to double (or double to real, I forget which) in certain
contexts on
Windows. @deed Could you please try to reduce the failing test
to a
minimal cod
Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8
for both Windows and Linux. This just illustrates the sin
function.
Replacing double with real makes everything pass on Linux Mint 16
with -m32 and -m64. Replacing double with float seems to give the
same problems as before, but
On Thursday, 23 October 2014 at 21:42:46 UTC, anonymous wrote:
On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote:
Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8
for both Windows and Linux. This just illustrates the sin
function.
I think the tests marked "[1]" are expec
OK, I tried with OSX 64-bit compiler. Perhaps 32 bit would not
fare as well. What platform are you testing on?
Have tried Linux and Windows 64-bit and it seems to be an issue
when compiled with -m32. Tests are provided here
http://dpaste.dzfl.pl/5f55f4152aa8.
I agree that one cannot compare
// bindings from
https://github.com/CS-svnmirror/dsource-bindings-win32/blob/308739a417eaaba85a5d3ce7741fd43d3042efe0/oaidl.d
---
import win32.oaidl;
// The following gives linker error: error LNK2019: unresolved
external
// symbol _D5win325oaidl7VARIANT6__initZ referenced
// in function ...
Your link is failing because the .init value of the struct is
not found. The .init will be in the object file corresponding
to the module where the struct is defined, so to fix the linker
error, add the win32.oaidl module to the list of modules you're
compiling and linking. An easy way to do th
struct Internal { int i; double d; string s; }
struct External_int {
Internal internal;
@property Internal* ptr () { return &internal; }
this (int a)
{
internal.s = "int";
internal.i = a;
}
}
struct External (T) {
Internal internal;
@property Internal* ptr () { ret
static if (is(typeof(T) == int))
should be
static if (is(T == int))
T is already a type.
Ahh. Thanks!
On Friday, 4 September 2015 at 01:31:28 UTC, Namal wrote:
How can I get just the maximum element? Do I need to give a
range for it?
Use max? http://dlang.org/phobos/std_algorithm_comparison.html#max
On Friday, 4 September 2015 at 07:27:54 UTC, Namal wrote:
On Friday, 4 September 2015 at 01:55:13 UTC, deed wrote:
On Friday, 4 September 2015 at 01:31:28 UTC, Namal wrote:
How can I get just the maximum element? Do I need to give a
range for it?
Use max?
http://dlang.org/phobos/std_algorith
On Saturday, 5 September 2015 at 12:41:37 UTC, Namal wrote:
Thx guys. Now I try out the split function. I read the file as
a single string?
auto arr = split(cast(string)read(filename),",");
where the file has "A", "B", "C"
and I get the output ["\"A\"", " \"B\"", " \"C\"\n"]
I can understand
On Saturday, 5 September 2015 at 14:44:19 UTC, deed wrote:
.map!(s => chomp(s, "\"")
.map!(s => chompPrefix(s, "\"")
should be
.map!(s => chomp(s, "\""))
.map!(s => chompPrefix(s, "\""))
On Saturday, 5 September 2015 at 17:31:39 UTC, Namal wrote:
Yeah, I have have been trying this example from wiki books
https://en.wikibooks.org/wiki/Learning_D_With_Project_Euler
It is not even compiling.
What exactly is not compiling?
On Sunday, 6 September 2015 at 17:57:49 UTC, Namal wrote:
Yeah, I just checked, it is 2.066, how can I install the new
version on ubuntu with sudo apt-get?
sudo apt-get install dmd
will give you dmd v2.067.1. Don't know when it will be upgraded
to 2.068 though.
On Sunday, 6 September 2015 at 22:04:55 UTC, Namal wrote:
oh, sorry. But I found out what I have been doing wrong besides
that.
arr.sort.uniq;
uniq(arr) or arr.sort.uniq; compiles but doesn't store it in
the arr array, I need to store it in a new one.
Right, it's like
int x = 3;
// x + 5;
On Monday, 7 September 2015 at 10:25:09 UTC, deed wrote:
writeln(x);// or you can pass it to a function.
I meant `writeln(x + 5)`
On Wednesday, 9 September 2015 at 11:30:26 UTC, Bahman Movaqar
wrote:
On Wednesday, 9 September 2015 at 08:29:20 UTC, cym13 wrote:
The way I would have written it is:
auto result = foobars.filter!(fb => nums.all!(n => (fb.x *
fb.y) > n))
.filter!(fb => nums.all!(n => fb.x
On Wednesday, 9 September 2015 at 20:28:35 UTC, Laeeth Isharc
wrote:
I have a DateTime[][] arg ...
I would like to find the intersection of the dates.
A suggestion:
auto minLength = arg.map!(a => a.length).reduce!min;
auto minIdx = arg.map!(a =>
a.length).countUntil(minLength);
a
On Friday, 11 September 2015 at 10:41:16 UTC, ixid wrote:
Does sort have to be eager or would it be possible to have a
lazy version? It's messy to always have to use array and leap
in and out of lazy operations within a UFCS chain. Surely as
many functions as possible should be optionally lazy.
On Saturday, 12 September 2015 at 10:17:19 UTC, Nordlöw wrote:
How do I most elegantly iterate all the adjacent pairs in an
`InputRange` using Phobos?
Something like
[1,2,3,4] => [(1,2), (2,3), (3,4)]
Why not just:
zip(arr[0 .. $-1], arr[1 .. $])
?
On Saturday, 12 September 2015 at 12:51:04 UTC, Namal wrote:
Anyway, there is no .reverse for strings I guess, what is the
way to completely reverse a string in D?
What do you want to do? Do you want to keep your data in original
order, but get a reversed view of it for something, or do you
a
On Sunday, 13 September 2015 at 03:20:31 UTC, deed wrote:
string s = "Some text";
s.retro.find("e"); // `Some te` (Surprising to me.
Error? 2.067.1)
Sorry, the above is wrong, .retro.find does indeed return what's
expected.
string s = "Some text";
s.retro.find("e").writeln; // Pri
On Sunday, 13 September 2015 at 03:20:31 UTC, deed wrote:
...
and since `string` is an alias for `const(char)[]`, it's not ...
string is an alias for immutable(char)[], not const(char)[].
http://dlang.org/arrays.html#strings
Sorry about the noise.
On Monday, 14 September 2015 at 18:36:54 UTC, Meta wrote:
As an aside, you should use `sort()` instead of the
parentheses-less `sort`. The reason for this is that doing
`arr.sort` invokes the old builtin array sorting which is
terribly slow, whereas `import std.algorithm; arr.sort()` uses
the
void main ()
{
new int[](1);
}
Compiles with dmd 2.071.2-b2, but no code is generated for `new
int[](1);`.
Caused a bug due to:
char[] arr;
got updated to
char[] arr; new char[](SIZE);
If it's considered a bug and someone would file it, I'd be
thankful.
On Thursday, 15 September 2016 at 13:57:13 UTC, rikki cattermole
wrote:
Not a bug, it is never used.
I'd expect an "Error: ... no effect ..." from the compiler.
On Thursday, 15 September 2016 at 14:42:13 UTC, Jonathan M Davis
wrote:
On Thursday, September 15, 2016 14:07:18 deed via
Digitalmars-d-learn wrote:
On Thursday, 15 September 2016 at 13:57:13 UTC, rikki
cattermole
wrote:
> Not a bug, it is never used.
I'd expect an "Error:
On Friday, 23 September 2016 at 09:21:56 UTC, Claude wrote:
...
// Maybe you can try using std.variant?
import std.variant;
alias Component = Variant;
class Entity
{
void register (Component v) { components ~= v; }
void unregister (T) () {
foreach (i, c; components) if (c.type
Unexpected auto-concatenation of string elements:
string[] arr = ["a", "b" "c"];// ["a", "bc"], length==2
int[] arr2 = [[1], [2] [3]];// Error: array index 3 is out
of bounds [2][0 .. 1]
// Error: array index 3 is out
of bounds [0..1]
dmd 2.071.2-b2
42 matches
Mail list logo