MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: something nice I found today, return multiple values from a function


Hi,

> Opps, I was in middle of editing and pasted earlier version, here is the 
> final version:
> 
> ------------------
> getPointCoordinates[x_, y_] := Module[{}, {x -> 10, y -> 7}]
> 
> p = getPointCoordinates[x, y];
> x = x /. p;
> y = y /. p;
> 
> Print["x=", x]
> Print["y=", y]
> 
> x=10
> y=7
> 

1) I think it has been mentioned in another post today: Module with an
empty list is just an elaborate noop: You better just say:

 getPointCoordinates[x_, y_] := {x -> 10, y -> 7}

2) you also might like this:


makepoint[p_Symbol,xx_,yy_]:=(p[x]=xx;p[y]=yy; p);

makepoint[p,10,7]

p@x
p@y

hth,

albert


  • Prev by Date: Re: Tutorial for running remote kernels?
  • Next by Date: Re: Boolean factorization
  • Previous by thread: something nice I found today, return multiple values from a function
  • Next by thread: Re: something nice I found today, return multiple values from a function