Hi,
When trying to use [expr size("arrayname")] to get the size of an array, some array names that are legal in Pd will cause (sometimes funny) syntax errors in [expr].
It seems that for example:
and maybe other restrictions.
For example:
expr: syntax error: 1005foo")
expr: syntax error: $1foo")
expr: syntax error: missing '"'
Seems like quotes are not treated quite like one would expect...
Is there a way to work it around, or do you have to restrict array names (of which you're gonna need to know the size) to the typical rules that apply to identifier names in many popular programming languages? (but then, why are quotes needed at all??)
thanks m.
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
I didn't know about [expr size("arrayname")] before, would be great if it was widely usable!
D.
On 3/27/10 8:57 PM, Matteo Sisti Sette wrote:
Hi,
When trying to use [expr size("arrayname")] to get the size of an array, some array names that are legal in Pd will cause (sometimes funny) syntax errors in [expr].
It seems that for example:
- array name cannot start with a number (or a $n)
(it can contain a number or dollar in the middle or end)
- array name cannot contain a minus sign ("-")
(nor I guess *, + and /)
and maybe other restrictions.
For example:
- [expr size("$0foo")]
expr: syntax error: 1005foo")
- [expr size("$1foo")]
expr: syntax error: $1foo")
- [expr size("foo-bar")]
expr: syntax error: missing '"'
Seems like quotes are not treated quite like one would expect...
Is there a way to work it around, or do you have to restrict array names (of which you're gonna need to know the size) to the typical rules that apply to identifier names in many popular programming languages? (but then, why are quotes needed at all??)
thanks m.
Sorry, meant this in second example:
[bang< | [f $0] | [expr size("$0foo")]
But you probably knew that!
D.
On 3/27/10 9:04 PM, Derek Holzer wrote:
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
Arrrg, actually meant this:
[bang< | [f $0] | [expr size("$1foo")]
Maybe Saturday night isn't such a good time to post things to mailing lists...
D.
On 3/27/10 9:06 PM, Derek Holzer wrote:
Sorry, meant this in second example:
[bang< | [f $0] | [expr size("$0foo")]
But you probably knew that!
D.
On 3/27/10 9:04 PM, Derek Holzer wrote:
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
Last option would be to try using [sprintf], [makefilename] or similar to create the array name, and send to [expr size($1)] . Maybe....
Prost! D.
hello, you can use [value foo] and [expr foo*$f1] when they are in the same patch, [expr foo] wont work in another one, like with block~, that's why you won't need $0
----- Mail Original ----- De: "Derek Holzer" derek@umatic.nl À: "Matteo Sisti Sette" matteosistisette@gmail.com, "pd-list" PD-list@iem.at Envoyé: Samedi 27 Mars 2010 21h06:35 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [PD] expr size() refuses some array names
Sorry, meant this in second example:
[bang< | [f $0] | [expr size("$0foo")]
But you probably knew that!
D.
On 3/27/10 9:04 PM, Derek Holzer wrote:
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
Yes, I was going to say next that [expr] doesn't take $1 or $0, it takes $f1, $f2 etc etc. That's why it won't create.
D.
On 3/27/10 9:17 PM, colet.patrice@free.fr wrote:
hello, you can use [value foo] and [expr foo*$f1] when they are in the same patch, [expr foo] wont work in another one, like with block~, that's why you won't need $0
----- Mail Original ----- De: "Derek Holzer"derek@umatic.nl À: "Matteo Sisti Sette"matteosistisette@gmail.com, "pd-list"PD-list@iem.at Envoyé: Samedi 27 Mars 2010 21h06:35 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [PD] expr size() refuses some array names
Sorry, meant this in second example:
[bang< | [f $0] | [expr size("$0foo")]
But you probably knew that!
D.
On 3/27/10 9:04 PM, Derek Holzer wrote:
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
Derek Holzer escribió:
Yes, I was going to say next that [expr] doesn't take $1 or $0, it takes $f1, $f2 etc etc. That's why it won't create.
It does take $0 and $1 etc, it just means a completely different thing than $f1, $f2 etc.
$1 is the creation argument of the patch containing [expr] and it expands to its value, just like it would in any other object.
And regarding array names, [expr size("foo$1")] does create and does work (also with $0)
The problem is not specific to dollar signs: the problem is that expr won't accept a name (for the array in this case) that starts with a number, or that contains an aritmetical operation sign. Which, besides not allowing for names that are legal in Pd, seems like an error in the parsing process, because it seems it applies the same rules inside quotation marks that it would apply without quotes.
Maybe the same problem would apply to variables (meaning [value]s) as well as arrays, I don't know - and maybe the workaround you suggested applies to that case...
colet.patrice@free.fr escribió:
hello, you can use [value foo] and [expr foo*$f1] when they are in the same patch, [expr foo] wont work in another one, like with block~, that's why you won't need $0
Either we are not talking about the same thing or I am completely lost.
I am trying to get the size of an array...
sorry for loosing you, it was just a trick to use variables in expr... but it's also possible to use inlets with $f1, $f2, ...
why don't you resize the array? You can also use [arraysize] to get it's size
----- Mail Original ----- De: "Matteo Sisti Sette" matteosistisette@gmail.com À: "colet patrice" colet.patrice@free.fr Cc: "Derek Holzer" derek@umatic.nl, "pd-list" pd-list@iem.at Envoyé: Samedi 27 Mars 2010 21h23:49 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [PD] expr size() refuses some array names
colet.patrice@free.fr escribió:
hello, you can use [value foo] and [expr foo*$f1] when they are in the same patch, [expr foo] wont work in another one, like with block~, that's why you won't need $0
Either we are not talking about the same thing or I am completely lost.
I am trying to get the size of an array...
Derek Holzer escribió:
What if you bang a [f $1] and send it to [expr size("$1foo")]?
Likewise with "bang"--->[f $0]--->[expr size("$0foo")]?
The problem is you cannot create [expr size("$1foo")] in the first place (nor with $0): it gives the syntax error at creation time and refuses to create.
If you could, then you wouldn't need the [f $0] (the expression doesn't depend on the input)....