Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concatenanation (++) on a Symbol should stay a Symbol #1830

Closed
olafklingt opened this issue Jan 28, 2016 · 4 comments
Closed

concatenanation (++) on a Symbol should stay a Symbol #1830

olafklingt opened this issue Jan 28, 2016 · 4 comments
Labels
API change comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library" enhancement stale - assign yourself to reopen This was closed due to lack of reinterest, assign yourself if you wish to reopen
Milestone

Comments

@olafklingt
Copy link
Contributor

On the mailing list a reoccurring question is why does a concatenation (++) of a symbol with something else does not stay a Symbol.
As other implementations of ++ are also aware of the Species of what is concatenated I suggest that it would be appropriate when Symbol would do the same.

@telephon telephon changed the title concatinanation (++) on a Symbol should stay a Symbol concatenanation (++) on a Symbol should stay a Symbol Jan 28, 2016
@telephon
Copy link
Member

Yes this might be right. But to be sure, let's see the way it evolved. In earlier versions of sclang, species would return (if I remember correctly) just either Array or String. So the system was simple: many operations on collections would simply return an array, and you would, after a series of operations, convert back to the class that you had started with. In most cases, this makes the most efficient procedure the default one.

Later, we decided that it was not so good that you had to write a conversion explicitly in the case of Set, where it is likely not to be efficient either. So we added to Set: species { ^this.class }.

Now indeed, ++ is a case where there are many more classes that implement it, and the receiver's class is a common return value.

Here is and overview of the current cases:

SequenceableCollection -> this.species
SparseArray -> SparseArray
Char -> String
Stream -> Stream
ArrayedCollection -> this.species
String -> String
Collection -> this.class
Nil -> the receiver class
Dictionary -> this.class
Symbol -> String
Pattern -> Pattern

(edit)

Here is the same divided into two groups:

// uniform:
SparseArray -> SparseArray
Array -> Array
String -> String
Collection -> Collection (via this.class) (Set, Range, Interval, Pair, Bag, various dictionaries)
Dictionary -> Dictionary (via this.class)
Pattern -> Pattern (may behave differently)
Stream -> Stream (may behave differently)

// non-uniform
SequenceableCollection -> Array (via this.species)
ArrayedCollection -> Array (via this.species)
Char -> String
Nil -> the receiver class
Symbol -> String

@telephon
Copy link
Member

So one thing that we should keep in mind: if you do something like the following:

a = \rocky;
1000.do { a = a ++ "abcdefghi".choose };

this will create 1000 new symbols in the symbol table, if you change the current behaviour.

while it can be written like this, without this side effect:

a = \rocky;
1000.do { a = a ++ "abcdefghi".choose };
a = a.asSymbol;

If I see it correctly, we already have a "leak" in the symbol table when you varying send strings over OSC, but that is another issue: #1029.

@olafklingt
Copy link
Contributor Author

ok that is to some degree an issue when you do something like
\gain++++\off++++6++\th++_+\filter
...
when does something like this becomes in a real world scenario a problem?

The other cases of non-uniformity are logical
the collections are classes can not be used directly:
SequenceableCollection -> Array (via this.species)
ArrayedCollection -> Array (via this.species)

two chars are a string i would say.
Char -> String

I am unsure about the behaviour of Nil.
Nil -> the receiver class

  1. leave it as it is
  2. return an error because why should ++ be implemented for Nil ?

@telephon
Copy link
Member

telephon commented Feb 8, 2016

when does something like this becomes in a real world scenario a problem?

I am not sure, it may amplify the issue described above when generating a lot of names. In any case, should we change it, we should not forget to document that the new usage is gain.asString ++ '_' ++ \off ++ _ ++ 6 ++ \th ++ _+\filter.

The other cases of non-uniformity are logical. the collections are classes can not be used directly.

You can use them directly: a = ArrayedCollection[]; that a = SequenceableCollection[]; throws an error is a bug, I think. But you are right that normally they are not used directly.

The Nil behaviour is intended, and well decided, I think. Also changing it would break a lot of code in weird places.

@telephon telephon added this to the 3.8 milestone Mar 4, 2016
@telephon telephon added enhancement comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library" API change labels Mar 4, 2016
@nhthn nhthn modified the milestones: 3.8, 3.9 Jan 15, 2017
@nhthn nhthn modified the milestones: 3.9, 3.9.x Oct 28, 2017
@muellmusik muellmusik added the stale - assign yourself to reopen This was closed due to lack of reinterest, assign yourself if you wish to reopen label Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library" enhancement stale - assign yourself to reopen This was closed due to lack of reinterest, assign yourself if you wish to reopen
Projects
None yet
Development

No branches or pull requests

4 participants