Hi there,
while developping my CouchPdb library I came up with the following problem:
I put out lists like this:
list _id 1 list pitch 440
Now I am trying to get the values for _id and pitch as floats, but that does not seem to work:
[couchdb] | [list trim] | [route _id pitch] \ | \ | [f] [f]
But I am always getting the message:
error: inlet: expected 'float' but got '1'
When I try to use [symbol] instead of [f], I get a similar error message.
In my object I do the following:
t_atom out_data[2] SETSYMBOL(&out_data[0], gensym(key)); SETFLOAT(&out_data[1], json_object_get_double(val)); outlet_list(data_outlet, &s_list, 2, &out_data[0]);
What am I doing wrong?
Best regards, Thomas
----- Original Message -----
From: Thomas Mayer thomas@residuum.org To: "pd-list@iem.at" pd-list@iem.at Cc: Sent: Wednesday, August 31, 2011 4:28 PM Subject: [PD] Problem with lists and data
Hi there,
while developping my CouchPdb library I came up with the following problem:
I put out lists like this:
list _id 1 list pitch 440
Now I am trying to get the values for _id and pitch as floats, but that does not seem to work:
[couchdb] | [list trim] | [route _id pitch] \ | \ | [f] [f]
But I am always getting the message:
error: inlet: expected 'float' but got '1'
That probably means you're formatting that part of your list as symbol-atom '1' instead of float-atom '1'.
Thus, the [route] object is outputting symbol-atom '1', which is just a message where the selector is the symbol-atom '1'. The right inlet of [f] has a method for messages with the selector 'float', but it doesn't have a symbol-atom '1' method, so you get the error.
-Jonathan
When I try to use [symbol] instead of [f], I get a similar error message.
In my object I do the following:
t_atom out_data[2] SETSYMBOL(&out_data[0], gensym(key)); SETFLOAT(&out_data[1], json_object_get_double(val)); outlet_list(data_outlet, &s_list, 2, &out_data[0]);
What am I doing wrong?
Best regards, Thomas -- "Chaney was aware that anything, however small, can get the eye of the media if it's repulsive enough." (Robert Anton Wilson - The Universe Next Door) http://www.residuum.org/
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 31.08.2011 23:19, Jonathan Wilkes wrote:
That probably means you're formatting that part of your list as symbol-atom '1' instead of float-atom '1'.
Thus, the [route] object is outputting symbol-atom '1', which is just a message where the selector is the symbol-atom '1'. The right inlet of [f] has a method for messages with the selector 'float', but it doesn't have a symbol-atom '1' method, so you get the error.
Yes, that gave me a pointer to the problem (for those interested, see below)
In my object I do the following:
t_atom out_data[2] SETSYMBOL(&out_data[0], gensym(key)); SETFLOAT(&out_data[1], json_object_get_double(val)); outlet_list(data_outlet,&s_list, 2,&out_data[0]);
What am I doing wrong?
CouchDB more or less always quotes the values, so it is a JSON string, which I now parse with:
case json_type_string: SETSYMBOL(&out_data[0], gensym(key)); /* Float values might come as string */ const char *string_value = json_object_get_string(val); float_value = atof(string_value); if (float_value == 0 && strcmp(string_value, "0") != 0) { SETSYMBOL(&out_data[1], gensym(string_value)); } else { SETFLOAT(&out_data[1], float_value); } outlet_list(data_outlet, &s_list, 2, &out_data[0]); break;
Now, it is working as intended. Is this the "standard" way in C to get possible floats out of strings?
Best regards, Thomas
On Thu, 1 Sep 2011, Thomas Mayer wrote:
if (float_value == 0 && strcmp(string_value, "0") != 0) { SETSYMBOL(&out_data[1], gensym(string_value)); } else { SETFLOAT(&out_data[1], float_value); } Now, it is working as intended. Is this the "standard" way in C to get possible floats out of strings?
It will not catch "-0".
I think that comparing pointers of strtof() is a safer bet... though "-0" rarely happens.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC