Is there anyway to check whether a symbol already exists?
.hc
------------------------------------------------------------------------ ----
Mistrust authority - promote decentralization. - the hacker ethic
Quoting Hans-Christoph Steiner hans@eds.org:
Is there anyway to check whether a symbol already exists?
i don't know of any.
2 suggestions: a) a symbol is a pointer if you get a symbol as "t_symbol*s" and s!=NULL, then you can safely assume that the symbol already exists (except someone evil sent you garbage) so you can implement: int symbol_exists(t_symbol*s) { return (0!=s); }
b) you can always make sure, that a certain string is always represented as a symbol; which guarantees that your symbol exists. int symbol_exists(char*string) { gensym(string); return 1; }
in practice, i think both implementations are rather a joke. what do you need this for?
finally, you can bind a "class" to a symbol and lookup the class by it's name.
fma.dsr IOhannes
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Nov 24, 2007, at 4:32 AM, zmoelnig@iem.at wrote:
Quoting Hans-Christoph Steiner hans@eds.org:
Is there anyway to check whether a symbol already exists?
i don't know of any.
2 suggestions: a) a symbol is a pointer if you get a symbol as "t_symbol*s" and s!=NULL, then you can safely assume that the symbol already exists (except someone evil sent you garbage) so you can implement: int symbol_exists(t_symbol*s) { return (0!=s); }
b) you can always make sure, that a certain string is always represented as a symbol; which guarantees that your symbol exists. int symbol_exists(char*string) { gensym(string); return 1; }
in practice, i think both implementations are rather a joke. what do you need this for?
finally, you can bind a "class" to a symbol and lookup the class by it's name.
I was thinking if using this to check whether a libdir had loaded its associated DLL so it wouldn't be opened multiple times with dlopen (). But I think dlopen() has an associated technique to check, so I'll try that.
.hc
fma.dsr IOhannes
This message was sent using IMP, the Internet Messaging Program.
PD-dev mailing list PD-dev@iem.at http://lists.puredata.info/listinfo/pd-dev
------------------------------------------------------------------------ ----
All mankind is of one author, and is one volume; when one man dies, one chapter is not torn out of the book, but translated into a better language; and every chapter must be so translated.... -John Donne
On Fri, 23 Nov 2007, Hans-Christoph Steiner wrote:
Is there anyway to check whether a symbol already exists?
As a normal external, the best you can do as an external is to check whether a symbol is used as receive-symbol or not. You can't do anything about the existence of a symbol apart from ensuring that it exists by calling gensym().
If you want to go abnormal, use do_gensym() directly. The second argument is a symbol that will be returned to you if there is no symbol corresponding to the second argument. (If the second argument is a null pointer, it does the same as gensym())
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
On Mon, 26 Nov 2007, Mathieu Bouchard wrote:
If you want to go abnormal, use do_gensym() directly. The second argument is a symbol that will be returned to you if there is no symbol corresponding to the second argument. (If the second argument is a null pointer, it does the same as gensym())
ERRATA:
... if there is no symbol corresponding to the first argument.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada