Upsurge icon indicating copy to clipboard operation
Upsurge copied to clipboard

Problem with 1D + operator

Open MUECKE446 opened this issue 7 years ago • 3 comments

    let A = [1.0,2.0,3.0]
    let B = [4.0,5.0,6.0]
    let C = A + B   <-------- error: Ambiguous use of operator '+'
    print(C)
    var D : ValueArray<Double> = [1.0,2.0,3.0]
    var E : ValueArray<Double> = [4.0,5.0,6.0]
    let F = D + E   <-------- this works ok
    print(F)

I have no idea how can I fix it: for a build in Double array + for appending exists. Can someone help?

MUECKE446 avatar Mar 20 '17 21:03 MUECKE446

Yes, for Array + is defined as concatenation. You have to use ValueArray. You can also write as:

var D = ValueArray([1.0,2.0,3.0])
var E = ValueArray([4.0,5.0,6.0])
let F = D + E

ghost avatar Mar 21 '17 02:03 ghost

Hello Alejandro,

this is evident, but I mean, that than the public func for + in the package should be removed.

Von: Alejandro Isaza [mailto:[email protected]] Gesendet: Dienstag, 21. März 2017 03:04 An: aleph7/Upsurge Cc: MUECKE446; Author Betreff: Re: [aleph7/Upsurge] Problem with 1D + operator (#71)

Yes, for Array + is defined as concatenation. You have to use ValueArray. You can also write as:

var D = ValueArray([1.0,2.0,3.0]) var E = ValueArray([4.0,5.0,6.0]) let F = D + E

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aleph7/Upsurge/issues/71#issuecomment-287954520 , or mute the thread https://github.com/notifications/unsubscribe-auth/AGZ4p-Mb05qYzZewddBC63zGQCxFYCbGks5rnzAdgaJpZM4MjDAm .Das Bild wurde vom Absender entfernt.

MUECKE446 avatar Mar 21 '17 20:03 MUECKE446

There are two options if you want to concatenate:

  1. Use A.append(contentsOf: B)
  2. Do this in a Swift file that does not import Upsurge

alejandro-isaza avatar Mar 22 '17 03:03 alejandro-isaza