Skip to content

Instantly share code, notes, and snippets.

View kwrooijen's full-sized avatar

Kevin van Rooijen kwrooijen

View GitHub Profile
(use-modules (srfi srfi-1)
(rnrs))
(define (transform-at l i val)
(let-values (((left right) (split-at l i)))
(append left (cons val (cdr right)))))
(display (transform-at '(1 2 3) 1 5)) ;=> '(1 5 3)
@kwrooijen
kwrooijen / dec->bin.scm
Last active May 22, 2020 11:16
Decimal to Binary conversion options in Scheme
;; Very clean, but is not tail recursive!
(define (dec->bin n)
(cond ((zero? n) '())
(else (cons (remainder n 2)
(dec->bin (quotient n 2))))))
;; Not so clean, but is tail recursive.
(define (dec->bin n)
(letrec ((recc (lambda (acc n)
(cond ((zero? n) acc)