(define reversed_iota (lambda (n) (if (zero? n) () (cons n (reversed_iota (-1+ n))) ) ) ) (define iota (lambda (n) (reverse! (reversed_iota n)))) (define (nthmemq elem lista) (let loop ((lista lista) (i 0)) (cond ((null? lista) #f) ((eq? (car lista) elem) i) (else (loop (cdr lista) (1+ i))) ) ) ) (define attach! ; Borrowed from Franz lisp, is like destructive cons. (lambda (elem lista) (set-cdr! lista (cons (car lista) (cdr lista))) (set-car! lista elem) lista ) ) (define (count-pars a) (cond ((not (pair? a)) 0) (else (+ 1 (count-pars (car a)) (count-pars (cdr a)))) ) ) (define (nthcdr n lista) (if (or (zero? n) (null? lista)) lista (nthcdr (-1+ n) (cdr lista)) ) ) ;; For testing whether we have an identity permutation or not. (define (first_dislocated lista) (let loop ((lista lista) (i 0)) (cond ((null? lista) lista) ((not (eq? (car lista) i)) lista) (else (loop (cdr lista) (1+ i))) ) ) )