# Re: Bracket Packing (#78)

**URL:** <https://www.ruby-forum.com/t/re-bracket-packing-78/94515>\
**Category:** Ruby\
**Created:** [May 5, 2006, 3:55pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515 "2006-05-05T15:55:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 5, 2006, 3:55pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/1 "2006-05-05T15:55:46Z")

</div>

Quick question about the phrase ‘occasionally missing off a bracket’. Is  
it possible to have lost more than one braket missing from the string,  
or will it be a case of 0…1 brackets missing? I assume just one. If it  
is possible to have more than one bracket missing, you could never trust  
what the program was saying, even when the string was valid.

Ie, [{(B),(B)}] -\> [(B),(B)]

- Stu

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 5, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/2 "2006-05-05T16:26:57Z")

</div>

Surely that isn’t possible, some combinations could have more than one  
possible  
correction, eg:

[{BB] =\> [{B}B]  
or  
[{BB] =\> [{BB}]  
or even,  
[{BB] =\> [{}BB]  
or even, (tho presumably this is invalid - some sort of black hole  
packaging):  
[{BB]}

Perhaps the program should present the possible options and ask which is  
wanted?

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 5, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/3 "2006-05-05T16:08:33Z")

</div>

On Fri, 2006-05-05 at 22:52 +0900, Stuart H. wrote:

> Quick question about the phrase ‘occasionally missing off a bracket’. Is  
> it possible to have lost more than one braket missing from the string,  
> or will it be a case of 0…1 brackets missing? I assume just one. If it  
> is possible to have more than one bracket missing, you could never trust  
> what the program was saying, even when the string was valid.
> 
> Ie, [{(B),(B)}] -\> [(B),(B)]

Good point. Let’s assume just one bracket will be missing, if any.  
Obviously, to fix it, it needs to go back in the right place.

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 5, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/4 "2006-05-05T21:43:34Z")

</div>

On Fri, 5 May 2006 23:38:05 +0900, Ross B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> sure the packer doesn’t get in a mess, and both of those will pass  
> through fine (even if the wrappings aren’t exactly as intended).

Hmm, to clarify, brackets can have non-bracket siblings?

-mental

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 5, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/5 "2006-05-05T16:39:04Z")

</div>

On Fri, 2006-05-05 at 23:23 +0900, removed\_email\_address@domain.invalid wrote:

> Surely that isn’t possible, some combinations could have more than one possible  
> correction, eg:
> 
> [{BB] =\> [{B}B]  
> or  
> [{BB] =\> [{BB}]

Either of the above is valid - the main object of this is just to make  
sure the packer doesn’t get in a mess, and both of those will pass  
through fine (even if the wrappings aren’t exactly as intended).

> or even,  
> [{BB] =\> [{}BB]  
> or even, (tho presumably this is invalid - some sort of black hole packaging):  
> [{BB]}

Both of these are invalid, and definitely not what was intended - there  
won’t be any empty packages (as in the first case) and the second isn’t  
balanced.

> Perhaps the program should present the possible options and ask which is wanted?

If you want to output the options and fail with exitcode 1 for the  
ambiguous ones, that’s cool too.

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 6, 2006, 12:21am UTC](https://www.ruby-forum.com/t/re-bracket-packing-78/94515/6 "2006-05-06T00:21:45Z")

</div>

On Sat, 2006-05-06 at 04:42 +0900, MenTaLguY wrote:

> > Either of the above is valid - the main object of this is just to make  
> > sure the packer doesn’t get in a mess, and both of those will pass  
> > through fine (even if the wrappings aren’t exactly as intended).
> 
> Hmm, to clarify, brackets can have non-bracket siblings?

It’s technically allowed in the output, but would never occur in a  
correct input.
