summaryrefslogtreecommitdiffstats
path: root/lib/blink/function.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/blink/function.rb')
-rw-r--r--lib/blink/function.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/blink/function.rb b/lib/blink/function.rb
new file mode 100644
index 000000000..66620c514
--- /dev/null
+++ b/lib/blink/function.rb
@@ -0,0 +1,41 @@
+#!/usr/local/bin/ruby -w
+
+# $Id$
+
+require 'blink'
+require 'blink/fact'
+
+module Blink
+ class Function
+ @@functions = Hash.new(nil)
+
+ #---------------------------------------------------------------
+ def [](name)
+ return @@functions[name]
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def call(*args)
+ @code.call(*args)
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ # we want a 'proc' item instead of a block, so that we can return
+ # from it
+ def initialize(name,code)
+ @name = name
+ @code = code
+
+ @@functions[name] = self
+ end
+ #---------------------------------------------------------------
+ end
+
+ Function.new("retrieve", proc { |fact|
+ require 'blink/fact'
+
+ return Fact[fact]
+ })
+end