Re: Sort within self-defined procedure
- To: mathgroup at smc.vnet.net
- Subject: [mg108621] Re: Sort within self-defined procedure
- From: "Hans Michel" <hmichel at cox.net>
- Date: Thu, 25 Mar 2010 04:27:20 -0500 (EST)
- References: <hocm9o$shi$1@smc.vnet.net>
dornakul: Try changing the "=" with ":=" please note the colon. You are using the Mathematica symbol/function Set over Mathematica symbol/function SetDelayed. For example kz[x_] := Module[{l}, l = {1, 5, x, 2}; Sort[l, Greater]] In[5]:= kz[20] Out[5]= {20,5,2,1} It is very cumbersome to use Mathematica without using shortcuts as most examples go against this grain. But for learning differences between functions/symbols or shortcuts I find it useful to use this form SetDelayed[kt[x_], Module[{l},l={1,5,x,2}; Sort[l,Greater]]] In[12]:= kt[30] Out[12]= {30,5,2,1} Now if you try to figure out how to do the entire process without using any shortcuts such as "x_" you'll end up frustrated but learn alot about Mathematica. Hans Hint see http://reference.wolfram.com/mathematica/tutorial/OperatorInputForms.html SetDelayed[kr[Pattern[x, Blank[ ] ] ], Module[{l}, l = {1, 5, x, 2}; Sort[l, Greater]]] "dornakul" <postitdummy at arcor.de> wrote in message news:hocm9o$shi$1 at smc.vnet.net... > Hi, > > I am desperate. Why is it not possible to sort a list within a self- > defined procedure? > > Here comes the minimal example > > In[188]:= ks[x_] = Module[{l}, > l = {1, 5, x, 2}; > Sort[l, Greater] > ] > > Out[188]= {5, x, 2, 1} > > In[190]:= ks[20] > > Out[190]= {5, 20, 2, 1} > > Dornakul > Using Mathematica 7 on a Windows machine >