1. Re: type string
At 11:27 PM 11-03-1999 , you wrote:
>Daniel Berstein <daber at PAIR.COM> wrote:
>
>>Here's my record breaking string type check:
>>
>>global type string5(object s)
>> object c
>> if not sequence(s) then
>> return 0
>> end if
>> for j = 1 to length(s) do
>> c = s[j]
>> if sequence(c) or floor(c/255) or not c then
>> return 0
>> end if
>> end for
>> return 1
>>end type
>
>Um...this routine allows the "string" to be a sequence of floating-point
>values...
>
>? string5({2.71828, 3.14159}) -- returns TRUE!
Yes, I know. Try this:
sequence s
s="hello world\n"
puts(1,s)
s+=0.5
puts(1,s)
Empirically I assumed fp numbers ARE valid characters in Euphoria. Sequence
subscripts act the same, very consistent implementation Rob :)
I wonder if puts, printf and sprintf do internally the conversion to
integer values?
BTW the results I got from my benchmark are (order from fastest to
slowest): string5, string4, string2, string3, string1. Can you confirm that
under plain DOS (NT doesn't have DOS at all, it just emulates it)?
Another thing (that I didn't knew) I discovered while optimzing the string
type is that the upper limit of a for loop is only evaluated once for the
whole loop, that's why there is no penalty by using length(s) as the loop
limit.
Euphoria keeps surprising me every day.
I understand (but not agree) Rob's opinion in not creating "limited"
sequences (fixed uni/bi/n dimensional), but given we already have an
integer type (subset of atom), there could also be a byte type (unsigned
char). A byte type is very useful for string and file
operations/manipulation. I know they won't be as fast as integers on 32bit
word machines, but should be faster than Euphorically breaking 32bit values
into 8bit ones.
Regards,
Daniel Berstein
[daber at pair.com]