Skip to content

Instantly share code, notes, and snippets.

@carld
Created August 2, 2021 12:04
Show Gist options
  • Save carld/25865bc39fceac17c81483b1b952ae35 to your computer and use it in GitHub Desktop.
Save carld/25865bc39fceac17c81483b1b952ae35 to your computer and use it in GitHub Desktop.
Take the even elements from a list using Racket
(define (take-even lst)
(letrec [(taker (lambda (lst-rem result)
;(printf "~a ~a" lst-rem result)
(if (< (length lst-rem) 2)
result
(cons (car (cdr lst-rem)) (taker (cdr (cdr lst-rem)) result)))))]
(taker lst '())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment