From 2df10ebf9e0d9f15fd58b3167690245e254535e9 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 4 Jul 2020 15:13:54 +0200 Subject: [PATCH] add a beginning fx --- data-structures/lists.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/data-structures/lists.scm b/data-structures/lists.scm index 2b01b17..8f84f3c 100644 --- a/data-structures/lists.scm +++ b/data-structures/lists.scm @@ -10,7 +10,18 @@ ((> b e) '()) (#t (cons b (rangeinc (+ 1 b) e))))) -(define (less-than l n) (cond ((null? l) #t) ((<= n 0) #f) (#t (less-than (cdr l) (- n 1))))) +(define (less-than l n) + (cond + ((null? l) #t) + ((<= n 0) #f) + (#t (less-than (cdr l) (- n 1))))) + +(define (beginning l n) + (cond + ((null? l) '()) + ((<= n 0) '()) + (#t (cons (car l) (beginning (cdr l) (- n 1)))))) + (define (unit v) v) (define (aget key alist) (cdr (assoc key alist))) (define (aset key val alist)