source: git/modules/openmathserver/binding.py @ b1b9c0d

spielwiese
Last change on this file since b1b9c0d was b1b9c0d, checked in by Michael Brickenstein <bricken@…>, 18 years ago
*bricken: refactoring git-svn-id: file:///usr/local/Singular/svn/trunk@8373 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.7 KB
Line 
1from objects import OMObjectBase, OMSymbol
2from cd import *
3from omexceptions import *
4from itertools import izip
5from copy import copy
6cdFns1=OMCD("fns1")
7lambdasym=OMSymbol("lambda",cdFns1)
8
9def islambda(sym):
10    return lambdasym==sym
11   
12class OMBinding(OMObjectBase):
13    """hopefully fixed possible problems: reevaluation writes new scope, if it isn't
14       meant so, references do not work correctly because of scopes
15       solve this by first evaluation to bounded OMBinding"""
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        assert islambda(self.binder)
24        if not self.bounded:
25            mycopy=copy(self)
26            mycopy.scope=context.scopeFromCurrentScope()
27            mycopy.bounded=True
28            return mycopy
29        else:
30            return self
31    def bind(self, args):
32        #print args, self.variables
33        assert len(args)==len(self.variables)
34        varBindings=dict(izip([i.name for i in self.variables],args))
35        self.scope.push(varBindings)
36    def unbind(self):
37        self.scope.pop()
38
39    def calcErg(self,context):
40        return context.evaluateInScope(self.block,self.scope)
41    def __call__(self, context,*args):
42        self.bind(args)
43        erg=self.calcErg(context)
44        self.unbind()
45        #print "__call__ erg is", erg
46        return erg   
47       
48    XMLtag="OMBIND"
49    def getChildren(self):
50        return [self.binder]+self.variables+[self.block]
51    def setChildren(self):
52        raise UnsupportedOperationError
53       
Note: See TracBrowser for help on using the repository browser.