Actually it's a regression:
https://forum.dlang.org/post/fwwhyqpdvmdyudtgi...@forum.dlang.org
On Sunday, 4 May 2025 at 00:15:23 UTC, Jonathan M Davis wrote:
That sounds like an ldc bug then. With dmd, your program gives
[2, 2, 2, 2, 1, 1, 1, 1]
[2, 2, 2, 2, 1, 1, 1, 1]
core.exception.RangeError@q.d(13): Range violation
??:? onRangeError [0x29f6b6]
??:? _d_arrayboundsp [0
On Saturday, May 3, 2025 8:23:00 AM Mountain Daylight Time Andy Valencia via
Digitalmars-d-learn wrote:
> At least on 1.40.1 of the ldc2 distro for x86-64, uses the
> "illegal instruction" instruction.
That sounds like an ldc bug then. With dmd, your program gives
[2, 2, 2, 2, 1, 1, 1, 1]
[2, 2,
But yeah, core.internal.util.array is wrong design, it should be
boolean function, and the compiler should generate
assert(areTypedArraysConformable()); at the caller side.
You link with release version of druntime, try to link with debug
version.
ldc2 distro for x86-64, uses the
"illegal instruction" instruction. But it does make sense that
array operations want to be outside the "nothrow" guarantee, as
that would make nothrow almost useless.
Thanks,
Andy
```
(gdb) r
Starting program: /home/vandys/dlang/tst41
[
On Friday, 2 May 2025 at 22:19:53 UTC, Andy Valencia wrote:
In the following code, two questions. First, is there any
difference between "x[] = y" and "x[] = y[]"? It appears not.
`y` is already a slice `int[]`, so slicing it does not change the
type. Slicing without indices selects all elem
On Friday, 2 May 2025 at 22:19:53 UTC, Andy Valencia wrote:
In the following code, two questions. First, is there any
difference between "x[] = y" and "x[] = y[]"?
With basic slices no; I could construct something with overloads
tho
```d
import std.stdio : writeln;
auto foo(ref int[] a, re
In the following code, two questions. First, is there any
difference between "x[] = y" and "x[] = y[]"? It appears not.
Second, in assigning from arrays of differing sizes, Phobos
causes an illegal instruction, rather than the sort of exception
I'd have expected. I'm curious why they steppe
On Saturday, 19 November 2016 at 21:05:49 UTC, John Colvin wrote:
On Saturday, 19 November 2016 at 19:36:50 UTC, Marduk wrote:
Thanks a lot! Now I get what it means that array declarations
are read from right to left.
The way I think about it is this:
int is a type. int[3] is an array of 3 in
On Saturday, 19 November 2016 at 19:36:50 UTC, Marduk wrote:
On Saturday, 19 November 2016 at 17:37:58 UTC, John Colvin
wrote:
On Saturday, 19 November 2016 at 10:20:16 UTC, Marduk wrote:
Additionally, I would like to assign 2D sub-arrays of a 3D
array, i.e. something like the following:
int[
On Saturday, 19 November 2016 at 17:37:58 UTC, John Colvin wrote:
On Saturday, 19 November 2016 at 10:20:16 UTC, Marduk wrote:
Additionally, I would like to assign 2D sub-arrays of a 3D
array, i.e. something like the following:
int[3][2][2] a;
a[0] = [[2,2], [2,2]];
You have the dimensions
On Saturday, 19 November 2016 at 10:20:16 UTC, Marduk wrote:
Additionally, I would like to assign 2D sub-arrays of a 3D
array, i.e. something like the following:
int[3][2][2] a;
a[0] = [[2,2], [2,2]];
You have the dimensions the wrong way around. a is a 2 element
array of 2 element arrays o
In the documentation one can learn how to do array operations
with 1D arrays. However, this does not scale up for 2D arrays.
For example, the following does not work:
int[2][2] a,b;
a = [[1,1],[1,1]];
b[][] = a[][]*2;
Additionally, I would like to assign 2D sub-arrays of a 3D array,
i.e
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote:
So after looking into it a little bit...
So now I'm trying to multiply the array by a double but it's
giving incompatible type errors. opBinary, opBinaryRight, and
opOpAssign are defined.
I have:
struct Vector3 {
public double[3] _
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote:
The postblit can only not take @nogc due to the array
duplication which is understandable.
I think the postblit might be redundant anyway since the struct
is built on a static array so there is no possibility of two
different Vect3s "point
On Wednesday, 8 July 2015 at 06:05:54 UTC, ketmar wrote:
do you see the gotcha? if you uncomment postblit or assigns,
this build function fails to compile, as that operations aren't
"pure nothrow @nogc @trusted", and they will be used for either
assign or postblitting.
So after looking into i
t.vdata[] = this.vdata[] + rhs.vdata[];
return result;
}
BOOM! adding (1) is enough to get the same error.
this is what is going on. i don't know why DMD insists on such
restrictions for array operations, though.
On Monday, 6 July 2015 at 15:48:28 UTC, anonymous wrote:
Ok, I disabled everything in the struct except what I posted and
it ran.
I then uncommented stuff to isolate the cause. I've added in the
bits that cause the error below (plus some constructors just for
reference).
struct Vector3 {
On Monday, 6 July 2015 at 12:15:22 UTC, Peter wrote:
dmd 2.066.1, windows 7 64bit
Tested it on Windows 7, using dmd 2.066.1: works for me.
The exact code I tested (just commented those "..." out):
struct Vector3 {
public double[3] _p;
//...
Vector3 opBinary(string op)(in Vecto
On Monday, 6 July 2015 at 10:29:35 UTC, anonymous wrote:
Works for me with various versions of dmd on linux. What
compiler are you using, what version of it, what operating
system, etc?
dmd 2.066.1, windows 7 64bit
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote:
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote:
[...]
unittest{
auto a = Vector3([2.0, 2.0, 0.0]);
auto b = Vector3([1.0, 2.0, 1.0]);
Vector3[] c = [a];
Vector3[] d = [b];
Vector3 e = a + b; // works
Vec
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote:
Hi,
I have a struct with arithmetic operations defined using
opBinary but array operations with arrays of it don't work.
struct Vector3 {
public double[3] _p;
...
Vector3 opBinary(string op)(in Vector3 rhs) const
i
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote:
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote:
Hi,
I have a struct with arithmetic operations defined using
opBinary but array operations with arrays of it don't work.
struct Vector3 {
public double[
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote:
Hi,
I have a struct with arithmetic operations defined using
opBinary but array operations with arrays of it don't work.
struct Vector3 {
public double[3] _p;
...
Vector3 opBinary(string op)(in Vector3 rhs) const
i
Hi,
I have a struct with arithmetic operations defined using opBinary
but array operations with arrays of it don't work.
struct Vector3 {
public double[3] _p;
...
Vector3 opBinary(string op)(in Vector3 rhs) const
if (op == "+"){
Vector3 result;
On Thursday, 2 July 2015 at 19:27:57 UTC, J Miller wrote:
I knew that automatic allocation doesn't happen, but I'm
confused by the fact if you explicitly declare "c" with "int[]
c;" and then assign "c[] = a[] * b[]", versus using "auto c =
a[] * b[]", you get two different errors (array length
On Thursday, 2 July 2015 at 12:59:03 UTC, Steven Schveighoffer
wrote:
On 7/2/15 8:21 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?=
" wrote:
On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer
wrote:
On 7/1/15 8:36 PM, J Miller wrote:
Oh, and to make things really confusing, "auto e = a[] -
b[
On 7/2/15 8:21 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote:
On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer wrote:
On 7/1/15 8:36 PM, J Miller wrote:
Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[]
e = a[] - b[]" both cause "Error: array operation a[] - b
https://issues.dlang.org/show_bug.cgi?id=14759
On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer
wrote:
On 7/1/15 8:36 PM, J Miller wrote:
Oh, and to make things really confusing, "auto e = a[] - b[]"
and "int[]
e = a[] - b[]" both cause "Error: array operation a[] - b[]
without
destination memory not allowed".
Using dmd 2.0
On 7/1/15 8:36 PM, J Miller wrote:
Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[]
e = a[] - b[]" both cause "Error: array operation a[] - b[] without
destination memory not allowed".
Using dmd 2.067.0.
This is not a bug. You need to allocate memory before you can wri
On Wednesday, 1 July 2015 at 21:15:13 UTC, Marc Schütz wrote:
On Wednesday, 1 July 2015 at 19:09:36 UTC, Alex Parrill wrote:
I don't think this is a bug.
Since you don't initialize `c` to anything, it defaults to an
empty slice. Array [] operations apply to each element of a
sli
On Wednesday, 1 July 2015 at 19:09:36 UTC, Alex Parrill wrote:
I don't think this is a bug.
Since you don't initialize `c` to anything, it defaults to an
empty slice. Array [] operations apply to each element of a
slice, but `c` doesn't have any elements, so it does nothing.
don't initialize `c` to anything, it defaults to an
empty slice. Array [] operations apply to each element of a
slice, but `c` doesn't have any elements, so it does nothing.
Change `int[] c;` to `int[] c = new int[4];` and it works.
On Tuesday, 30 June 2015 at 22:37:34 UTC, ixid wrote:
int[] a = [1,1,1,1];
int[] b = [1,1,1,1];
int[] c;
c[] = a[] - b[];
c.writeln;
This outputs []. This feels wrong, it feels like something that
should have exploded or set the length to 4. If the leng
int[] a = [1,1,1,1];
int[] b = [1,1,1,1];
int[] c;
c[] = a[] - b[];
c.writeln;
This outputs []. This feels wrong, it feels like something that
should have exploded or set the length to 4. If the lengths of a
and b are mismatched it throws an exception.
Márcio Martins:
float[10] a;
a[] = uniform(0.0f, 1.0f);
This is going to set all values to the result of a single call
to uniform();
Is there a way to express my intent that I want one result per
array element?
Currently D array operations can't be used for that kind of
usage. S
Hello!
I started exploring D today and one of the things that caught my
attention was the "array operations" feature.
While playing around and writing some code with it, I came across
a problem I wasn't able to find a solution for. The following is
a simple example of the a
On Wednesday, 21 May 2014 at 17:07:27 UTC, Francesco Cattoglio
wrote:
On Wednesday, 21 May 2014 at 13:52:47 UTC, John Colvin wrote:
On Wednesday, 21 May 2014 at 11:45:57 UTC, Stefan Frijters
wrote:
I would have expected the last case to work as well, but I get
testarr.d(20): Error: incompatibl
On Wednesday, 21 May 2014 at 13:52:47 UTC, John Colvin wrote:
On Wednesday, 21 May 2014 at 11:45:57 UTC, Stefan Frijters
wrote:
I would have expected the last case to work as well, but I get
testarr.d(20): Error: incompatible types for ((dfoo) *
(ibar[])): 'double' and 'int[]'
Is this by des
On Wednesday, 21 May 2014 at 13:52:47 UTC, John Colvin wrote:
Please file a bug, there's no reason for that not to work, it
just needs to be implemented properly.
Ok, thanks for confirming. Filed as
https://issues.dlang.org/show_bug.cgi?id=12780 .
On Wednesday, 21 May 2014 at 11:45:57 UTC, Stefan Frijters wrote:
When working on my current project (writing a numerical
simulation code) I ran into the following issue when trying to
multiply a vector (represented by a fixed-length array) by a
scalar:
import std.stdio;
void main() {
int
Stefan Frijters:
Is this by design? It was very surprising to me, especially
since all other combinations do seem to work.
I don't know if this situation is by design. At first sights it
seems a limitation that could be removed.
Bye,
bearophile
When working on my current project (writing a numerical
simulation code) I ran into the following issue when trying to
multiply a vector (represented by a fixed-length array) by a
scalar:
import std.stdio;
void main() {
int ifoo = 2;
int[3] ibar = 1;
double dfoo = 2.0;
double[3] dbar
Timon Gehr:
> I agree. It is odd that we have opSliceUnary but not opSliceBinary.
If you think something useful is missing, then file a Bugzilla enhancement
request.
Bye,
bearophile
On 10/15/2011 01:12 AM, Jay Norwood wrote:
Jonathan M Davis Wrote:
On Friday, October 14, 2011 15:29:17 Jay Norwood wrote:
Jonathan M Davis Wrote:
On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
Is it possible to overload array operations
Please be more specific. Are you asking
On 10/14/2011 09:43 PM, Jonathan M Davis wrote:
On Friday, October 14, 2011 15:29:17 Jay Norwood wrote:
Jonathan M Davis Wrote:
On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
Is it possible to overload array operations
Please be more specific. Are you asking whether a struct or
On Friday, October 14, 2011 16:12 Jay Norwood wrote:
> Jonathan M Davis Wrote:
> > On Friday, October 14, 2011 15:29:17 Jay Norwood wrote:
> > > Jonathan M Davis Wrote:
> > > > On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> > > > >
Jonathan M Davis Wrote:
> On Friday, October 14, 2011 15:29:17 Jay Norwood wrote:
> > Jonathan M Davis Wrote:
> > > On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> > > > Is it possible to overload array operations
> > >
> > > Please be m
On Friday, October 14, 2011 15:29:17 Jay Norwood wrote:
> Jonathan M Davis Wrote:
> > On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> > > Is it possible to overload array operations
> >
> > Please be more specific. Are you asking whether a struct or class
Jonathan M Davis Wrote:
> On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> > Is it possible to overload array operations
>
> Please be more specific. Are you asking whether a struct or class can
> overload
> the indexing and slicing operators? If so, the answer
Jonathan M Davis Wrote:
> On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> > Is it possible to overload array operations
>
> Please be more specific. Are you asking whether a struct or class can
> overload
> the indexing and slicing operators? If so, the answer
On Friday, October 14, 2011 11:30:25 Jay Norwood wrote:
> Is it possible to overload array operations
Please be more specific. Are you asking whether a struct or class can overload
the indexing and slicing operators? If so, the answer is yes.
http://d-programming-language.
Is it possible to overload array operations
On 07.08.2010 14:10, simendsjo wrote:
I'm new to D2, so please.. :)
(...)
Thanks for all answers. Seems array operations is a bit buggy, so I'll
rather look more into them at a later date.
Don:
> That is bug 4578, which has been fixed, and will be in the next compiler
> release.
Good, there is no need to file it then.
simendsjo post shows two more cases, this is the first:
> {
> double[3] a = [1,1,1];
> auto b = a[] + 3; // What happens here?
>
4,4]); // fails as b.length == 0.. Should the
> compiler
> say something?
> }
That is wrong code, because array operations don't allocate new memory.
The compiler (or runtime, because those are dynamic arrays) must complain here,
but here it doesn't yet, and
Mafi wrote:
Hey, here Mafi again,
I thought about your snippets and here's what I have.
Am 07.08.2010 14:10, schrieb simendsjo:
{ // Like the previous example, but with dynamic arrays..
double[] a = [1,1,1];
auto b = a;
assert(a is b);
b = a[] + 3;
assert(a == [1,1,1]);
//writeln(b); // acces
Hey, here Mafi again,
I thought about your snippets and here's what I have.
Am 07.08.2010 14:10, schrieb simendsjo:
{
double[3] a = [1,1,1];
double[3] b;
b[] = a[] + 3;
assert(a == [1,1,1]);
assert(b == [4,4,4]);
}
{
double[3] a = [1,1,1];
auto b = a;
b[] = a[] + 3;
assert(a == [1,1,1]);
assert
Am 07.08.2010 14:10, schrieb simendsjo:
I'm new to D2, so please.. :)
The spec on Array Operations,
http://www.digitalmars.com/d/2./arrays.html says:
"""A vector operation is indicated by the slice operator appearing as
the lvalue of an =, +=, -=, *=, /=, %=, ^=, &=
I'm new to D2, so please.. :)
The spec on Array Operations,
http://www.digitalmars.com/d/2./arrays.html says:
"""A vector operation is indicated by the slice operator appearing as
the lvalue of an =, +=, -=, *=, /=, %=, ^=, &= or |= operator."""
The f
be greatly appreciated.
Thanks,
Pillsy
I'm using dmd 2.045 on linux here, and that example works fine, so I'd
guess it's an OS X specific bug if you can't get it working with newer
versions of dmd... There were some issues to do with array operations
that have been fixed recent
I have the following program on Mac OS X 10.6.3 running dmd version 2.043:
$ cat if.d
import std.stdio;
void main (string [] args)
{
foreach(arg; args)
writeln(arg);
auto vec = new double[10];
foreach(i, ref x; vec) { x = cast(double) i; }
if (args.length > 1 && args[1] == "bar") {
64 matches
Mail list logo