mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +02:00
Added various functions to stdlib
This commit is contained in:
parent
fac76980fe
commit
b410e54836
1 changed files with 17 additions and 1 deletions
18
trans.scm
18
trans.scm
|
@ -64,12 +64,16 @@
|
||||||
(if (null? lst)
|
(if (null? lst)
|
||||||
end
|
end
|
||||||
(func (car lst) (foldr func end (cdr lst)))))
|
(func (car lst) (foldr func end (cdr lst)))))
|
||||||
|
(define (not x) (if x #f #t))
|
||||||
(define (list? obj)
|
(define (list? obj)
|
||||||
(cond
|
(cond
|
||||||
((null? obj) #t)
|
((null? obj) #t)
|
||||||
((pair? obj)
|
((pair? obj)
|
||||||
(list? (cdr obj)))
|
(list? (cdr obj)))
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
(define (zero? n) (= n 0))
|
||||||
|
(define (positive? n) (> n 0))
|
||||||
|
(define (negative? n) (< n 0))
|
||||||
; append accepts a variable number of arguments, per R5RS. So a wrapper
|
; append accepts a variable number of arguments, per R5RS. So a wrapper
|
||||||
; has been provided for the standard 2-argument version of (append).
|
; has been provided for the standard 2-argument version of (append).
|
||||||
;
|
;
|
||||||
|
@ -85,9 +89,21 @@
|
||||||
(car lst)
|
(car lst)
|
||||||
(foldl (lambda (a b) (append-2 b a)) (car lst) (cdr lst)))))
|
(foldl (lambda (a b) (append-2 b a)) (car lst) (cdr lst)))))
|
||||||
(define (list . objs) objs)
|
(define (list . objs) objs)
|
||||||
|
; TODO: (define (make-list k . fill)
|
||||||
|
; )
|
||||||
(define (map func lst)
|
(define (map func lst)
|
||||||
(foldr (lambda (x y) (cons (func x) y)) '() lst))
|
(foldr (lambda (x y) (cons (func x) y)) '() lst))
|
||||||
(define (not x) (if x #f #t))
|
(define (for-each f lst)
|
||||||
|
(cond
|
||||||
|
((null? lst) #t)
|
||||||
|
(else
|
||||||
|
(f (car lst))
|
||||||
|
(for-each f (cdr lst)))))
|
||||||
|
(define (list-tail lst k)
|
||||||
|
(if (zero? k)
|
||||||
|
lst
|
||||||
|
(list-tail (cdr lst) (- k 1))))
|
||||||
|
(define (list-ref lst k) (car (list-tail lst k)))
|
||||||
(define (reverse lst) (foldl cons '() lst))
|
(define (reverse lst) (foldl cons '() lst))
|
||||||
(define (error msg . args)
|
(define (error msg . args)
|
||||||
(raise (cons msg args)))
|
(raise (cons msg args)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue