File: position

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (22 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
S9 LIB  (position object list)        ==>  integer | #f
        (posv object list)            ==>  integer | #f
        (posq object list)            ==>  integer | #f
        (posp procedure object list)  ==>  integer | #f

Find the position of an object in a list. When LIST contains OBJECT,
return the position of OBJECT (where the first object is as position
zero) and otherwise return #F.

POSP uses PROCEDURE as a predicate to compare OBJECT to each member
of list.

(Position a b)  equals  (posp equal? a b)
(Posv a b)      equals  (posp eqv? a b)
(Posq a b)      equals  (posp eq? a b)

(position '(bar) '((foo) (bar) (baz)))  ==>  1
(posv 4 '(0 1 2 3 4 5 6))               ==>  4
(posq 'foo '(foo bar baz))              ==>  0
(posp (lambda (x y) (= x (car y)))
      2
      '((0 . a) (1 . b) (2 . c)))       ==>  2