[PD] Problem with lists and data

Thomas Mayer thomas at residuum.org
Thu Sep 1 00:17:51 CEST 2011

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]);

Now, it is working as intended. Is this the "standard" way in C to get 
possible floats out of strings?

Best regards,
"Prisons are needed only to provide the illusion that courts and police
are effective. They're a kind of job insurance."
(Leto II. in: Frank Herbert, God Emperor of Dune)

More information about the Pd-list mailing list