On Thu, 19 Jun 2003, Larry Price wrote:

> Neil popped this one on the clinic,
> 
> can you write a function in java that does the equivalent of this 
> python script
> 
> -------snip--------
> #!/usr/bin/python
> 
> def swap(a,b):
>      return b,a
> 
> a = 'foo'
> b = 'bar'
> print a,b
> a,b = swap(a,b)
> print a,b
> ------snap---------
> 
> turns out to be surprisingly difficult ;-)
> 

Cool :-)

The convenience python offers here doesn't really come from the swap
function, but from the transparent 'tupling' in-and-out -- at both sides
of the assignment operator, and at the return............. Horst
 (No, I won't show the vector in-and-out version in Java, neither in C++ ,
for that matter :-)

#!/usr/bin/python
def swap(a,b): return b,a
a, b = 'foo', 'bar'
print a,b
a,b = swap(a,b)
print a,b
print "return type of swap():", type(swap(a, b))






_______________________________________________
EuG-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to