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
;; 2.17 | |
(define (last-pair list) | |
(if (= (cdr list) ()) | |
(car list)) ;; I think paren error on this line. | |
(cdr list)) ;; not calling last-pair recursively | |
;; 2.18 fails for me | |
(define (reverse list) | |
(= (cdr list) ()) ;; missing an if statement | |
(= new-list (cons (car list) ()) |
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
;; 2.17 | |
;; Helpful link on equivalence | |
;; http://sicp.ai.mit.edu/Fall-2003/manuals/scheme-7.5.5/doc/scheme_4.html | |
(define (last-pair list) | |
(if (null? (cdr list)) | |
(car list) ;; fixed paren error | |
(last-pair (cdr list)))) |
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
;; 2.17 | |
;; Helpful link on equivalence | |
;; http://sicp.ai.mit.edu/Fall-2003/manuals/scheme-7.5.5/doc/scheme_4.html | |
(define (last-pair list) | |
(if (null? (cdr list)) | |
(car list) ;; fixed paren error | |
(last-pair (cdr list)))) |
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
;; 2.2 | |
;; SICP Exercise 2.2 | |
;; takes x and y coordinates to create a point | |
(define (make-point x y) | |
(cons x y)) | |
(define (make-segment x1 y1 x2 y2) | |
;; needs implementation | |
) |
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
;; think on this: | |
;; contains-incomplete returns 0 if it doesn't find | |
;; the val and greater than 0 if it does | |
(define (contains-incomplete val list) | |
(fold-left (lambda (a x) (YOUR CODE) 0 list)) | |
;; testing | |
(contains-incomplete 0 '(1 2 3)) ;; => 0 | |
(contains-incomplete 1 '(1 2 3)) ;; => 1 |
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
(define test1 '(1 3 (5 7) 9)) | |
(define test2 '((7))) | |
(define test3 '(1 (2 (3 (4 (5 (6 7))))))) | |
;; testing | |
(car test1) ;; => 1 | |
(car (cdr test1)) ;; => 3 | |
;; write your code for test1, test2, test3 in |
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
<form> | |
Name: <input type="textbox" name="name" /> <br /> | |
Check box if you're alive: <input type="checkbox" name="alive" /> <br /> | |
<input type="button" name="submit" value="we win click!" onClick="pulse(form)" /> | |
</form> | |
<script type="text/javascript"> | |
function pulse(data){ | |
console.log(data); |
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
// working version | |
function swap(a_array, i, j) { | |
var tmp = a_array[i]; | |
a_array[i] = a_array[j]; | |
a_array[j] = tmp; | |
} | |
function bubble_sort(an_array){ | |
var n = an_array.length; |
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
function max(a, b) { | |
this.a = a; | |
this.b = b; | |
if (a > b) { | |
return a; | |
} else { | |
return b; | |
} | |
} |