Changeset 057e4d3 in git for modules/openmathserver/binding.py
- Timestamp:
- Jun 23, 2005, 5:24:01 PM (18 years ago)
- Branches:
- (u'spielwiese', 'ec94ef7a30b928574c0c3daf41f6804dff5f6b69')
- Children:
- e25c5effa9b6fa015db14b7bde31ddca40b78786
- Parents:
- 17c7ba38fdfb7e1701605423c601fe8230072950
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/openmathserver/binding.py
r17c7ba r057e4d3 1 1 from objects import OMObjectBase, OMSymbol 2 from cd import *3 from omexceptions import *2 from cd import OMCD 3 from omexceptions import UnsupportedOperationError 4 4 from itertools import izip 5 5 from copy import copy 6 cdFns1 =OMCD("fns1")7 lambdasym =OMSymbol("lambda",cdFns1)6 cdFns1 = OMCD("fns1") 7 lambdasym = OMSymbol("lambda", cdFns1) 8 8 9 9 def islambda(sym): 10 return lambdasym ==sym10 return lambdasym == sym 11 11 12 12 class OMBinding(OMObjectBase): … … 14 14 meant so, references do not work correctly because of scopes 15 15 solve this by first evaluation to bounded OMBinding""" 16 def __init__(self, binder, variables,block):17 super(OMBinding, self).__init__()18 self.block =block19 self.binder =binder20 self.variables =variables21 self.bounded =False22 def evaluate(self, context):16 def __init__(self, binder, variables, block): 17 super(OMBinding, self).__init__() 18 self.block = block 19 self.binder = binder 20 self.variables = variables 21 self.bounded = False 22 def evaluate(self, context): 23 23 assert islambda(self.binder) 24 24 if not self.bounded: 25 mycopy =copy(self)26 mycopy.scope =context.scopeFromCurrentScope()27 mycopy.bounded =True25 mycopy = copy(self) 26 mycopy.scope = context.scopeFromCurrentScope() 27 mycopy.bounded = True 28 28 return mycopy 29 29 else: … … 31 31 def bind(self, args): 32 32 #print args, self.variables 33 assert len(args) ==len(self.variables)34 varBindings =dict(izip([i.name for i in self.variables],args))33 assert len(args) == len(self.variables) 34 varBindings = dict(izip([i.name for i in self.variables], args)) 35 35 self.scope.push(varBindings) 36 36 def unbind(self): 37 37 self.scope.pop() 38 38 39 def calcErg(self, context):40 return context.evaluateInScope(self.block, self.scope)41 def __call__(self, context, *args):39 def calcErg(self, context): 40 return context.evaluateInScope(self.block, self.scope) 41 def __call__(self, context, *args): 42 42 self.bind(args) 43 erg =self.calcErg(context)43 erg = self.calcErg(context) 44 44 self.unbind() 45 45 #print "__call__ erg is", erg 46 46 return erg 47 47 48 XMLtag ="OMBIND"48 XMLtag = "OMBIND" 49 49 def getChildren(self): 50 50 return [self.binder]+self.variables+[self.block]
Note: See TracChangeset
for help on using the changeset viewer.