This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; P22 (*) Create a list containing all integers within a given range. | |
;; If first argument is smaller than second, produce a list in decreasing order. | |
;; Example: | |
;; * (range 4 9) | |
;; (4 5 6 7 8 9) | |
#lang racket | |
(provide range) | |
(define (range ini fin) | |
(let ((proc (if (> ini fin) - +))) | |
(let loop ((i ini) (acc '())) | |
(let ((cia (cons i acc))) | |
(if (= i fin) | |
(reverse cia) | |
(loop (proc i 1) cia)))))) |
0 件のコメント:
コメントを投稿