How about a LENGTH operator?

This forum is for discussing the development of Rel examples and sample applications.
Post Reply
HughDarwen
Posts: 124
Joined: Sat May 24, 2008 4:49 pm

How about a LENGTH operator?

Post by HughDarwen »

I found the package of FOREIGN string operators not only very useful but also informative--even though I don't know Java I might just be able to learn enough from them to write a simple FOREIGN operator myself!

I was surprised not to find OPERATOR LENGTH ( C CHAR ) RETURNS INTEGER in that package, but I did spot LAST_INDEX_OF and so was easily able to make my own NATIVE (?) implementation of LENGTH:

OPERATOR LENGTH ( C CHAR ) RETURNS INTEGER ; RETURN LAST_INDEX_OF ( C, '' ) ; END OPERATOR ;

which pleased me no end!

Now tell me that LENGTH is defined in some other package, or there's some other reason why I din't need to do that.

Hugh
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: How about a LENGTH operator?

Post by Dave »

In versions of Rel prior to 0.3.x, LENGTH was a built-in operator. I forgot to include it in OperatorsChar.d when I released the 0.3.x series.

It will be available in the next update (0.3.13), but for now, here's what it should have been:

Code: Select all

OPERATOR LENGTH(s CHAR) RETURNS INTEGER Java FOREIGN
	return new ValueInteger(s.stringValue().length());
END OPERATOR;
Of course, your LENGTH operator is just as good!
Post Reply