|
|
|
![]() |
|
Strumenti |
![]() |
#101 | |
Senior Member
Iscritto dal: Jul 2002
Città: Reggio Calabria -> London
Messaggi: 12093
|
Quote:
![]() Spero che non sia davvero possibile fare una cosa del genere in python perchè altrimenti non mi spiego proprio come faccia l'interprete a scegliere quale signature della funzione utilizzare quando si lancia una funzione ![]()
__________________
![]() |
|
![]() |
![]() |
![]() |
#102 | |||
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
Quote:
![]() ![]() ![]() ![]() ![]() ![]() Quote:
Quote:
![]() |
|||
![]() |
![]() |
![]() |
#103 | ||
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
![]() Quote:
Anche se probabilmente abbiamo due idee diverse sul significato di "variabile temporanea"
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
||
![]() |
![]() |
![]() |
#104 | |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
nella definizione di foo2: Codice:
def foo2(x,y=[]): y.append(x) print y Ad esempio foo2(5) equivale a foo2(5,[]), in quanto nella definizione di funzione ho scritto y=[]. Nulla mi vieta ovviamente di specificare esplicitamente il secondo parametro, ad esempio foo2(1,['x']). La cosa da fare attenzione e' che il valore di default viene calcolato solo all'inizio e non ad ogni chiamata. Quindi quando scrivo Codice:
foo2(1) foo2(2) In ogni caso l'inteprete non deve scegliere assolutamente la signature della funzione da utilizzare: in python non esiste l'overloading delle funzioni. Se definisco due funzioni con lo stesso nome (anche se con signature differente) la prima "sparisce" e rimane valida solo la seconda. Se scrivo Codice:
def f(x): return x def f(x,y): return x+y f(1)
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
![]() |
![]() |
![]() |
#105 | |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
O l'autore decide che deve tornare la distanza (oltre che stamparlo) e allora l'ultima riga dovrebbe essere return DistQuadrata (o meglio ancora la sua radice, ma questo e' un altro discorso), oppure stabilisce che invece che una funzione e' una procedura, e il risultato viene solo stampato; in quest'ultimo caso il return proprio non ci dovrebbe essere.
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
![]() |
![]() |
![]() |
#106 | |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
Quote:
|
|
![]() |
![]() |
![]() |
#107 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
voi che dite?
|
![]() |
![]() |
![]() |
#108 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
up
|
![]() |
![]() |
![]() |
#109 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
up
|
![]() |
![]() |
![]() |
#110 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
up
|
![]() |
![]() |
![]() |
#111 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
up
|
![]() |
![]() |
![]() |
#112 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
e non ho capito nemmeno l'esempio di foo
Ultima modifica di Th3 Kn0wl3dg3 : 10-03-2007 alle 21:00. |
![]() |
![]() |
![]() |
#113 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
up
|
![]() |
![]() |
![]() |
#114 |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Non preoccuparti troppo, e' un caso abbastanza particolare che avevo usato per mostrare come in un caso (il primo) ad ogni chiamata y viene inizializzato a lla lista vuota, mentre nel secondo le modifiche alla lista vengono conservate tra una chiamata e l'altra.
Codice:
def foo(x,y): y = [] y.append(x) print y def foo2(x,y=[]): y.append(x) print y
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele Ultima modifica di marco.r : 13-03-2007 alle 20:51. |
![]() |
![]() |
![]() |
#115 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
![]() |
![]() |
![]() |
![]() |
#116 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 887
|
leggendo documenti su documenti credo che invece che python mi convenga iniziare da C o meglio ancora da java...voi che dite?
|
![]() |
![]() |
![]() |
#117 |
Senior Member
Iscritto dal: Aug 2005
Messaggi: 2755
|
Che problema c'è?
Quando uppi, quota il tuo problema, almeno è più semplice rispondere
__________________
|
![]() |
![]() |
![]() |
#118 |
Senior Member
Iscritto dal: Aug 2005
Messaggi: 2755
|
Dato che hai iniziato con python ti consiglio di continuare, è un ottimo linguaggio.
__________________
|
![]() |
![]() |
![]() |
#119 |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Allora mi sono accorto che l'ultimo codice che ho postato non e' corretto, lo riscrivo qui per chiarezza, togliendo il secondo argomento a foo:
Codice:
def foo(x): y = [] y.append(x) print y def foo2(x,y=[]): y.append(x) print y per cui se io scrivo Codice:
foo(1,1) foo(2,2) foo(3,3) Con foo2 invece, y viene inizializzato ogni volta con la stessa lista, che pero' nel frattempo cresce. Con Codice:
foo2(1) foo2(2) foo2(3) come dicevo sopra non crucciarti piu' di tanto per questo esempio, e' uno dei rari casi in cui python un po' strano.
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
![]() |
![]() |
![]() |
#120 | |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
![]()
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:01.