Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
String-literal interning?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Darshan Shaligram  
View profile  
 More options Mar 14 2008, 4:34 am
From: "Darshan Shaligram" <scinti...@gmail.com>
Date: Fri, 14 Mar 2008 14:04:19 +0530
Local: Fri, Mar 14 2008 4:34 am
Subject: String-literal interning?
Clojure does not appear to intern string literals:

(def h (new java.util.IdentityHashMap))
(. h (put "a" "b"))
(println "a:" (. h (get "a")))
(. h (put :a :b))
(println "a:" (. h (get :a)))

prints:

a: nil
a: :b

Java guarantees that string literals and string-valued constants are interned:

import java.util.*;
public class Lit {
  public static void main(String[] args) {
    IdentityHashMap<String, String> hm = new IdentityHashMap<String, String>();
    hm.put("a", "b");
    System.out.println("a: " + hm.get("a"));
  }

}

prints:
a: b

For interoperability with Java, and the principle of least surprise, I
think the Clojure reader should also intern string literals that it
reads.

Thanks,
Darshan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rich Hickey  
View profile  
 More options Mar 14 2008, 8:42 am
From: Rich Hickey <richhic...@gmail.com>
Date: Fri, 14 Mar 2008 05:42:53 -0700 (PDT)
Local: Fri, Mar 14 2008 8:42 am
Subject: Re: String-literal interning?

On Mar 14, 4:34 am, "Darshan Shaligram" <scinti...@gmail.com> wrote:

> Clojure does not appear to intern string literals:

> For interoperability with Java, and the principle of least surprise, I
> think the Clojure reader should also intern string literals that it
> reads.

This was a bit of regression when I switched to different constant
handling. I've restored string literal interning for compiled
literals. Note however that this is not, and will not be, interning of
strings in the reader. The reader can be used for arbitrary data
reading, and it is inappropriate to intern every string read. Only
string literals that are evaluated/compiled are interned.

Rich


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Darshan Shaligram  
View profile  
 More options Mar 14 2008, 8:46 am
From: "Darshan Shaligram" <scinti...@gmail.com>
Date: Fri, 14 Mar 2008 18:16:15 +0530
Local: Fri, Mar 14 2008 8:46 am
Subject: Re: String-literal interning?

On Fri, Mar 14, 2008 at 6:12 PM, Rich Hickey <richhic...@gmail.com> wrote:
>  On Mar 14, 4:34 am, "Darshan Shaligram" <scinti...@gmail.com> wrote:
>  > Clojure does not appear to intern string literals:
>  I've restored string literal interning for compiled
>  literals. Note however that this is not, and will not be, interning of
>  strings in the reader. The reader can be used for arbitrary data
>  reading, and it is inappropriate to intern every string read. Only
>  string literals that are evaluated/compiled are interned.

That works great, thanks!

Cheers,
Darshan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »