# Hi all, # is there a way of knowing the number of creation arguments of an abstraction in the scope of the abstraction while loading it. # I want to load the parameters of an abstraction from a file. But if no arguments are given, default parameters will be loaded.
ex: [abst] [abst param1.dat]
# I made something like this:
[loadbang] | [symbol $1] | [read $1( | [qlist]
etc.
# But, of course, this gives an error when there are no creation arguments. error: : can't open error: : read failed
# So, I thought that, if there exists some mechanism to know about the number of creation arguments, like argc and argv variables in C, the abstraction can behave according to it. # By the way, this error is harmless but getting an error every time creating that abstraction seems uncomfortable.
-ugur guney-
Hallo, sokratesla hat gesagt: // sokratesla wrote:
# Hi all, # is there a way of knowing the number of creation arguments of an abstraction in the scope of the abstraction while loading it. # I want to load the parameters of an abstraction from a file. But if no arguments are given, default parameters will be loaded.
ex: [abst] [abst param1.dat]
# I made something like this:
[loadbang] | [symbol $1] | [read $1( | [qlist]
etc.
# But, of course, this gives an error when there are no creation arguments.
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments. Instead of [symbol $1] I would maybe use [list $1], which can deal with both symbols and floats. Then just connect the [list] to the [select] and use the right outlet of [select] to go to the [read $1( message. You can also connect a message with a default value to the left outlet of [select], which will be banged if you didn't supply an argument.
Frank Barknecht _ ______footils.org_ __goto10.org__
# Thank you very much, Frank! # Using list instead of symbol solves my problem. Perhaps it will be good, if there were an equivalent of zero in symbol domain, ie. an empty symbol(?) # And a small detail: Pd couldn't create [list $1] in the scope of the abstraction. Because, if I understood correctly, [list $1] turns into [list fileName] but there isn't that kind of a list. Instead, I wrote [list append $1] and that worked. # Thanks again! -ugur guney-
On 7/21/06, Frank Barknecht fbar@footils.org wrote:
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments. Instead of [symbol $1] I would maybe use [list $1], which can deal with both symbols and floats. Then just connect the [list] to the [select] and use the right outlet of [select] to go to the [read $1( message. You can also connect a message with a default value to the left outlet of [select], which will be banged if you didn't supply an argument.
Ciao
Frank Barknecht _ ______footils.org_ __goto10.org__
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Hallo, sokratesla hat gesagt: // sokratesla wrote:
# Using list instead of symbol solves my problem. Perhaps it will be good, if there were an equivalent of zero in symbol domain, ie. an empty symbol(?) # And a small detail: Pd couldn't create [list $1] in the scope of the abstraction. Because, if I understood correctly, [list $1] turns into [list fileName] but there isn't that kind of a list. Instead, I wrote [list append $1] and that worked.
Yes, you've found it: I forgot the "append", sorry. ;)
Frank Barknecht _ ______footils.org_ __goto10.org__
On Fri, 21 Jul 2006, Frank Barknecht wrote:
# But, of course, this gives an error when there are no creation arguments.
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments.
If someone really wants to have $1 = 0, how is that unwanted?
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
Hallo, Mathieu Bouchard hat gesagt: // Mathieu Bouchard wrote:
On Fri, 21 Jul 2006, Frank Barknecht wrote:
# But, of course, this gives an error when there are no creation arguments.
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments.
If someone really wants to have $1 = 0, how is that unwanted?
It's an unwanted problem with Pd's argument passing.
Frank Barknecht _ ______footils.org_ __goto10.org__
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
Mathieu Bouchard hat gesagt: // Mathieu Bouchard wrote:
On Fri, 21 Jul 2006, Frank Barknecht wrote:
# But, of course, this gives an error when there are no creation arguments.
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments.
If someone really wants to have $1 = 0, how is that unwanted?
It's an unwanted problem with Pd's argument passing.
And there are two ways out: One is IEMlib's [dollarg], the other would be to introduce a special symbol for 0, like "ZERO" and use something like:
[select 0] | [select ZERO] | [0(
Of course then you cannot have $1 = ZERO (the symbol) anymore.
Frank Barknecht _ ______footils.org_ __goto10.org__
Maybe there should be an undefined type in PD...
a "undef" or something so that you can test arguments against it. (or another special $ variable in an abstraction would be the arg count, like argv/argc stuff:
[float $$] <- number of args to this abstraction
[float $1] <- first arg
[float $0] <- unique ID for abstraction
I guess $-1 could also work, but looks really junky.
Actually I would prefer something like [float $argc] [float $unique]
but thats me and words...
.b.
Frank Barknecht wrote:
Hallo, Mathieu Bouchard hat gesagt: // Mathieu Bouchard wrote:
On Fri, 21 Jul 2006, Frank Barknecht wrote:
# But, of course, this gives an error when there are no creation arguments.
As missing arguments are initialized to 0 you can use a [select 0] to filter out unwanted arguments.
If someone really wants to have $1 = 0, how is that unwanted?
It's an unwanted problem with Pd's argument passing.
Ciao