On Dec 17, 2006, at 1:36 AM, Mathieu Bouchard wrote:
On Sat, 16 Dec 2006, Martin Peach wrote:
What if strings could be automatically cast to symbols for externals that would rather have symbols, and vice-versa?
I have written an external asc2sym that takes lists of bytes and splits them into symbols based on the argument(s) which are characters. But it seems important to avoid symbols as much as possible to avoid filling up the symbol table with symbols that are referenced only once..
Yes, but my reason for wanting this, is that all externals currently available understand symbols but not strings. So, what if you want to make strings as widely used as possible, as easily as possible, and working with all externals currently available in Pd?
You make them work as strings when they can, and You make them work as symbols when they must.
A string could be considered unused when its length is set to 0.
If you want to use a string as a mutable buffer, then you want to be able to have 0-length strings, as a boundary condition: you start with nothing and then add to it. You don't want to have to start with something just because setting the length to 0 would delete it.
It seems that you are suggesting that the deallocation would be user-controlled? Then how do you prevent the user from crashing pd? If you use a weak-pointer as an intermediate (like t_gpointer or t_gfxstub), then you still have to manage reference counts. Whatever you do for the user, you have to know more about externals' behaviour than what they tell you now, because right now they don't deallocate atoms explicitly.
But if strings are going to be deallocated explicitly and there is not going to be any checks, why not instead make something that will allow users to deallocate symbols. It's about as safe as that and you don't need to introduce a string type.
Memory would need to be dynamically allocated in small blocks.
What do you mean "in small blocks" ?
The API should return "no method for string" if the external doesn't implement strings.
That's aiming low. Why shouldn't there be any automatic casts between the two?
Automatic type conversion sounds like a really bad idea if the language only partially supports it. Pd is strongly typed, so what Martin says is definitely appropriate. Perl is the opposite, everything can be automatically cast, so there it makes sense.
So... anyone want to code up some of these ideas? We could try them out in the next Pd-extended.
.hc
------------------------------------------------------------------------
There is no way to peace, peace is the way. -A.J. Muste