[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

ægte closures / blokke i python



Nu inden jeg blamerer mig på comp.lang.python...

Er der egentlig aldrig nogen der har overvejet rigtige closures i python på samme måde som i ruby? Altså ikke blot lambda-funktioner...

ruby:

4.times {|i| print i}
[1,3,4,7].each {|i| print i}
button.set_click_action {print "You quit!; exit}
storage.transaction {20.times {write "Atomic data!"}}

kunne vel gøres mulige i python:

4.times() i: print i
[1,3,4,7].each() i: print i
button.set_click_action(): print "You quit!; sys.exit()
storage.transaction():
  20.times():
    write("Atomic data!")


* Selfølgelig skal klasserne int og list udvides med de viste metoder
* i er en lokal variabel i blokken som indeholder den parameter, som metoderne each() og times() kalder den med.
* I Ruby kalder metoden blokken med det reserverede ord 'yield'. Det findes allerede i python og bruges i generatorer til at returnere en værdi uden at afslutte generatoren. Hvis disse to anvendelser ikke kan kombineres skulle man evt indføre et nyt reserveret ord.


- Siemen

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-02-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *