<commit_before>; These are functions described in R5RS as ``library procedures'' meaning they
; can be implemented in Scheme with primitive procedures, so that's what I've
; done. There is of course no requirement that they must be.

; Works similar to assert. I'm thinking about throwing out type-checking for
; arithmatic procedures and letting the passing of non-numbers to them be
; unspecified. It could lead to some interesting hacking but I haven't thought
; too much about the security implications.
(define (check condition who msg . args)
  (if (not condition)
    (apply error (cons who (cons msg args)))))

(define (zero? z)
  (check (number? z) 'zero? "not a number" z)
  (= z 0))

(define (positive? x)
  (check (number? x) 'positive? "not a number" x)
  (>= x 0))

(define (negative? x)
  (check (number? x) 'negative? "not a number" x)
  (< x 0))

(define (odd? n)
  (check (integer? n) 'odd? "not a number" n)
  (= (modulo n 2) 1))

(define (even? n)
  (check (integer? n) 'even? "not a number" n)
  (= (modulo n 2) 0))

(define (max x . args)
  (if (null? args)
    x
    (let ((y (car args)))
      (if (and (number? x) (number? y))
        (apply max (cons (if (> x y) x y) (cdr args)))
        (error 'max "arguments must be real numbers" x args)))))

(define (min x . args)
  (if (null? args)
    x
    (let ((y (car args)))
      (if (and (number? x) (number? y))
        (apply min (cons (if (< x y) x y) (cdr args)))
        (error 'min "arguments must be real numbers" x args)))))


(define (abs x)
  (check (number? x) 'abs "not a number" x)
  (if (< x 0)
    (- x)
    x))

; Returns the greatest common divisor or of its arguments.
; The result is always non-negative.
(define (gcd . args)
  (define (euclid a b) ; Euclid's algoritm
    (check (and (integer? a) (integer? b)) 'gcd "args must be itegers" args)
    (if (= b 0)
      a
      (euclid b (remainder a b))))
  (cond ((null? args) 0)
        ((null? (cdr args)) (abs (car args)))
        (else
          (apply gcd (cons (euclid (car args) (cadr args))
                           (cddr args))))))

(define (lcm . args)
  (define (algo a b)
    (/ (abs (* a b)) (gcd a b)))
  (cond ((null? args) 1)
        ((null? (cdr args)) (abs (car args)))
        (else
          (apply lcm (cons (algo (car args) (cadr args))
                           (cddr args))))))
(define (not obj)
  (if obj #f #t))

(define (boolean? obj)
  (or (eq? obj #f) (eq? obj #t)))

(define (null? obj)
  (eq? obj '()))

(define (list? obj)
  (if (null? obj)<commit_msg>Formatting.<commit_after>; These are functions described in R5RS as ``library procedures'' meaning they
; can be implemented in Scheme with primitive procedures, so that's what I've
; done. There is of course no requirement that they must be.

; Works similar to assert. I'm thinking about throwing out type-checking for
; arithmatic procedures and letting the passing of non-numbers to them be
; unspecified. It could lead to some interesting hacking but I haven't thought
; too much about the security implications.
(define (check condition who msg . args)
  (if (not condition)
    (apply error (cons who (cons msg args)))))

(define (zero? z)
  (check (number? z) 'zero? "not a number" z)
  (= z 0))

(define (positive? x)
  (check (number? x) 'positive? "not a number" x)
  (>= x 0))

(define (negative? x)
  (check (number? x) 'negative? "not a number" x)
  (< x 0))

(define (odd? n)
  (check (integer? n) 'odd? "not a number" n)
  (= (modulo n 2) 1))

(define (even? n)
  (check (integer? n) 'even? "not a number" n)
  (= (modulo n 2) 0))

(define (max x . args)
  (if (null? args)
    x
    (let ((y (car args)))
      (if (and (number? x) (number? y))
        (apply max (cons (if (> x y) x y) (cdr args)))
        (error 'max "arguments must be real numbers" x args)))))

(define (min x . args)
  (if (null? args)
    x
    (let ((y (car args)))
      (if (and (number? x) (number? y))
        (apply min (cons (if (< x y) x y) (cdr args)))
        (error 'min "arguments must be real numbers" x args)))))


(define (abs x)
  (check (number? x) 'abs "not a number" x)
  (if (< x 0)
    (- x)
    x))

; Returns the greatest common divisor of its arguments.
; The result is always non-negative.
(define (gcd . args)
  (define (euclid a b) ; Euclid's algoritm
    (check (and (integer? a) (integer? b)) 'gcd "args must be itegers" args)
    (if (= b 0)
      a
      (euclid b (remainder a b))))
  (cond ((null? args) 0)
        ((null? (cdr args)) (abs (car args)))
        (else
          (apply gcd (cons (euclid (car args) (cadr args))
                           (cddr args))))))

(define (lcm . args)
  (define (algo a b)
    (/ (abs (* a b)) (gcd a b)))
  (cond ((null? args) 1)
        ((null? (cdr args)) (abs (car args)))
        (else
          (apply lcm (cons (algo (car args) (cadr args))
                           (cddr args))))))

(define (not obj)
  (if obj #f #t))

(define (boolean? obj)
  (or (eq? obj #f) (eq? obj #t)))

(define (null? obj)
  (eq? obj '()))

(define (list? obj)
  (if (null? obj)
{'fraction_non_alphanumeric': 0.15921677215189872, 'fraction_numerical': 0.004746835443037975, 'mean_word_length': 2.6966374269005846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6279747', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1780, 'n_words': 752}