Frickn' awesome.

This commit is contained in:
Paul Tagliamonte 2012-12-16 17:46:33 -05:00
parent c8937f8f07
commit c55f501d2e
6 changed files with 36 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import imp
from hy.lex.tokenize import tokenize
import imp
def _add_native_methods(mod):
@ -35,12 +35,13 @@ def _add_native_methods(mod):
ret /= x
return ret
natives = {
"print": _print,
"+": _plus,
"-": _subtract,
"*": _mult,
"/": _divide
"/": _divide,
}
for native in natives:

View File

@ -23,7 +23,19 @@ def _fn(obj):
return _
def _import(obj):
ns = obj.namespace
fd = obj.get_invocation()
args = fd['args']
mods = args[0]
for module in mods:
mod = __import__(module)
obj.namespace[module] = mod
builtins = {
"def": _define,
"fn": _fn,
"import": _import
}

View File

@ -35,4 +35,4 @@ class HYExpression(list, HYObject):
for child in self.get_children():
things.append(child())
return self.namespace[fn](*things)
return self.lookup(fn)(*things)

View File

@ -12,3 +12,19 @@ class HYObject(object):
def __call__(self, *args, **kwargs):
return self.eval(*args, **kwargs)
def lookup(self, fn):
callee = None
if fn in self.namespace:
callee = self.namespace[fn]
if "." in fn:
lon, short = fn.rsplit(".", 1)
holder = self.lookup(lon)
callee = getattr(holder, short)
if callee:
return callee
raise Exception

View File

@ -8,4 +8,4 @@ class HYSymbol(unicode, HYObject):
def eval(self, *args, **kwargs):
if self.isdigit():
return float(self)
return self.namespace[self]
return self.lookup(self)

View File

@ -1,6 +1,9 @@
; vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 filetype=lisp
(import ["sys"])
(def square (fn [x]
(* x x)))
(print (square 2))
(print sys.argv)