Ed Leafe wrote:
> On Dec 6, 2006, at 3:05 PM, Carl Karsten wrote:
>
>> I am trying to figure out how to pass in an expression as an..
>> um... expression
>> object? I think the line of code in this method should simply be rec
>> [field] =
>> Expr and Expr can either be a reference to a 'constant', a
>> reference to a
>> function, or an expression in some other... namespace? (cuz scope
>> is going to
>> be an issue)
>
> I'm not going to respond point-by-point, as I'm knee-deep in the
> Menu Designer stuff. But I have a suggestion: why not just code it
> the way it should be?
Cuz I am not sure how it should be. My strategy is to try to gather
requirements and known issues before I start coding. :)
In the time it took you to write that post I'll
> bet you could have had a prototype working!
I did that too. not I like it, wondering if there is a prettier implementation,
The pythonic way is v.cumbersome. But I still think it is better.
current code is like this:
def f1(x): print eval(x)
I am suggesting:
def f2(x): print x()
and so the call would change from of course the only point of that would be to
ma
f1('2*3')
to Re: [dabo-users] interactive work
f2(lambda:3*2)
I will concede that F1 is easier to use. but I think it has limitations. But
it is easy to write an F1 that calls F2:
def f1(x): print f2( lambda:eval(x) )
Which 'might' be nice to have for working interactively, but I am skeptical
that
it is worth it. The "3*2" way is less typing, and maybe easier to read. I
have
a feeling the "3*2" way will end up with situations where someone doesn't get
what they are expecting, and then has to figure out that they really need to
use
the lambda way, and suddenly you have burned up all the time ever saved.
One function, type lambda each time, done.
OK, here is my stab at how it should be coded.
def replace(self, field, Expr, scope=None):
"""Replaces the value of the specified field
with the given expression.
All records matching the scope are affected; if
no scope is specified, all records are affected.
Scope is a boolean expression.
"""
Re wrote the doc-string. isn't it pretty?
Then the next lines sent me off to another function that I don't quite
understand.
scope = self._fldReplace(scope, "rec")
def _fldReplace(self, expr, dictName=None):
"""The list comprehensions require the field names be the keys
in a dictionary expression. Users, though, should not have to know
about this. This takes a user-defined, SQL-like expressions, and
substitutes any field name with the corresponding dict
expression.
"""
Can you give me an example of what is going on here? I think "Users" needs to
be better defined. I am guessing you mean users of a function like .replace() ?
Carl K
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users