source: git/modules/openmathserver/binding.py @ 68549d

spielwiese
Last change on this file since 68549d was 68549d, checked in by Michael Brickenstein <bricken@…>, 19 years ago
*bricken: initial version git-svn-id: file:///usr/local/Singular/svn/trunk@8358 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.1 KB
Line 
1from objects import OMobject, OMsymbol
2from cd import *
3from omexceptions import *
4from itertools import izip
5cdFns1=OMcd("fns1")
6lambdasym=OMsymbol("lambda",cdFns1)
7
8def islambda(sym):
9    return lambdasym==sym
10   
11class OMbinding(OMobject):
12    def __init__(self, binder,variables,block):
13        super(OMbinding,self).__init__()
14        self.block=block
15        self.binder=binder
16        self.variables=variables
17    def evaluate(self,context):
18        assert islambda(self.binder)
19        self.scope=context.scopeFromCurrentScope()
20        return self
21    def bind(self, args):
22        #print args, self.variables
23        assert len(args)==len(self.variables)
24        varBindings=dict(izip([i.name for i in self.variables],args))
25        self.scope.push(varBindings)
26    def unbind(self):
27        self.scope.pop()
28
29    def calcErg(self,context):
30        return context.evaluateInScope(self.block,self.scope)
31    def __call__(self, context,*args):
32        self.bind(args)
33        erg=self.calcErg(context)
34        self.unbind()
35        #print "__call__ erg is", erg
36        return erg   
37       
Note: See TracBrowser for help on using the repository browser.