Skip to content

Commit

Permalink
UGH, I think I know what to do, FUCKING LIST AND CONS CONFUCSING ME
Browse files Browse the repository at this point in the history
AND WHY THE HELL DID THEHY USE CONS INSTEAD OF LIST ?
oh god now I'm gonna have to review everything up until now to check if
I am understanding this correctly...

sigh

but still I guess this is progress, by the way this version of the code
is still not complete I just realized that if I kept only pushing
correct stuff its not gonna be much of learning tbh.
  • Loading branch information
zenAndroid committed Feb 29, 2020
1 parent 698b82a commit 30ced8c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions 4_fourth/09-WhileUntil.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
; 2020-02-29 11:33 :: zenAndroid :: Other solutions only implemented a subset, I will therefore probably implement while and until
; Also, I saw Eli's solution and didn't like that it leaked the definition of the while-iter procedure to the outer namespace.


; For reference:
; (until <condition> <body>)

(define (tagged-list? exp tag)
(if (pair? exp)
(eq? (car exp) tag)
false))

(define (until? exp) (tagged-list? exp 'until))

(define (until-condition exp) (cadr exp))

(define (until-body exp) (cddr exp))

(define (make-lambda parameters body)
(list 'lambda parameters body))

(define (make-if predicate consequent alternative)
(list 'if predicate consequent alternative))

(define (last-exp? seq) (null? (cdr seq)))
(define (first-exp seq) (car seq))
(define (rest-exps seq) (cdr seq))

(define (sequence->exp seq)
(cond ((null? seq) seq)
((last-exp? seq) (first-exp seq))
(else (make-begin seq))))

(define (make-begin seq) (cons 'begin seq))

(define (until-exp-handler exp)
(let ((condition (until-condition exp))
(body (until-body exp)))
(list
(make-lambda '()
(sequence->exp
(list 'define (list 'loop)
(make-if condition
(sequence->exp (list body (list 'loop)))
'while-loop-done)
(list 'loop)))))))

(define test-code
'(until
(< ii 5)
(display ii)
(set! ii (+ ii 1))))


; ((lambda ()
; (define (loop)
; (if (< ii 5)
; (begin ((display ii) (set! ii (+ ii 1))) (loop))
; while-loop-done)))
; (loop))

(define ii 0)

((lambda ()
(begin (define (loop)
(if (< ii 5)
(begin (display ii) (set! ii (+ ii 1)) (loop))
'while-loop-done))(loop))))

0 comments on commit 30ced8c

Please sign in to comment.