Files
beluga/lisp-interpreter/stdlib/3_math.scm
T
Arthur Barraux d8fc7d2d67
Meson Build and Deploy / build (push) Failing after 29s
adding lisp-interpreter
2025-09-24 10:58:09 +02:00

36 lines
885 B
Scheme

(define (number? x) (real? x))
(define (odd? x) (not (even? x)))
(define (inexact? x) (not (exact? x)))
(define (zero? x) (= x 0))
(define (positive? x) (>= x 0))
(define (negative? x) (< x 0))
(define (>= a b) (not (< a b)))
(define (> a b) (< b a))
(define (<= a b) (not (< b a)))
(define (max . ls)
(fold-left (lambda (m x)
(if (> x m)
x
m)) (car ls) (cdr ls)))
(define (min . ls)
(fold-left (lambda (m x)
(if (< x m)
x
m)) (car ls) (cdr ls)))
(define (_gcd-helper a b)
(if (= b 0) a (_gcd-helper b (modulo a b))))
(define (gcd . args)
(if (null? args) 0
(_gcd-helper (car args) (car (cdr args)))))
(define (lcm . args)
(if (null? args) 1
(abs (* (/ (car args) (apply gcd args))
(apply * (cdr args))))))