1414
1515import java .io .ObjectStreamException ;
1616import java .io .Serializable ;
17+ import java .io .PrintWriter ;
1718import java .util .concurrent .ConcurrentHashMap ;
1819import java .util .concurrent .atomic .AtomicReference ;
1920
@@ -66,7 +67,23 @@ public Var intern(Symbol sym){
6667 if (o instanceof Var && ((Var ) o ).ns == this )
6768 return (Var ) o ;
6869
69- throw new IllegalStateException (sym + " already refers to: " + o + " in namespace: " + name );
70+ // throw new IllegalStateException(sym + " already refers to: " + o + " in namespace: " + name);
71+
72+ if (v == null )
73+ v = new Var (this , sym );
74+
75+ warnOnReplace (sym , o , v );
76+
77+
78+ while (!mappings .compareAndSet (map , map .assoc (sym , v )))
79+ map = getMappings ();
80+
81+ return v ;
82+ }
83+
84+ private void warnOnReplace (Symbol sym , Object o , Object v ){
85+ ((PrintWriter ) RT .ERR .deref ()).println ("WARNING: " + sym + " already refers to: " + o + " in namespace: " + name
86+ + ", being replaced by: " + v );
7087}
7188
7289Object reference (Symbol sym , Object val ){
@@ -85,7 +102,14 @@ Object reference(Symbol sym, Object val){
85102 if (o == val )
86103 return o ;
87104
88- throw new IllegalStateException (sym + " already refers to: " + o + " in namespace: " + name );
105+ // throw new IllegalStateException(sym + " already refers to: " + o + " in namespace: " + name);
106+ warnOnReplace (sym , o , val );
107+
108+ while (!mappings .compareAndSet (map , map .assoc (sym , val )))
109+ map = getMappings ();
110+
111+ return val ;
112+
89113}
90114
91115public static boolean areDifferentInstancesOfSameClassName (Class cls1 , Class cls2 ) {
0 commit comments