librelist archives

« back to archive

STRING.intern

STRING.intern

From:
Paolo Redaelli
Date:
2012-02-24 @ 08:58
I'm trying to make ZMQ_STRING_MESSAGE a proper heir of 
NATIVELY_STORED_STRING.
Digging in the code I read in STRING:
    intern: FIXED_STRING is
          -- A shared version of this string.
       local
          strings: FAST_ARRAY[FIXED_STRING]
          i: INTEGER
       do
          strings := interned.reference_at(hash_code)
          if strings = Void then
             create strings.with_capacity(4)
             interned.add(strings, hash_code)
          end
          from
             i := strings.lower
          until
             Result /= Void or else i > strings.upper
          loop
             if strings.item(i).same_as(Current) then
                Result := strings.item(i)
             end
             i := i + 1
          end
          if Result = Void then
             create Result.make_from_string(Current)
             Result.do_intern(strings)
          end
       end

Which seems to me pretty generic. Is there a specific reason not to put 
it into ABSTRACT_STRING?

     Paolo

Re: [libertyeiffel] STRING.intern

From:
Cyril Adrian
Date:
2012-02-24 @ 12:13
Hi Paolo,

*intern* is defined in STRING in order to use the FIXED_STRING.*
make_from_string* constructor.

Other implementations usually just do

   intern: FIXED_STRING *is*
      *do*
         Result := out.intern
      *end*

(or something similar, see LAZY_STRING for instance)

cheers

 *Cyril ADRIAN* *(from office)*
http://www.cadrian.net/cyril
[image: Twitter] <http://twitter.com/cadbart> [image:
LinkedIn]<http://fr.linkedin.com/in/cadrian> [image:
Google Plus] <https://plus.google.com/u/0/100388810006463519079/> [image:
Google 
Calendar]<https://www.google.com/calendar/embed?src=1t93vvvrdc26ee0f83p0cunj60%40group.calendar.google.com&ctz=Europe/Paris>
Contact me: [image: Google Talk] cyril.adrian@gmail.com
 [image: Twitter] <http://twitter.com/cadbart> Latest tweet: [Liberty]
http://t.co/fJhPszSJ Cyril Adrian - Let the programmer decide what he wants
to do when an exception occurs (don't ignore so man...
Follow @cadbart <http://twitter.com/cadbart> Reply

<http://twitter.com/?status=@cadbart%20&in_reply_to_status_id=162264499590660100&in_reply_to=cadbart>
Retweet

<http://twitter.com/?status=RT%20%40cadbart%3A%20%5BLiberty%5D%20http%3A%2F%2Ft.co%2FfJhPszSJ%20Cyril%20Adrian%20-%20Let%20the%20programmer%20decide%20what%20he%20wants%20to%20do%20when%20an%20exception%20occurs%20(don't%20ignore%20so%20man...>
 21:04 Jan-25<http://twitter.com/cadbart/statuses/162264499590660097>
  Get this email app!

<http://www.wisestamp.com/apps/twitter?utm_source=extension&utm_medium=email&utm_term=twitter&utm_campaign=apps>

 [image: Google Plus] <http://plus.google.com/100388810006463519079> My
latest G+: Prochains concerts de Contraste : Victor Hugo et la Musiqueen
partenariat avec l'Orchestre Besançon-Montbéliard Franche-Comté - vendredi
10/02 (Kursaal, Besançon, 20h00) - samedi 11/02 (MA scène nationale,
Montbéliard, 20h00) - dimanche 12/02
(Sa...<http://plus.google.com/100388810006463519079/posts/Nozsd4fh2M4/>
My G+ <http://plus.google.com/100388810006463519079> -
Posts<http://plus.google.com/100388810006463519079/posts/>- Add
to Circles <http://plus.google.com/100388810006463519079/about/> - 13:31
Feb-09 <http://plus.google.com/100388810006463519079>
  Get this email app!

<http://www.wisestamp.com/apps/plus?utm_source=extension&utm_medium=email&utm_term=plus&utm_campaign=apps>

  <http://www.linkedin.com/in/cyril.adrian>
  Want a signature like mine?

<http://r1.wisestamp.com/r/landing?promo=22&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_22>
Click

here.<http://r1.wisestamp.com/r/landing?promo=22&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_22>



2012/2/24 Paolo Redaelli <paolo.redaelli@gmail.com>

> I'm trying to make ZMQ_STRING_MESSAGE a proper heir of
> NATIVELY_STORED_STRING.
> Digging in the code I read in STRING:
>    intern: FIXED_STRING is
>          -- A shared version of this string.
>       local
>          strings: FAST_ARRAY[FIXED_STRING]
>          i: INTEGER
>       do
>          strings := interned.reference_at(hash_code)
>          if strings = Void then
>             create strings.with_capacity(4)
>             interned.add(strings, hash_code)
>          end
>          from
>             i := strings.lower
>          until
>             Result /= Void or else i > strings.upper
>          loop
>             if strings.item(i).same_as(Current) then
>                Result := strings.item(i)
>             end
>             i := i + 1
>          end
>          if Result = Void then
>             create Result.make_from_string(Current)
>             Result.do_intern(strings)
>          end
>       end
>
> Which seems to me pretty generic. Is there a specific reason not to put
> it into ABSTRACT_STRING?
>
>     Paolo
>
>

Re: [libertyeiffel] STRING.intern

From:
Paolo Redaelli
Date:
2012-02-24 @ 14:18
Il 24/02/2012 13:13, Cyril ADRIAN ha scritto:
> Hi Paolo,
>
> /intern/ is defined in STRING in order to use the 
> FIXED_STRING./make_from_string/ constructor.
>
> Other implementations usually just do
>
>    intern: FIXED_STRING *is*
> *do*
>          Result := out.intern
> *end*
>
> (or something similar, see LAZY_STRING for instance)
>
Quite clear... I was going to answer without thinking too much about it 
"Then if I understand it a little and "other implementation usually" 
could mean "most implementation will" we may just put this 
implementation in ABSTRACT_STRING and redefine it in FIXED_STRING." ....
  But this means that out must be a FIXED_STRING, so I was actually 
going to propose to insert a potentially infinite and subtle loop... oh, 
how smart I am! 8-P