rlm@10: /** rlm@10: * Copyright (c) Rich Hickey. All rights reserved. rlm@10: * The use and distribution terms for this software are covered by the rlm@10: * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) rlm@10: * which can be found in the file epl-v10.html at the root of this distribution. rlm@10: * By using this software in any fashion, you are agreeing to be bound by rlm@10: * the terms of this license. rlm@10: * You must not remove this notice, or any other, from this software. rlm@10: **/ rlm@10: rlm@10: /* rich Jun 28, 2007 */ rlm@10: rlm@10: package clojure.lang; rlm@10: rlm@10: public class Delay implements IDeref{ rlm@10: Object val; rlm@10: IFn fn; rlm@10: rlm@10: public Delay(IFn fn){ rlm@10: this.fn = fn; rlm@10: this.val = null; rlm@10: } rlm@10: rlm@10: static public Object force(Object x) throws Exception{ rlm@10: return (x instanceof Delay) ? rlm@10: ((Delay) x).deref() rlm@10: : x; rlm@10: } rlm@10: rlm@10: synchronized public Object deref() throws Exception{ rlm@10: if(fn != null) rlm@10: { rlm@10: val = fn.invoke(); rlm@10: fn = null; rlm@10: } rlm@10: return val; rlm@10: } rlm@10: }