Search the web
Sign In
New User? Sign Up
python-list · Python List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: What's better about Ruby than Python?   Message List  
Reply | Forward Message #106142 of 122067 |
Re: What's better about Ruby than Python?

Kenny Tilton:
> This macro:
>
> (defmacro c? (&body code)
> `(let ((cache :unbound))
> (lambda (self)
> (declare (ignorable self))
> (if (eq cache :unbound)
> (setf cache (progn ,@code))
> cache))))

I have about no idea of what that means. Could you explain
without using syntax? My guess is that it caches function calls,
based only on the variable names. Why is a macro needed
for that?

>>> import time
>>> def CachedCall(f):
... cache = {}
... def cached_call(self, *args):
... if args in cache:
... return cache[args]
... x = f(self, *args)
... cache[args] = x
... return x
... return cached_call
...
>>> class LongWait:
... def compute(self, i):
... time.sleep(i)
... return i*2
... compute = CachedCall(compute)
...
>>> t1=time.time();LongWait().compute(3);print time.time()-t1
6
3.01400005817
>>> t1=time.time();LongWait().compute(3);print time.time()-t1
6
0.00999999046326
>>>

(Need to use the function instead of a class with __call__
so that the method gets bound correctly. And I believe
this won't work if the class is derived from object. Nope!
I'm wrong. It does work.)

Andrew
dalke@...


--
http://mail.python.org/mailman/listinfo/python-list



Thu Aug 21, 2003 1:18 pm

adalke@...
Send Email Send Email

Forward
Message #106142 of 122067 |
Expand Messages Author Sort by Date

Andrew Dalke wrote: ... Just as prevalent is the wish to please EVERYone -- that's how one gets, say, PL/I, or perl... by NOT deliberately refusing to "get...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
6:24 am

... I have about no idea of what that means. Could you explain without using syntax? My guess is that it caches function calls, based only on the variable...
Andrew Dalke
adalke@...
Send Email
Aug 21, 2003
6:27 am

Andrew Dalke wrote: ... You could use a class if its instances where descriptors, i.e. supported __get__ appropriately -- that's basically what functions do...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
6:36 am

... Good question! I don't have any preset answers yet. We definitely do want to impose those restrictions that have "multiple" benefits, i.e. that both let...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
7:13 am

... I've created a new language, called Speech. It's based on the core primitives found in the International Phonetic Alphabet. I've made some demos using...
Andrew Dalke
adalke@...
Send Email
Aug 21, 2003
7:16 am

... I'm slowing easing my way into this new stuff. I read it through once, but it didn't all sink in. Could you post an example of how to use it for my cache...
Andrew Dalke
adalke@...
Send Email
Aug 21, 2003
7:24 am

... and != vs. <> Can we have a deprecation warning for that? I've never seen it in any code I've reviewed. Andrew dalke@... -- ...
Andrew Dalke
adalke@...
Send Email
Aug 21, 2003
7:28 am

Alex Martelli <aleax@...> wrote: ... What sort of syntax tweak? -- http://mail.python.org/mailman/listinfo/python-list...
Joshua Marshall
joshway_without_spam@...
Send Email
Aug 21, 2003
8:07 am

... A dangerous idiom -- you should definitely use try/finally here, otherwise your sys.stdout will stay wrongly bound if there is an exception soon after it....
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
8:12 am

... I'm very much made out of the same cloth, though age has slowly and gradually moved me a little bit towards mainstream. When I was 9 -- and every relative...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
8:23 am

... Some sort of macro, I guess <ducking for cover>. BTW, what about using macros not to create new variants but to express idiomatic transforms between...
Borcis
borcis@...
Send Email
Aug 21, 2003
8:27 am

Bengt Richter wrote: ... Properties AND many other descriptors, sure. The whole descriptors scene is cool, and properties one of the best uses for them so...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
8:37 am

... I believe you unwittingly locate an issue. Machine translation of human languages has been an unescapable project for computer scientists, a challenge that...
Borcis
borcis@...
Send Email
Aug 21, 2003
8:46 am

... Several possibilities have been discussed on python-dev in the past. E.g., <somenewkeyword> <someobject>: <block> translating into: <someobject>.begin() ...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
8:58 am

... ... cache = {} ... def cached_call(self, *args): ... if args in cache: ... return cache[args] ... x = f(self, *args) ......
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
9:50 am

... The first thing I would do with macros in Python is build an inline-facility which allows certain functions being expanded whenever they are called. This...
Matthias
spam@...
Send Email
Aug 21, 2003
9:50 am

... That's the part where I still lack understanding. class Spam: def f(self): pass f = CachedCall(f) obj = Spam() obj.f() Under old-style Python obj.f is the...
Andrew Dalke
adalke@...
Send Email
Aug 21, 2003
10:01 am

In article <ql_0b.1664$Ej6.614@...>, ... We will, probably 2.4 or 2.5. (Whenever 3.0 starts getting off the ground.) -- Aahz...
Aahz
aahz@...
Send Email
Aug 21, 2003
10:28 am

... Hmm... I still use <> exclusively for my code, and I wouldn't really like it getting deprecated. At least for me, != is more difficult to see when browsing...
Heiko Wundram
heikowu@...
Send Email
Aug 22, 2003
7:46 am

... That's an oldstyle class -- use a newstyle one for smoothest and most reliable behavior of descriptors ... This equivalence holds today as well -- the...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
11:01 am

"Andrew Dalke" <adalke@...> wrote: [defines cognitive macro called Speech] ... [snip lots of examples using it, trying to make macros look bad?] ......
Anton Vredegoor
anton@...
Send Email
Aug 21, 2003
1:15 pm

... Wow :) -- http://mail.python.org/mailman/listinfo/python-list...
Borcis
borcis@...
Send Email
Aug 21, 2003
1:47 pm

... The alternative is to understand (and subsequently recognize) the chunks of source code implementing a given patten for which no abstraction was provided...
Jacek Generowicz
jacek.generowicz@...
Send Email
Aug 21, 2003
1:53 pm

... This criticism can't help looking frivolous, imho. You appear to be confusing "language" with "speech". But I do believe there *must* exist a sane niche...
Borcis
borcis@...
Send Email
Aug 21, 2003
1:58 pm

... C? does something similar to what you think, but at with an order of magnitude more power. Estimated. :) Here is how C? can be used: (make-instance 'box ...
Kenny Tilton
ktilton@...
Send Email
Aug 21, 2003
2:09 pm

... You are absolutely right. "Umormor uya kulala" is less readable than "My maternal grandmother is going for the purpose of sleeping", to someone who is...
Jacek Generowicz
jacek.generowicz@...
Send Email
Aug 21, 2003
2:20 pm

Really cute intuition pump you've got there, Alex! :-) Obviously, no programmer of Python, Lisp, Java, etc., would ever want to deal with code in their...
Olivier Drolet
trimtab@...
Send Email
Aug 21, 2003
2:39 pm

... Hunh? This one doesn't work, and this is the one you have to answer. Forget argument by analogy: How is a macro different than an API or class, which hide...
Kenny Tilton
ktilton@...
Send Email
Aug 21, 2003
3:02 pm

... Only in so far as the original thesis is frivolous. ... I'm not sure what you mean by this. Are you saying that macros are "language" because you've heard...
Jacek Generowicz
jacek.generowicz@...
Send Email
Aug 21, 2003
3:47 pm

Jacek Generowicz wrote: ... Not at all. "Defining a function for a sinmgle use" is often a perfectly valid way to make a program MUCH CLEARER. Example: def...
Alex Martelli
aleax@...
Send Email
Aug 21, 2003
4:13 pm
 First  |  |  Last 
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help