Robert Bradshaw wrote: > On Dec 3, 2008, at 10:42 AM, Jason Grout wrote: > >> Robert Bradshaw wrote: >>> On Dec 3, 2008, at 5:55 AM, Stan Schymanski wrote: >>> >>>> Dear all, >>>> >>>> Could anyone tell me how to controll the order in which arguments >>>> are >>>> evaluated when they are passed to python functions? It seems that >>>> the >>>> functions are evaluated first and then the variables are >>>> substituted, >>>> which leads to failures in the following example: >>> To answer the original question, Python doesn't give control over >>> this. Arguments are always evaluated before passed to the function. >>> (What one can do, as Jason demonstrated, is pass in a function to be >>> evaluated later). >> So, bringing up an issue that has come up before, there is no way >> to do >> the equivalent of the Hold or HoldAll commands in Mma? See >> http://reference.wolfram.com/mathematica/ref/Hold.html?q=Hold&lang=en >> for example. > > Not without some preparsing magic, and even then it might be tricky > as there is not a simple one-to-one correspondence between the python > parse tree and the mathematical expression. >
Huh, maybe that's why it's so natural in Mathematica; their entire language is literally a parse tree for the mathematical expression. Okay, here's some brainstorming that may not even make sense, or may be completely obvious... You know a lot more about the python parsing trees than I do, but maybe we could only pay attention to the subexpression tree formed by Sage symbolic components? For example, surely the ginac parse tree is fairly close to the mathematical expression. Maybe the preparser could set a flag that tells any new symbolic composition whether it should try to simplify itself or whether it should just hold an inert copy of its arguments. Or maybe even better, we could attack the problem at the coercion level (since that is the level that things are combined, like addition, etc.) If a global flag is set, then something in the coercion system somehow uses inert form of operators, that basically just construct an expression tree, but doesn't evaluate the tree. I guess I'm saying that one way to do things would be to have Sage construct an expression tree before doing anything, then evaluate the expression tree if it needs to, or it can just return the tree. Wow, it seems like a lot of work; I guess it's basically replacing the python parser. I hope at least some of that makes sense. Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---