def _anonymous(self, fn): if fn in self._['functions']: return self._['functions'][fn]['call'] elif fn in self._['tex']: return self._['tex'][fn]['call'] # TODO: fix this so that it actually scopes the variables instead of not allowing them variables = [q for q in set(re_math.var_name.findall(fn)) if q not in self._['tex'] and q not in self._['variables'] and q not in self._['functions']] return lambda *args : self.compute( util.replace_list(variables, args, fn) )
def _assign(self, math): q = re_math.assignment.match(math) name, value = q.group(1), q.group(2) name = name.replace(' ', '') if '(' in name: fn = name[:name.index('(')] if not re_math.variable_name.match(fn): raise ValueError('Invalid name') params = util.get_inner(name[name.index('('):])[0] self._['functions'][fn] = { 'call': lambda *args : self.compute(util.replace_list(params.split(','), args, value), True), 'math': math } result = self._['functions'][fn]['call'] else: if not re_math.variable_name.match(name): raise ValueError('Invalid name') result = self.compute(value); self._['variables'][name] = str(result) if type(result) not in (type(np.array([])), type(np.matrix([]))) else str(result.tolist()) return result