MathGroup Archive 2002

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

Search the Archive

Re: Test of a pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34033] Re: [mg34010] Test of a pure function
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Sat, 27 Apr 2002 00:56:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Friday, April 26, 2002, at 03:27 AM, Shawn O'Connor wrote:

> Hello,
>
>     I hope someone can help me with this I know the solution should be 
> easy
> but I am still learning how pure functions work.
>
> I am trying to pick out a position in a list were a number falls i.e.
>
> Position[xBins, _?(#1<=x <= #2 &)].  I keep getting errors Like these
>
>
> Function::slotn: Slot number 2 in #1æxæ#2& cannot be filled
> from \
> (#1æxæ#2&)[List].
>
> Function::slotn: Slot number 2 in
> #1æxæ#2& cannot be filled from \
> (#1æxæ#2&)[-1].
>
> From
> In[83]:=
> Function::slotn: Slot number 2 in #1æxæ#2& cannot be filled from
> \
> (#1æxæ#2&)[-0.995].
>
> General::stop: Further output of
> Function::slotn will be suppressed during \
> this calculation.
>
>
> Can I make a comparison with the nth and nth+1 element in a pure 
> function.
> Thank you,
>
>

Position takes patterns as its second argument, not a function.  It 
returns the list of positions where the pattern matches the list 
element.  If you have a sorted list then one way of finding the position 
a value would occupy is to get the length of the list containing all the 
values less than the one you have.  You can use Select for that, which 
does take functions as an argument.  The function in this case only has 
one argument though, so there is only one slot to fill.  That's the 
reason for your errors, your function expects two values and only one is 
being supplied but in the case of Position I'm not sure what that 
argument is.  Here's an example of a function that returns the position 
at which a value would be inserted into a sorted list:

insertposition[value_,lst_List] := Select[lst, #<=value&]+1

Regards,

Ssezi



  • Prev by Date: Re: Dynamic referencing AND hyperlinking for numbered equations
  • Next by Date: Re: Getting File Directory Using Any Platform
  • Previous by thread: Re: Test of a pure function
  • Next by thread: RE: Test of a pure function