# Array Sutraction

**URL:** <https://rubytalk.org/t/array-sutraction/5540>\
**Category:** ruby-talk\
**Created:** [8 April 2003 03:58 UTC](https://rubytalk.org/t/array-sutraction/5540 "2003-04-08T03:58:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [8 April 2003 03:58 UTC](https://rubytalk.org/t/array-sutraction/5540/1 "2003-04-08T03:58:53Z")

</div>

Ok, this has been discussed at length previously,  
and it appears that the implementation has  
changed.

Consider:

# in 1.6.7

[1,1,2,2,3,3] - [3] =\> [1,2]

# in 1.8.0

[1,1,2,2,3,3] - [3] =\> [1,1,2,2]

I think this last algorithm was chosen for  
performance reasons. The problem is, the #- operation  
is neither explainable by the Array being considered a bag  
or a set. Plus, since this operation seems to change  
with revisions, it is hard to rely upon.

The one explanation that is consistent between the two  
is if #uniq is applied to both sides of the equation.  
Tbat is,

([1,1,2,2,3,3].uniq - [3].uniq).uniq #=\> [1,2].uniq =\> [1,2]  
([1,1,2,2,3,3].uniq - [3].uniq).uniq #=\> [1,1,2,2].uniq =\> [1,2]

So it would seem that Array#- is incomplete and the user  
is required to apply #uniq to the result.

All I can say is, Why?

> **···**
>
> ## – Jim Freeze
> 
> Mandrell: "You know what I think?"  
> Doctor: “Ah, ah that’s a catch question. With a brain your size you  
> don’t think, right?”  
> – Dr. Who

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [8 April 2003 04:19 UTC](https://rubytalk.org/t/array-sutraction/5540/2 "2003-04-08T04:19:32Z")

</div>

Hi,

> **···**
>
> In message “Array Sutraction” on 03/04/08, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) writes:
> 
> > So it would seem that Array#- is incomplete and the user  
> > is required to apply #uniq to the result.
> 
> If you want uniq elements in the result. 1.8.0 Array#- removes  
> elements in the right operand from the receiver (right operand).
> 
> ```
> matz.
> 
> ```

---

<div class="post-metadata">

**Author:** ![Berger\_Daniel2](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@Berger\_Daniel2](https://rubytalk.org/u/Berger_Daniel2)\
**Post date:** [8 April 2003 13:54 UTC](https://rubytalk.org/t/array-sutraction/5540/3 "2003-04-08T13:54:25Z")

</div>

Jim Freeze wrote:

> Ok, this has been discussed at length previously,  
> and it appears that the implementation has  
> changed.
> 
> Consider:
> 
> # in 1.6.7
> 
> [1,1,2,2,3,3] - [3] =\> [1,2]
> 
> # in 1.8.0
> 
> [1,1,2,2,3,3] - [3] =\> [1,1,2,2]
> 
> I think this last algorithm was chosen for  
> performance reasons. The problem is, the #- operation  
> is neither explainable by the Array being considered a bag  
> or a set. Plus, since this operation seems to change  
> with revisions, it is hard to rely upon.

FWIW, 1.8 has a Set class if you want true set behavior:

require “set”  
set\_a = Set.new([1,1,2,2,3,3])  
p set\_a → #\<Set: {1, 2, 3}\>

set\_b = set\_a -[3]  
p set\_b → #\<Set: {1, 2}\>

Regards,

Dan

> **···**
>
> –  
> a = [74, 117, 115, 116, 32, 65, 110, 111, 116, 104, 101, 114, 32, 82]  
> a.push(117,98, 121, 32, 72, 97, 99, 107, 101, 114)  
> puts a.pack(“C\*”)

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [8 April 2003 04:28 UTC](https://rubytalk.org/t/array-sutraction/5540/4 "2003-04-08T04:28:00Z")

</div>

I’m sorry Matz, I don’t understand.

I don’t have a horse in either the set or bag race.  
It’s just the current implementation is very confusing.

If I have a = [1,1,2,2,2] and I subtract [2], then  
I should get [1,1,2,2] if a is considered a bag.  
If a is considered a set, then it must first be  
temporarily converted to a set [1,2] and then  
the subtraction is performed yielding [1].

However, 1.8.0 returns [1,1].

ruby -ve ‘p [1,1,2,2,2]-[2]’  
ruby 1.8.0 (2003-03-10) [i386-freebsd4.6]  
[1, 1]

> **···**
>
> On Tuesday, 8 April 2003 at 13:19:32 +0900, Yukihiro Matsumoto wrote:
> 
> > Hi,
> > 
> > In message “Array Sutraction” \> on 03/04/08, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) writes:
> > 
> > > So it would seem that Array#- is incomplete and the user  
> > > is required to apply #uniq to the result.
> > 
> > If you want uniq elements in the result. 1.8.0 Array#- removes  
> > elements in the right operand from the receiver (right operand).
> > 
> > ```
> > matz.
> > 
> > ```
> 
> ## – Jim Freeze
> 
> There’s no real need to do housework – after four years it doesn’t get  
> any worse.

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [8 April 2003 14:31 UTC](https://rubytalk.org/t/array-sutraction/5540/5 "2003-04-08T14:31:57Z")

</div>

Ahh, thanks Dan. I didn’t know this.

> **···**
>
> On Tuesday, 8 April 2003 at 22:54:25 +0900, Daniel Berger wrote:
> 
> > Jim Freeze wrote:
> > 
> > > 
> > 
> > FWIW, 1.8 has a Set class if you want true set behavior:
> > 
> > require “set”  
> > set\_a = Set.new([1,1,2,2,3,3])  
> > p set\_a → #\<Set: {1, 2, 3}\>
> > 
> > set\_b = set\_a -[3]  
> > p set\_b → #\<Set: {1, 2}\>
> > 
> > Regards,
> > 
> > Dan
> 
> ## – Jim Freeze
> 
> It is now 10 p.m. Do you know where Henry Kissinger is?  
> – Elizabeth Carpenter

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [8 April 2003 04:41 UTC](https://rubytalk.org/t/array-sutraction/5540/6 "2003-04-08T04:41:17Z")

</div>

Hi,

> I don’t have a horse in either the set or bag race.  
> It’s just the current implementation is very confusing.

I defined array subtraction as

def -(other)  
self.delete\_if{|x| other.include?(x)}  
end

which is very clear for me (note that real Array#- uses Hash inside,  
so that its comparison is actually done by eql? not ==).

```
						matz.

```

> **···**
>
> In message “Re: Array Sutraction” on 03/04/08, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) writes:

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [8 April 2003 08:33 UTC](https://rubytalk.org/t/array-sutraction/5540/7 "2003-04-08T08:33:20Z")

</div>

“Jim Freeze” [jim@freeze.org](mailto:jim@freeze.org) schrieb im Newsbeitrag  
[news:20030408003523.A678@freeze.org](mailto:news:20030408003523.A678@freeze.org)…

> I’m sorry Matz, I don’t understand.
> 
> I don’t have a horse in either the set or bag race.  
> It’s just the current implementation is very confusing.
> 
> If I have a = [1,1,2,2,2] and I subtract [2], then  
> I should get [1,1,2,2] if a is considered a bag.  
> If a is considered a set, then it must first be  
> temporarily converted to a set [1,2] and then  
> the subtraction is performed yielding [1].

I don’t find this confusing. In fact I find the implicit application of  
uniq (older version) more confusing because it is somewhat surprising - at  
least to me. In that case substraction indeed combines two operations.

I’d view the substraction “a-b” as “remove all elements in b from a”,  
which would reasonable lead to all 2’s removed from [1,1,2,2,2] yielding  
[1,1].

> However, 1.8.0 returns [1,1].
> 
> ruby -ve ‘p [1,1,2,2,2]-[2]’  
> ruby 1.8.0 (2003-03-10) [i386-freebsd4.6]  
> [1, 1]

That’s what I’d expect.

```
robert

```

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [8 April 2003 13:59 UTC](https://rubytalk.org/t/array-sutraction/5540/8 "2003-04-08T13:59:50Z")

</div>

> I don’t find this confusing. In fact I find the implicit  
> application of  
> uniq (older version) more confusing because it is somewhat  
> surprising - at  
> least to me. In that case substraction indeed combines two  
> operations.
> 
> I’d view the substraction “a-b” as “remove all elements in b from  
> a”,  
> which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> yielding  
> [1,1].

So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
That seems odd to me.

> **···**
>
> * * *
> 
> Do you Yahoo!?  
> Yahoo! Tax Center - File online, calculators, forms, and more
> 
> > **[Taxes 2023: News, Tips, Dates & Latest Info - Yahoo Finance](https://finance.yahoo.com/taxes/)**
> >
> > Find the latest tax news, tips, dates and info that you need to file taxes in 2023.

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [8 April 2003 14:14 UTC](https://rubytalk.org/t/array-sutraction/5540/9 "2003-04-08T14:14:43Z")

</div>

I agree. But the presence of a Set in 1.8  
maes me feel better. After all, an Array  
is not in itself a bag or a set, so we can  
define its minus operator more or less  
arbitrarily.

Hal

> **···**
>
> ----- Original Message -----  
> From: “Michael Campbell” [michael\_s\_campbell@yahoo.com](mailto:michael_s_campbell@yahoo.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Tuesday, April 08, 2003 8:59 AM  
> Subject: Re: Array Sutraction
> 
> > > I’d view the substraction “a-b” as “remove all elements in b from  
> > > a”,  
> > > which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> > > yielding  
> > > [1,1].
> > 
> > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
> > That seems odd to me.

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [8 April 2003 14:33 UTC](https://rubytalk.org/t/array-sutraction/5540/10 "2003-04-08T14:33:17Z")

</div>

Yes. It’s not really subtraction as implied by the ‘-’ minus operator.  
Maybe it should be renamed to #remove\_all\_from. 🙂

> **···**
>
> On Tuesday, 8 April 2003 at 22:59:50 +0900, Michael Campbell wrote:
> 
> > > I don’t find this confusing. In fact I find the implicit  
> > > application of  
> > > uniq (older version) more confusing because it is somewhat  
> > > surprising - at  
> > > least to me. In that case substraction indeed combines two  
> > > operations.
> > > 
> > > I’d view the substraction “a-b” as “remove all elements in b from  
> > > a”,  
> > > which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> > > yielding  
> > > [1,1].
> > 
> > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
> > That seems odd to me.
> 
> ## – Jim Freeze
> 
> F: When into a room I plunge, I  
> Sometimes find some VIOLET FUNGI.  
> Then I linger, darkly brooding  
> On the poison they’re exuding.  
> – The Roguelet’s ABC

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [8 April 2003 14:17 UTC](https://rubytalk.org/t/array-sutraction/5540/11 "2003-04-08T14:17:23Z")

</div>

> > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2,  
> > 2]?  
> > That seems odd to me.
> 
> I agree. But the presence of a Set in 1.8  
> maes me feel better. After all, an Array  
> is not in itself a bag or a set, so we can  
> define its minus operator more or less  
> arbitrarily.

I’ll defer to others on the behavior (though I might still disagree),  
but I’d at least like to not have it change quite so drastically in a  
dot release. (Is 1.6 → 1.8 considered a dot release?)

> **···**
>
> * * *
> 
> Do you Yahoo!?  
> Yahoo! Tax Center - File online, calculators, forms, and more
> 
> > **[Taxes 2023: News, Tips, Dates & Latest Info - Yahoo Finance](https://finance.yahoo.com/taxes)**
> >
> > Find the latest tax news, tips, dates and info that you need to file taxes in 2023.

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [8 April 2003 14:35 UTC](https://rubytalk.org/t/array-sutraction/5540/12 "2003-04-08T14:35:02Z")

</div>

> From: “Michael Campbell” [michael\_s\_campbell@yahoo.com](mailto:michael_s_campbell@yahoo.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Tuesday, April 08, 2003 8:59 AM  
> Subject: Re: Array Sutraction
> 
> > > I’d view the substraction “a-b” as “remove all elements in b from  
> > > a”,  
> > > which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> > > yielding  
> > > [1,1].
> > 
> > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
> > That seems odd to me.
> 
> I agree. But the presence of a Set in 1.8  
> maes me feel better. After all, an Array  
> is not in itself a bag or a set, so we can

Hmm, I was not aware that an Array was not a bag.  
Can you give an example Hal.

> define its minus operator more or less  
> arbitrarily.  
> –^^^^^^^^^^^  
> You found the confusion. 🙂

> **···**
>
> On Tuesday, 8 April 2003 at 23:14:43 +0900, Hal E. Fulton wrote:
> 
> > ----- Original Message -----
> 
> ## – Jim Freeze
> 
> Corrupt, adj.:  
> In politics, holding an office of trust or profit.

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [8 April 2003 15:52 UTC](https://rubytalk.org/t/array-sutraction/5540/13 "2003-04-08T15:52:55Z")

</div>

I think it’s more confusing when dealing with numbers than with  
Objects.

i = Object.new # =\> #Object:0x277c230  
j = Object.new # =\> #Object:0x276fdf8  
k = Object.new # =\> #Object:0x2768898  
a = [i, j, k, i, i]

a - [i] # =\> [j, k]  
[i].each { |e| a.delete(e) }  
# =\> [j, k]

You’re removing a specific Object from an array. At least, IMO.

-austin  
– Austin Ziegler, austin@halostatue.ca on 2003.04.08 at 11:48

> **···**
>
> On Tue, 8 Apr 2003 23:33:17 +0900, Jim Freeze wrote:
> 
> > On Tuesday, 8 April 2003 at 22:59:50 +0900, Michael Campbell wrote:
> > 
> > > > I don’t find this confusing. In fact I find the implicit  
> > > > application of uniq (older version) more confusing because it is  
> > > > somewhat surprising - at least to me. In that case substraction  
> > > > indeed combines two operations.
> > > > 
> > > > I’d view the substraction “a-b” as “remove all elements in b  
> > > > from a”, which would reasonable lead to all 2’s removed from  
> > > > [1,1,2,2,2] yielding [1,1].  
> > > > So [1, 1, 2, 2] - [2] should yield the same as  
> > > > [1, 1, 2, 2] - [2, 2]?  
> > > > That seems odd to me.  
> > > > Yes. It’s not really subtraction as implied by the ‘-’ minus  
> > > > operator. Maybe it should be renamed to #remove\_all\_from. 🙂

---

<div class="post-metadata">

**Author:** ![Martin\_Bonner](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Martin\_Bonner](https://rubytalk.org/u/Martin_Bonner)\
**Post date:** [8 April 2003 15:57 UTC](https://rubytalk.org/t/array-sutraction/5540/14 "2003-04-08T15:57:45Z")

</div>

> > > I don’t find this confusing. In fact I find the implicit  
> > > application of  
> > > uniq (older version) more confusing because it is somewhat  
> > > surprising - at  
> > > least to me. In that case substraction indeed combines two  
> > > operations.
> > > 
> > > I’d view the substraction “a-b” as “remove all elements in b from  
> > > a”,  
> > > which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> > > yielding  
> > > [1,1].
> > 
> > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
> > That seems odd to me.
> 
> Yes. It’s not really subtraction as implied by the ‘-’ minus operator.  
> Maybe it should be renamed to #remove\_all\_from. 🙂

Hmm… there might still be some confusion there. I might expect that to  
remove all elements from the array. Perhaps it should be called  
#remove\_all\_elements\_equivalent\_to \*\*  
🙂

Marty

\*\* This was funny when I thought of it, but Austin, Texas has more than its  
share of allergens in the air right now, so my head feels rather like a  
recently kicked (US)football.

> **···**
>
> ----- Original Message -----  
> From: “Jim Freeze” [jim@freeze.org](mailto:jim@freeze.org)
> 
> > On Tuesday, 8 April 2003 at 22:59:50 +0900, Michael Campbell wrote:
> 
> > ## – Jim Freeze
> > 
> > F: When into a room I plunge, I  
> > Sometimes find some VIOLET FUNGI.  
> > Then I linger, darkly brooding  
> > On the poison they’re exuding.  
> > – The Roguelet’s ABC

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [8 April 2003 14:21 UTC](https://rubytalk.org/t/array-sutraction/5540/15 "2003-04-08T14:21:29Z")

</div>

That’s the most disturbing part to me.

Is there at least a warning or something?

Of course, anyone who encounters a bug can  
add his own Array#- which does a uniq after  
(or before) calling the “real” one.

Hal

> **···**
>
> ----- Original Message -----  
> From: “Michael Campbell” [michael\_s\_campbell@yahoo.com](mailto:michael_s_campbell@yahoo.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Tuesday, April 08, 2003 9:17 AM  
> Subject: Re: Array Sutraction
> 
> > > > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2,  
> > > > 2]?  
> > > > That seems odd to me.
> > > 
> > > I agree. But the presence of a Set in 1.8  
> > > maes me feel better. After all, an Array  
> > > is not in itself a bag or a set, so we can  
> > > define its minus operator more or less  
> > > arbitrarily.
> > 
> > I’ll defer to others on the behavior (though I might still disagree),  
> > but I’d at least like to not have it change quite so drastically in a  
> > dot release. (Is 1.6 → 1.8 considered a dot release?)

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [8 April 2003 16:03 UTC](https://rubytalk.org/t/array-sutraction/5540/16 "2003-04-08T16:03:24Z")

</div>

Hmmmmmmm.

x = [“one”, “one”, “two”, “two”, “two”]  
y = [“two”]

What do you want x-y to be here?

Hal

> **···**
>
> ----- Original Message -----  
> From: “Austin Ziegler” [austin@halostatue.ca](mailto:austin@halostatue.ca)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Tuesday, April 08, 2003 10:52 AM  
> Subject: Re: Array Sutraction
> 
> > > > That seems odd to me.  
> > > > Yes. It’s not really subtraction as implied by the ‘-’ minus  
> > > > operator. Maybe it should be renamed to #remove\_all\_from. 🙂
> > 
> > I think it’s more confusing when dealing with numbers than with  
> > Objects.
> > 
> > i = Object.new # =\> #Object:0x277c230  
> > j = Object.new # =\> #Object:0x276fdf8  
> > k = Object.new # =\> #Object:0x2768898  
> > a = [i, j, k, i, i]
> > 
> > a - [i] # =\> [j, k]  
> > [i].each { |e| a.delete(e) }  
> > # =\> [j, k]
> > 
> > You’re removing a specific Object from an array. At least, IMO.

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [8 April 2003 16:16 UTC](https://rubytalk.org/t/array-sutraction/5540/17 "2003-04-08T16:16:38Z")

</div>

Jim Freeze wrote:

> Hmm, I was not aware that an Array was not a bag.

[1, 2] != [2, 1]

But if they were bags (or sets), wouldn’t they be == ?

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [8 April 2003 16:30 UTC](https://rubytalk.org/t/array-sutraction/5540/18 "2003-04-08T16:30:48Z")

</div>

I believe he means that  
[1,1,2,2] - [2] =\> [1,1] instead of [1,1,2]

> **···**
>
> On Tue, Apr 08, 2003 at 11:35:02PM +0900, Jim Freeze wrote:
> 
> > > > > I’d view the substraction “a-b” as “remove all elements in b from  
> > > > > a”,  
> > > > > which would reasonable lead to all 2’s removed from [1,1,2,2,2]  
> > > > > yielding  
> > > > > [1,1].
> > > > 
> > > > So [1, 1, 2, 2] - [2] should yield the same as [1, 1, 2, 2] - [2, 2]?  
> > > > That seems odd to me.
> > > 
> > > I agree. But the presence of a Set in 1.8  
> > > maes me feel better. After all, an Array  
> > > is not in itself a bag or a set, so we can
> > 
> > Hmm, I was not aware that an Array was not a bag.  
> > Can you give an example Hal.
> 
> –  
> \_ \_
> 
> > > \_\_ \_\_ _| |_ \_\_\_ \_ \_\_ \_\_\_ \_\_ \_ \_ \_\_  
> > > '\_ \ / _`| __/__ | '_` \_ \ / ` | ’ \   
> > > ) | (| | |_\_\_ \ | | | | | (_| | | | |  
> > > .\_\_/ \_,_|\ __|__ /| |_| |_|\__,_|_| |\_|  
> > > Running Debian GNU/Linux Sid (unstable)  
> > > batsman dot geo at yahoo dot com
> 
> Remember: While root can do most everything, there are certain  
> privileges that only a partner can grant.  
> – Telsa Gwynne

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [8 April 2003 16:31 UTC](https://rubytalk.org/t/array-sutraction/5540/19 "2003-04-08T16:31:06Z")

</div>

I want [“one”, “one”, “two”, “two”, “two”], because they’re not the  
same objects.

But maybe that’s me. I’d use #delete\_if if I wanted something other  
than #delete-like behaviour. At least IMO.

-austin  
– Austin Ziegler, austin@halostatue.ca on 2003.04.08 at 12:26:54

> **···**
>
> On Wed, 9 Apr 2003 01:03:24 +0900, Hal E. Fulton wrote:
> 
> > > > > That seems odd to me.  
> > > > > Yes. It’s not really subtraction as implied by the ‘-’ minus  
> > > > > operator. Maybe it should be renamed to #remove\_all\_from. 🙂  
> > > > > I think it’s more confusing when dealing with numbers than with  
> > > > > Objects.
> > > 
> > > i = Object.new # =\> #Object:0x277c230  
> > > j = Object.new # =\> #Object:0x276fdf8  
> > > k = Object.new # =\> #Object:0x2768898  
> > > a = [i, j, k, i, i]
> > > 
> > > a - [i] # =\> [j, k]  
> > > [i].each { |e| a.delete(e) }  
> > > # =\> [j, k]
> > > 
> > > You’re removing a specific Object from an array. At least, IMO.
> 
> > Hmmmmmmm.
> > 
> > x = [“one”, “one”, “two”, “two”, “two”]  
> > y = [“two”]
> > 
> > What do you want x-y to be here?

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [10 April 2003 08:03 UTC](https://rubytalk.org/t/array-sutraction/5540/20 "2003-04-10T08:03:16Z")

</div>

“Hal E. Fulton” [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com) schrieb im Newsbeitrag  
[news:08cf01c2fde8$fde0bfc0$0300a8c0@austin.rr.com](mailto:news:08cf01c2fde8$fde0bfc0$0300a8c0@austin.rr.com)…

> Hmmmmmmm.
> 
> x = [“one”, “one”, “two”, “two”, “two”]  
> y = [“two”]
> 
> What do you want x-y to be here?

I’d expect [“one”, “one”] as a result.

```
robert

```

[Next page](https://rubytalk.org/t/array-sutraction/5540.md?page=2)
