;; ;; Pretext ;; (define-module (pretext)) ; #:replace (list-head)) ;; ;; Runtime Environment Options ;; (debug-set! stack (* 2 (expt 10 7))) (debug-set! depth 200) (debug-set! maxdepth (expt 10 6)) (define (natural-number? n) (and (exact? n) (integer? n) ; 'integer?' does not check for exactness ... (> n 0))) (define-public (repeat n closure) "Execute closure n times." (if (not (or (natural-number? n) (= n 0))) (error "repeat: the parameter n must be an exact natural number or zero.") (let loop ((i 0)) (if (< i n) (begin (closure) (loop (1+ i)))) ))) (define-public from-module @) (define-public (my-debug . args) (for-each (lambda (arg) (display arg)) args) (newline)) ;(define-public debug my-debug) (define-public (my-list-head list n) (if (or (null? list) (<= n 0)) '() (cons (car list) (my-list-head (cdr list) (- n 1))))) (define (my-take list n) (if (< n 0) (error "take: the parameter n has to be an exact natural number or zero")) (cond ((and (not (null? list)) (= n 0)) '()) ((and (null? list) (not (= n 0))) (error "take: argument out of range: n was greater than the length of the list.")) ((and (not (null? list)) (> n 0)) (cons (car list) (take (cdr list) (- n 1)) )) (else (error "take: Oh dear, we failed!"))) )