hacked this over lunch
This commit is contained in:
parent
4f5bc16508
commit
a1af08819d
@ -18,9 +18,10 @@ def _fn(obj):
|
||||
for i in range(0, len(sig)):
|
||||
name = sig[i]
|
||||
value = args[i]
|
||||
obj.local_namespace[name] = value
|
||||
meth.local_namespace[name] = value
|
||||
|
||||
return meth(*args, **kwargs)
|
||||
ret = meth(*args, **kwargs)
|
||||
return ret
|
||||
return _
|
||||
|
||||
|
||||
|
@ -33,7 +33,9 @@ class HYExpression(list, HYObject):
|
||||
|
||||
things = []
|
||||
for child in self.get_children():
|
||||
things.append(child())
|
||||
c = child.copy()
|
||||
things.append(c())
|
||||
print c, things
|
||||
|
||||
ret = self.lookup(fn)(*things, **kwargs)
|
||||
return ret
|
||||
|
@ -7,7 +7,7 @@ class HYObject(object):
|
||||
self.local_namespace = nns
|
||||
|
||||
for c in self.get_children():
|
||||
c.set_namespace(ns, ls=nns)
|
||||
c.set_namespace(ns, nns)
|
||||
|
||||
def get_children(self):
|
||||
return []
|
||||
@ -19,11 +19,12 @@ class HYObject(object):
|
||||
callee = None
|
||||
if fn in self.local_namespace:
|
||||
callee = self.local_namespace[fn]
|
||||
print "%s = %s (ls %s)" % (fn, callee, id(self.local_namespace))
|
||||
|
||||
if callee is None and fn in self.namespace:
|
||||
elif callee is None and fn in self.namespace:
|
||||
callee = self.namespace[fn]
|
||||
|
||||
if callee is None and "." in fn:
|
||||
elif callee is None and "." in fn:
|
||||
lon, short = fn.rsplit(".", 1)
|
||||
holder = self.lookup(lon)
|
||||
callee = getattr(holder, short)
|
||||
@ -37,3 +38,8 @@ class HYObject(object):
|
||||
for node in self.get_children():
|
||||
node.eval(*args, **kwargs)
|
||||
return self
|
||||
|
||||
def copy(self):
|
||||
new = type(self)(self)
|
||||
new.set_namespace(self.namespace, self.local_namespace)
|
||||
return new
|
||||
|
@ -1,12 +1,12 @@
|
||||
from hy.lang.hyobj import HYObject
|
||||
|
||||
|
||||
class HYNumber(int, HYObject):
|
||||
def __init__(self, number):
|
||||
class HYNumber(HYObject, int):
|
||||
def __new__(cls, number, *args, **kwargs):
|
||||
if isinstance(number, HYObject):
|
||||
number = number.eval()
|
||||
number = int(number)
|
||||
self = number
|
||||
return super(HYNumber, cls).__new__(cls, number)
|
||||
|
||||
def eval(self, *args, **kwargs):
|
||||
return int(self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user