Available data types and operations, type casts on primitive types

1 view
Skip to first unread message

Rene Freude

unread,
Sep 10, 2007, 8:59:57 AM9/10/07
to Tef...@googlegroups.com
Hello

Where can I find a list of data types and operations on data types which are supported in Tefkat?

How can type casts on primitive data types be done? For example, how to cast a String which represents a number to an Integer.

Best regards

René

michael lawley

unread,
Sep 11, 2007, 2:25:13 AM9/11/07
to Tef...@googlegroups.com
On 10/09/2007, Rene Freude <rene....@student.hpi.uni-potsdam.de> wrote:

> Where can I find a list of data types and operations on data types which are supported in Tefkat?
>
> How can type casts on primitive data types be done? For example, how to cast a String which represents a number to an Integer.

Hi René,

This kind of support has been added on an as-needed basis and thus
Tefkat currently supports four basic "primitive" types using the
underlying Java classes Boolean, String, Long, and Double. Thus you
can invoke any of the associated Java methods on them as well as
construct the normal set of arithmetic expression for the numeric
types with +, -, *, and /. Tefkat also attempts to automatically do
what you want with these values, converting between them as required.
For example if 'age' is an integer-type attribute, then SET x.age =
"22" will automatically parse the String 22 into an int.

If you need to force a conversion for any reason (i.e., to select a
specific method when there are several overload versions), then there
are functions int(), long(), float(), and double() that treat their
arguments as Strings to be parsed appropriately.

String functions:
* append() takes zero or more arguments and concatenates them;
* join() takes a separator (String) and either a collection or 1 or
more subsequent arguments and concatenates the collection members or
the subsequent arguments separated by the first argument (e.g., x =
join(", ", 1, 2, 3, 4) or y = x.attr{} AND z = join(":", y));
* split() takes a String to split and a regex (e.g., x =
split("1,2,3,4", ",")); and
* stripSuffix() takes a string and a suffix and returns the string
with the suffix removed ("foo" = stripSuffix("foo.txt", ".txt") and
"foo.txt" = stripSuffix("foo.txt", ".xml")

For collections:
* elementAt(list, index) returns the element of list at the given index
* subList() takes a list and either one or two indicies and returns a
sublist starting from the first index and ending at the second index
(or the end of the list if only one index is supplied)

If there are other functions or data types that you feel need to be
supported then please let us know.

Regards,

michael

RFR

unread,
Sep 11, 2007, 7:39:56 AM9/11/07
to Tefkat
Thanks a lot for fast and extensive reply!
For the next questions I have chosen to make separate entries. This
way the topics might be better to detect for others.

Best regards
René

RFR

unread,
Sep 18, 2007, 4:51:57 AM9/18/07
to Tefkat
Hi again,

Another question on primitive types: Is it possible to use a primitive
type in the FROM part of a rule? Something like:

FROM Class c, String s
WHERE c.asso = s
MAKE ComplexString cs
SET cs.value = s

I want to wrap all primitive Strings s (unbounded property) of Class c
with Association asso.

Regards
René

On 11 Sep., 08:25, "michael lawley" <mich...@lawley.id.au> wrote:

michael lawley

unread,
Sep 18, 2007, 7:12:16 PM9/18/07
to Tef...@googlegroups.com
Hi René,

You can't range over primitive types in a FORALL since they constitute
an infinite domain. However, for most (all?) practical purposes it
shouldn't be a problem since the actual values you need to range over
are constrained by the range of some attribute in the source model.

In you example, you can simply write:

RULE R
FORALL Class c
WHERE c.asso = s
MAKE ComplexString cs FROM cs(c, s)
SET cs.value = s
;

which will create one ComplexString instance per unique Class, string
pair. If you only want one per unique string, then you would use FROM
cs(s) instead.

Cheers,

michael

Reply all
Reply to author
Forward
0 new messages