;;; -*- Mode:LISP; Package:USER; Base:10 -*- (define-local-syntax (maplist list-var start-form exit-form . body) `(LET ,(first start-form) ,(append (rest start-form) (list (list (second list-var) (second list-var)))) (LET ((,(first start-form) (LAMBDA ,(mapcar first (rest start-form)) (,(first start-form) ,@(mapcar first (rest start-form)) (REST ,(second list-var)))))) (IF (NULL? ,(second list-var)) ,exit-form (LET ((,(first list-var) (FIRST ,(second list-var)))) ,@body))))) (define (split-list pred list) (maplist (element list) (loop (half-one '()) (half-two '())) (values half-one half-two) (if (pred element) (loop (cons element half-one) half-two) (loop half-one (cons element half-two))))) (define (split-list pred list) (let loop ((half-one '()) (half-two '()) (list list)) (if (null? list) (values half-one half-two) (let ((element (first list))) (if (pred element) (loop (cons element half-one) half-two (rest list)) (loop half-two (cons element half-one) (rest list)))))))