Sha256: ae4f7830d17d01739bd02f4fdb25ca0ab80bd3102c5ef629ea21c30c5a1c389f

Contents?: true

Size: 1.05 KB

Versions: 396

Compression:

Stored size: 1.05 KB

Contents

#lang racket

(provide my-length
         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 (rest l) (+ 1 acc))))
  (go l 0))

(define (my-reverse l)
  (define (go l acc)
    (if (null? l)
        acc
        (go (rest l) (cons (first l) acc))))
  (go l '()))

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

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

(define (my-fold f acc l)
  (if (null? l)
      acc
      (my-fold f (f (first l) acc) (rest l))))

(define (my-append a b)
  (define (go l acc)
    (if (null? l)
        acc
        (go (rest l) (cons (first 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/racket/exercises/list-ops/example.rkt
trackler-2.2.1.179 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.178 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.177 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.176 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.175 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.174 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.173 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.172 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.171 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.170 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.169 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.167 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.166 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.165 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.164 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.163 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.162 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.161 tracks/racket/exercises/list-ops/example.rkt
trackler-2.2.1.160 tracks/racket/exercises/list-ops/example.rkt