[PD-dev] makefilename crash

Mathieu Bouchard matju at sympatico.ca
Sat Jan 8 13:52:40 CET 2005


On Sat, 8 Jan 2005, Tim Blechmann wrote:

> |float 4(
> |
> |makefilename CR%sSH|
> intended to crash?
> i'd somehow prefer to have a proper error message or a type conversion
> from float 4 to symbol 4 instead of a segfault ...

Hi. Let's use precedent from another language. For example, let's first
look at the sprintf from Ruby:

"%s %s %s" % [3.14,"test",:test] gives   "3.14 test test"
"%s %s %s" % [3.14,"test"]       gives error (list too short)
"%f %f" % [3.14,:test]           gives error (can't conv to float)

In the first case, 3.14 is a Float, so it gets converted to a String
before applying %s; also :test is a Symbol, so it also gets converted to a
String before applying %s.

However not all conversions are applicable, and it is important to match
list lengths with format strings (each %-code of a String requires one or
two or zero arguments, according to the same rules as in C language).

Trying the same with Python, I get similar results. The differences are:
there is no Symbol datatype, only String; I had to replace [] by ()
because Python has two kinds of lists and it wants ()-lists there; and the
Floats have a different default formatting in converting to String,
apparently %.6f instead of just %f.

Plus I'd rather have [makefilename] be named differently, because it
clearly gets used for much more than just filenames. maybe
[formatsymbol]. I'd suggest [sprintf] if not for nameclashes.

_____________________________________________________________________
Mathieu Bouchard -=- Montréal QC Canada -=- http://artengine.ca/matju





More information about the Pd-dev mailing list