Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2021-04-10T09:49:02+00:00 → 2021-04-17T08:56:26+00:00
<language>SchemeJS</language> | |
<code id="605dd0651e5eb"> | |
(define stream-car car) | |
(define stream-cdr | |
(lambda (stm) | |
(force (cdr stm)))) | |
(define-macro (stream-cons head tail) | |
`(cons ,head (delay ,tail))) | |
(define stream? | |
(lambda (stm) | |
(and (pair? stm) (promise? (cdr stm))))) | |
(define stream-map | |
(lambda (proz stm) | |
(stream-cons (proz (stream-car stm)) (stream-map proz (stream-cdr stm))))) | |
(define show-stream | |
(lambda (stm n) | |
(letrec | |
([show | |
(lambda (stm n ls) | |
(if (= n 0) | |
(apply display (append ls (list "..."))) | |
(show (stream-cdr stm) (- n 1) (append ls (list (stream-car stm) ", ")))))]) | |
(show stm n ())))) | |
(define zeige-mir show-stream) | |
</code> | |
<code id="605dd0651e650"> | |
(define baue-hilberthotel | |
(lambda () | |
(stream-cons #f (baue-hilberthotel))) | |
) | |
(define hilberthotel (baue-hilberthotel)) | |
</code> | |
<run id="605dd0651e6ad"> | |
(zeige-mir hilberthotel 11) | |
</run> | |
<code id="605dd4de3e11c"> | |
(define einzelbuchung | |
(lambda (val stm pos) | |
(let ([old-pos pos]) | |
(letrec | |
([shorten | |
(lambda (val stm pos) | |
(if (= pos 0) | |
(if (eq? #f (stream-car stm)) | |
(stream-cons val (stream-cdr stm)) | |
(raise (string-append (number->string old-pos) " schon belegt mit: " (stream-car stm)))) | |
(stream-cons (stream-car stm) (shorten val (stream-cdr stm) (- pos 1))) | |
)) | |
]) | |
(shorten val stm pos) | |
) | |
) | |
) | |
) | |
</code> | |
<run id="605dd4de3e1e0"> | |
(set! hilberthotel (einzelbuchung "Otto Grundmann" hilberthotel 3)) | |
| − | (zeig-mir hilberthotel 12) |
| + | (zeige-mir hilberthotel 12) |
</run> | |
<code id="605ded6247d06"> | |
(define baue-kleinbus | |
(lambda (numb pers) | |
(list numb pers))) | |
(define kleinbus815 (baue-kleinbus 815 8)) | |
</code> | |
<run id="605ded74e3e0f"> | |
| − | (zeig-mir kleinbus815) |
| + | (zeige-mir kleinbus815) |
</run> | |
<code id="605dff4adf833"> | |
(define kleingruppenbuchung | |
(lambda (hotel finite-bus) | |
(letrec | |
([helper | |
(lambda (hotel finite-bus pos) | |
(if (not (empty? finite-bus)) | |
(helper (einzelbuchung (car finite-bus) hotel pos) (+ pos 1)) | |
(hotel) | |
) | |
) | |
]) | |
(hotel finite-bus 0) | |
) | |
) | |
) | |
(set! hilberthotel (kleingruppenbuchung kleinbus815 hilberthotel)) | |
</code> | |
<run id="605dff4adf8c7"> | |
(zeig-mir hilberthotel 12) | |
</run> |