MathGroup Archive 1998

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

Search the Archive

Re: Select x s.t. y>10

  • To: mathgroup at
  • Subject: [mg13989] Re: [mg13957] Select x s.t. y>10
  • From: Xah Lee <xah at>
  • Date: Sat, 12 Sep 1998 16:59:13 -0400
  • Sender: owner-wri-mathgroup at

At 7:06 PM -0000 1998.09.11, Jason Gill wrote:
> what I
>am trying to do is take a list of lists of length 2 ie a list of x,y
>coordinates, and Select x values based on some criterion for y.  For
>example I want to select the first x value for which the corresponding
>y is greater than 5.

Use Select or Cases.

In general, there are two ways to extract elements from the list. One is
 based on their position, the other on properties of elements. The
former is
 done with Take or Part, which is useful when you know the positions of
 elements you want. For the latter, there's Select and Cases. In Select,
 selection is based on a user defined True/False function (a predicate).
 Cases is more general. It uses pattern matching as criterion, and user
 also specify the level to extract at, and applying a transformation on
 elements of matched result.

Note that a pattern matching and predicate are interchangable as
 Suppose predicateQ is your predicate function, and suppose patternQ is

To turn a predicate into a pattern, use


To turn a pattern into a predicate, use



In your example, perhaps one of the following is useful:
 (Last at #>5&) or {x_, _?(#>5&)}->x.

 Xah, xah at
 Perl: all unix's stupidity in one.

  • Prev by Date: Re: Piecewise function integrated thrice
  • Next by Date: Re: Q: efficient list operation wanted
  • Previous by thread: Re: Select x s.t. y>10
  • Next by thread: Re: Select x s.t. y>10