Skip to content

Commit

Permalink
finished scheme Part III
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyfan34 committed Mar 14, 2021
1 parent 400dfca commit 2ecaefa
Show file tree
Hide file tree
Showing 55 changed files with 26 additions and 10 deletions.
Binary file modified scheme/.ok_history
Binary file not shown.
Binary file modified scheme/.ok_storage
Binary file not shown.
Binary file modified scheme/__pycache__/scheme.cpython-38.pyc
Binary file not shown.
Binary file added scheme/editor/__pycache__/__main__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added scheme/editor/__pycache__/console.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added scheme/editor/__pycache__/helper.cpython-38.pyc
Binary file not shown.
Binary file added scheme/editor/__pycache__/lexer.cpython-38.pyc
Binary file not shown.
Binary file added scheme/editor/__pycache__/lists.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added scheme/editor/__pycache__/log.cpython-38.pyc
Binary file not shown.
Binary file added scheme/editor/__pycache__/log_utils.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added scheme/editor/__pycache__/persistence.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 26 additions & 10 deletions scheme/questions.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
;; Returns a list of two-element lists
(define (enumerate s)
; BEGIN PROBLEM 15
'replace-this-line
(begin (define (helper index s)
(cond ((null? s) s)
(else (cons (cons index (cons (car s) nil)) (helper (+ 1 index) (cdr s))))))
(helper 0 s))
)
; END PROBLEM 15

Expand All @@ -23,7 +26,10 @@
;; the merged lists.
(define (merge comp list1 list2)
; BEGIN PROBLEM 16
'replace-this-line
(cond ((null? list1) list2)
((null? list2) list1)
((comp (car list1) (car list2)) (cons (car list1) (merge comp (cdr list1) list2)))
(else (cons (car list2) (merge comp list1 (cdr list2)))))
)
; END PROBLEM 16

Expand All @@ -37,9 +43,20 @@

(define (nondecreaselist s)
; BEGIN PROBLEM 17
'replace-this-line
(cond (
((null? (cdr s)) (cons s nil))
((> (car s) (car (cdr s))) (cons (cons (car s) nil) (nondecreaselist (cdr s))))
(else (cons (cons (car s) (car (nondecreaselist (cdr s)))) (cdr (nondecreaselist (cdr s))))))
)
)
; END PROBLEM 17


(define (zip s)
(cond ((null? s) '(() ()))
(else (cons (cons (car (car s)) (car (zip (cdr s)))) (cons (cons (car (cdr (car s))) (car (cdr (zip (cdr s))))) nil))))
)


;; Problem EC
;; Returns a function that checks if an expression is the special form FORM
Expand All @@ -55,12 +72,12 @@
(define (let-to-lambda expr)
(cond ((atom? expr)
; BEGIN PROBLEM EC
'replace-this-line
expr
; END PROBLEM EC
)
((quoted? expr)
; BEGIN PROBLEM EC
'replace-this-line
expr
; END PROBLEM EC
)
((or (lambda? expr)
Expand All @@ -69,19 +86,18 @@
(params (cadr expr))
(body (cddr expr)))
; BEGIN PROBLEM EC
'replace-this-line
(cons form (cons params (let-to-lambda body)))
; END PROBLEM EC
))
((let? expr)
(let ((values (cadr expr))
(body (cddr expr)))
; BEGIN PROBLEM EC
'replace-this-line
(cons (cons 'lambda (cons (car (zip values)) (cons (let-to-lambda (car body)) nil))) (car (cdr (zip values))))
; END PROBLEM EC
))
(else
; BEGIN PROBLEM EC
'replace-this-line
(map let-to-lambda expr)
; END PROBLEM EC
)))

)))
Binary file modified scheme/tests/__pycache__/01.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/02.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/03.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/04.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/05.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/06.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/07.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/08.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/09.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/10.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/11.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/12.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/13.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/14.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/15.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/16.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/17.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/18.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/19.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/20.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/EC.cpython-38.pyc
Binary file not shown.
Binary file modified scheme/tests/__pycache__/eval_apply.cpython-38.pyc
Binary file not shown.

0 comments on commit 2ecaefa

Please sign in to comment.