Re: Euphoria 2.5 Features..... ??

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
>From: Isaac Raway 
>Subject: Re: Euphoria 2.5 Features..... ??
>
>
>
>Concerning strings; Paul Graham Wrote an excellent 
>article a few months ago that has a section very 
>pertinent to this concept of adding a string type.
> By the way, my final vote is *don't add strings*, 
>just make the interpreter optimize sequences that 
>are only made of characters. We don't need a 
>string data type. We just need the sequence data 
>type to be a bit smarter.

Well, I tend to have a different opinion. That's because I view the current
Euphoria idiom of a sequence as being a variable length list of objects, but a
string is a variable list of characters. And we all know that an object is not
the same as a character. An object is an entity whose value's datatype can be a
sequence, atom, or integer, with no additional  restrictions on their value
domain. But a character is an integer and is constrained to the value domain zero
to some upper limit, depending on the encoding method in use. For example, ASCII
and UTF-8 have the upper limit of 255, UTF-16 has the upper limit of 2^16, etc...

The problem we have with Euphoria is that there is no way that we can tell it
that a sequence CAN only contain characters in an effecient manner. The 'type'
mechanism can be used, but it has some overheads.

 type string(sequence x)
  for i = 1 to length(x) do
    if not integer(x[i]) then
        return 0
    end if
    if x[i] < 0 or x[i] > EncodingMaxLimit then
        return 0
    end if
  end for
  return 1
 end type

Now we can force Euphoria to support strings, but still not waste RAM.

string Name
Name = "Derek" -- okay, this works.
Name[3] = 2.345 -- This should now fail.

But without this 'hint', Euphoria would be quite happen to turn a 'string' back
in to an ordinary sequence again.

Thus, I would argue that a string type needs to be built into Euphoria before we
gain both efficiency in speed and in RAM usage.

-- 
Derek

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu