Sha256: 4653a16ea6c96cce2c2c91779cabcc3ae54d4bdacadb96226d246eabc6ae6d84

Contents?: true

Size: 1.11 KB

Versions: 396

Compression:

Stored size: 1.11 KB

Contents

(define-module (list-ops)
  #:export (my-length ; Avoid overriding core bindings
            my-reverse
            my-map
            my-filter
            my-fold
            my-append
            my-concatenate
            ))

(define (my-length l)
  (define (go l acc)
    (if (null? l)
        acc
        (go (cdr l) (+ 1 acc))))
  (go l 0))

(define (my-reverse l)
  (define (go l acc)
    (if (null? l)
        acc
        (go (cdr l) (cons (car l) acc))))
  (go l '()))

(define (my-map f l)
  (define (go l acc)
    (if (null? l)
        (my-reverse acc)
        (go (cdr l) (cons (f (car l)) acc))))
  (go l '()))

(define (my-filter f l)
  (define (go l acc)
    (if (null? l)
        (my-reverse acc)
        (if (f (car l))
            (go (cdr l) (cons (car l) acc))
            (go (cdr l) acc))))
  (go l '()))

(define (my-fold f acc l)
  (if (null? l)
      acc
      (my-fold f (f (car l) acc) (cdr l))))

(define (my-append a b)
  (define (go l acc)
    (if (null? l)
        acc
        (go (cdr l) (cons (car l) acc))))
  (go (my-reverse a) b))

(define (my-concatenate ll)
  (my-fold my-append '() (my-reverse ll)))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.179 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.178 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.177 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.176 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.175 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.174 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.173 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.172 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.171 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.170 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.169 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.167 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.166 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.165 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.164 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.163 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.162 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.161 tracks/scheme/exercises/list-ops/example.scm
trackler-2.2.1.160 tracks/scheme/exercises/list-ops/example.scm