Looking for thoughts: Append collections with objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Looking for thoughts: Append collections with objects

Nicolas Cellier
Michael Lucas-Smith <michael.lucassmith <at> gmail.com> writes:

>
> I'm looking for some feedback on an API that has been proposed for appending
collections with
> non-collections. So let me describe the desired behavior:
>
> #(1) & 2 -> #(1 2)
> #(1) & #(2) -> #(1 2)
> 1 & #(2) -> #(1 2) * note 1
> 1 & 2 -> #(1 2)
> #a & #b -> #(#a #b) * note 2
>
> note 1: the #& api is based off of ScriptingSupport which does not produce
this result, instead it gives you

> #(1 #(2))
> note 2: the #, api in Smalltalk-80 would produce 'ab'
>
> First question: Do you desire this kind of behavior?
> Sub question 1: Where do you use this kind of behavior?
> Sub question 2: Have you implemented this in your own libraries?
> Sub question 3: You hate it, why?
>
> Second question: What do you think of using #& for this kind of behavior?
> Sub question 1: Do you have another suggested binary selector?
>
> My thoughts on the subject: I find this approach to appending much more
convenient when doing scripting. I
> also think #& might be a bad choice as we'd never be able to create
collections from booleans. Perhaps /\ to
> append two objects and \/ to create a set from two objects. I saw /\ and \/
used as binary operations in Slate
> and thought it was quite an interesting use.
>
> Michael
>

It reminds me recent squeak-dev
http://thread.gmane.org/gmane.comp.lang.smalltalk.squeak.general/149213

& operator seems natural to me.
Once I used & for concatenating matrix columns and | for concatening rows, with
extension to scalar, thus (in matlab notation)

1 & 2 -> [1 , 2 ]
1 | 2 -> [1 ; 2 ]

Note that in Squeak these are , and ,, (; is already for cascades...)

See also
http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28string_functions%29#Concatenation

(there were no Smalltalk here, a shame)

Of course, you propose & rather than , so it must be clear that the right answer
is the second one:

$a & ' mouse' -> #($a ' mouse').
$a & ' mouse' -> #($a $  $m $o $u $s $e).
$a & ' mouse' -> 'a mouse'.

Alternatively there could be a kind of "escape" to just mean take the object as
a whole rather than the elements.

$a &/ ' mouse' -> #($a ' mouse').

Symmetricaly,

'mice' /& 'cats' -> #('mice' $c $a $t $s).

and maybe

'mice' /&/ 'cats' -> #('mice' 'cats')

Just my stupid late evening idea

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
12