binding a reference to a variable
Andrew Koenig
ark at research.att.com
Wed Apr 10 23:02:31 EDT 2002
Tim> I did that a looong time ago, but the code didn't survive my
Tim> then-employer's financial meltdown. Unless you bought their
Tim> assets at the fire sale, I'm not sure how you could know whether
Tim> your approach is completely different <wink>.
The implementation I was thinking of was actually done in Ada, and
gatewayed to Python...
Tim> It is, though. The use of unevaluated expressions in SNOBOL4 is
Tim> crucial for advanced matching, and the "how do you do that with a
Tim> bare name in Python?" problem seems unsolvable in a squeaky
Tim> clean way. Like:
Tim> ARB = NULL | LEN(1) *ARB
Yup. But why not
arb = null | (len(1) + indirect(lambda: arg))
?
>> Focusing just on the (break("@") . id) subexpression, how would
>> one implement it? That's what led me on this path.
Tim> After I left that path <wink>, I found it was much easier to
Tim> model Icon's spelling of patterns, and with generators in 2.2
Tim> that can be a breeze.
Indeed. But I want more Snobolish than Iconish patterns.
Tim> However, Icon pattern-matching has a more procedural flavor, and
Tim> SNOBOL4 pattern-matching a more declarative flavor, and each has
Tim> strengths and weaknesses following from that.
Agreed completely.
Tim> Before I left that path, it looked something like
Tim> id = S.var('id')
Tim> ... id.ass(S.break('@')) ...
Tim> were .ass() had an optional argument to choose between delayed
Tim> (.) and immediate ($) assignment, defaulting to delayed. BTW,
Tim> operator overloading was much harder to predict in Python back
Tim> then, so I often settled for ordinary method-call notation.
Tim> After operator overloading because easy to predict in Python, I
Tim> learned to hate it from being forced to endure reading code that
Tim> used it <0.7 wink>.
Maybe there's another way. If I knew, I'd say what it is :-)
Tim> An iteration before that I used string names as keys to an
Tim> explicit namespace dictionary (as others have suggesting), but
Tim> found that modeling "SNOBOL4 variable" as a class in its own
Tim> right felt at least a little better, despite needing explicit
Tim> "declarations", i.e. lines of the form
Tim> var1, var2, ... = S.var(name1, name2, ...)
Tim> Remembering to do that once was less painful than needing to slop
Tim> in quotes everywhere.
Might well be.
Tim> Have fun! It's an interesting challenge.
Indeed. And a good learning vehicle.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list