[kepler-dev] Re: Fun with the Ptolemy II expression language

Tobin Fricke tobin at splorg.org
Wed Aug 4 23:10:06 PDT 2004

On strings, '+' does concatenation:

>> "foo" + "bar"

This gives us a "poor man's printf" using 'sum':

>> sum({"foo", "bar"})

(It seems that this is incredibly slow for large arrays of strings.. maybe
some clever check for {string} could use an alternate implementation of
'sum' that would use a StringBuffer for better efficiency?)

The 'toString' method is also exposed, although I think it will get called
implicitly in almost any circumstance where you'd want to use it.  You can
even call a method on a literal:

>> 4.toString

I can use the "poor man's sprintf" trick to turn an array of records
{{x=double,y=double,z=double}} into a command for gnuplot:

>> gnuplotify = function(x:{{x=double,y=double,z=double}})
("splot '-'\n" + sum(map(function(tuple:{x=double,y=double,z=double})
sum({tuple.x, " ", tuple.y, " ", tuple.z, "\n"}),x)) + "e\n")

>> gnuplotify({{x=0,y=0,z=0},{x=0,y=1,z=2},{x=1,y=0,z=1},{x=1,y=1,z=1.5}})
"splot '-'
0 0 0.0
0 1 2.0
1 0 1.0
1 1 1.5

The 'workflows/orb/GnuplotSurfaceDemo.xml' model I just comitted to Kepler
CVS combines the grid forming trick with the gnuplot trick to plot an
arbitrary function of two variables.


More information about the Kepler-dev mailing list