blob: 6e1bf33b4a1498cbe30dc24a920093e71c1b3d5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/**
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
* Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
* which can be found in the file CPL.TXT at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
/* rich Mar 29, 2006 10:39:05 AM */
using System;
using System.Collections.Specialized;
namespace org.clojure.runtime
{
public class Keyword : Indexer
{
static public HybridDictionary table = new HybridDictionary();
public String name;
override public String ToString()
{
return ":" + name;
}
public static Keyword intern(String name)
{
lock(table)
{
Keyword sym = (Keyword) table[name];
if(sym == null)
table.Add(name, sym = new Keyword(name));
return sym;
}
}
/**
* Used by Namespace.intern()
*
* @param name
*/
Keyword(String name)
{
this.name = name;
}
/**
* Indexer implements IFn for attr access
* This single arg version is the getter
* @param tld
* @param obj - must be AMap
* @return the value of the attr or nil if not found
*/
override public Object invoke(ThreadLocalData tld, Object obj) /*throws Exception*/
{
return ((AMap)obj).get(this);
}
/**
* Indexer implements IFn for attr access
* This two arg version is the setter
* @param tld
* @param obj - must be AMap
* @param val
* @return val
*/
override public Object invoke(ThreadLocalData tld, Object obj, Object val) /*throws Exception*/
{
return ((AMap)obj).put(this,val);
}
}
}
|