[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: arg-order of test-fn for #'position

In article <39g3btEoi1@uni-erlangen.de> uhbecker@cip.informatik.uni-erlangen.de (Ulrich Becker) writes:
>I need to find the position of the first item in a list of numbers
>that is smaller than a given number. I thought it might be possible 
>to use the position-function for this purpose, using it that way:
>(position given-number list-of-numbers :test #'>)
>This of course works only if given-number is the first arg and 
>the item in list-of-numbers is the second arg passed to the 
>test-function (which is true for MCL). My question is: Is this true 
>for all CL implementations, or is the ordering of arguments passed 
>to the test-function implementation-dependent?

Since your question is about "all CL implementations", wouldn't your
question be more appropriate for comp.lang.lisp than comp.lang.lisp.mcl?

The answer to your question is yes.  From p.391 of CLtL2:

    You may depend on the order in which arguments are given to <testfn>;
    this permits the use of non-commutative test functions in a predictable
    manner.  The order of the arguments to <testfn> corresponds to the
    order in which those arguments (or the sequences containing those
    arguments) were given to the sequence function in question.  If a
    sequence function gives two elements from the same sequence argument to
    <testfn>, they are given in the same order in which they appear in the

By the way, if this weren't true you could easily solve your original
problem with:

(position-if #'(lambda (x) (> x given-number)) list-of-numbers)

Barry Margolin
BBN Internet Services Corp.