/usr/lib/s9fes/position.scm is in scheme9 2010.11.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2010
; See the LICENSE file of the S9fES package for terms of use
;
; (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)
;
; Example: (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
(define (posp p x a)
(let loop ((a a)
(i 0))
(cond ((null? a)
#f)
((p x (car a))
i)
(else
(loop (cdr a) (+ i 1))))))
(define (position x a) (posp equal? x a))
(define (posv x a) (posp eqv? x a))
(define (posq x a) (posp eq? x a))
|