SICP : Let's Read!Anonymoushttps://bbs.gikopoi.com/atom/thread/17888951122026-09-14T14:41:55+00:00SICP : Let's Read!https://bbs.gikopoi.com/post/1788895112/12026-09-08T19:18:32+00:002026-09-08T19:18:32+00:00
> SICP Book: <br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-4.html<br><br>> SICP Lectures:<br>https://www.youtube.com/playlist?list=PLE18841CABEA24090<br>> Racket Scheme<br>https://racket-lang.org/download/<br>> SICP Racket<br>https://docs.racket-lang.org/sicp-manual/Installation.html<br><br>Let's embrace the tree structure of Pohon BBS. <br><br>Top level comments for chapters of the book, <br>replies to top level comments for discussions of the chapter.<br><br>Comment #2 will be for general help installing Scheme<br>Comment #3 will be for random Scheme discussion that doesn't <br>fit into chapter discussion. <br><br>Ready, start, go!
Reply to threadhttps://bbs.gikopoi.com/post/1788895112/22026-09-08T19:19:01+00:002026-09-08T19:19:01+00:00
General Scheme troubleshooting / installation help / etc goes under this<br>comment....
Reply to threadhttps://bbs.gikopoi.com/post/1788895112/32026-09-08T19:20:17+00:002026-09-08T19:20:17+00:00
Random Scheme / Lisp / programming discussion that doesn't fit into<br>chapter discussion goes here....
Chapter 1https://bbs.gikopoi.com/post/1788895112/42026-09-08T19:21:18+00:002026-09-08T19:21:18+00:00
SICP chapter 1 <br>> Building Abstractions with Procedures<br><br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-9.html#%_chap_1
phatcat power level formula (first scheme test)https://bbs.gikopoi.com/post/1788895112/52026-09-08T19:24:34+00:002026-09-08T19:24:34+00:00
(define phatcat_powerlevel 1200)<br>(define unlocked_potential 500)<br>(define (phatcat_bulky_transformation x y) (* 1.2 (+ x y)))<br>(phatcat_bulky_transformation phatcat_powerlevel unlocked_potential)<br>
Chapter 2https://bbs.gikopoi.com/post/1788895112/62026-09-08T19:27:34+00:002026-09-08T19:27:34+00:00
> Building Abstractions with Data<br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-13.html#%_chap_2
Chapter 3https://bbs.gikopoi.com/post/1788895112/72026-09-08T19:28:36+00:002026-09-08T19:28:36+00:00
> Modularity, Objects, and State<br><br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-19.html#%_chap_3
Chapter 4https://bbs.gikopoi.com/post/1788895112/82026-09-08T19:29:38+00:002026-09-08T19:29:38+00:00
> Metalinguistic Abstraction<br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-25.html#%_chap_4
Chapter 5https://bbs.gikopoi.com/post/1788895112/92026-09-08T19:30:51+00:002026-09-08T19:30:51+00:00
> Computing with Register Machines<br><br>https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-30.html#%_chap_5
outputs color based on stats (hopefully)https://bbs.gikopoi.com/post/1788895112/102026-09-08T19:37:11+00:002026-09-08T19:37:11+00:00
(define (clouds_color strength intelligence Defense)<br>(define red strength)<br>(define blue intelligence)<br>(define green defence)<br>(list red green blue))) % gives RGB color (idk how to/<br> if its even possible for lisp to output a color)
some sample lisp codehttps://bbs.gikopoi.com/post/1788895112/112026-09-08T19:51:10+00:002026-09-08T19:51:10+00:00
(define pi 3.14159265)<br>(define (square x) (* x x))<br><br>(define (volume-of-cone radius height)<br> (* pi (square radius) (/ height 3)))<br><br>(define my-cone-volume (volume-of-cone 1 2))<br><br>my-cone-volume<br>=> 2.09
Reply to threadhttps://bbs.gikopoi.com/post/1788895112/122026-09-08T20:11:17+00:002026-09-08T20:11:17+00:00
Famous article by a guy who used Lisp to become a billionaire :<br><br>> Graham, Paul. "The Roots of Lisp." (2001) 15pp <br>https://wiki.eecs.yorku.ca/course_archive/2014-15/W/6339/_media/jmc.pdf<br><br>discusses how 7 primitives became the meta language
exercise 1.3https://bbs.gikopoi.com/post/1788895112/132026-09-08T21:50:10+00:002026-09-08T21:50:10+00:00
%% (define (square x) %%<br>%% (* x x)) %%<br>%% (define (sum-squares x y) %%<br>%% (+ (square x) (square y))) %%<br>%% %%<br>%% (define (sum-greater-squares x y z) %%<br>%% (if (> x y) %%<br>%% (if (> y z) %%<br>%% (sum-squares x y) %%<br>%% (sum-squares x z)) %%<br>%% (if (> x z) %%<br>%% (sum-squares y x) %%<br>%% (sum-squares y z)))) %%<br>%% %%<br>%% (sum-greater-squares 1 2 3) %%<br>%% (sum-greater-squares 4 2 3) %%<br>%% (sum-greater-squares 5 1 0) %%<br>
Excercise 1.3https://bbs.gikopoi.com/post/1788895112/142026-09-09T01:43:46+00:002026-09-09T01:43:46+00:00
My attempt at exercise 1.3. it took me a long time as most of my attempts made code that excluded anything that wasn't the maximum number, so i guess finding the "middle" number is what makes this challenging. my first attempts were checking each variable against the others individually (mistake). if x>y then output x otherwise 0, if x>z output x otherwise 0 then multiply both outputs, repeat for each variable (rather silly in retrospect). After this i decided to only compare to the third variable if the first check failed and directly compute the square if the variable wasn't the minimum. Code below:<br><br>%%#lang sicp%%<br>%%(define (sicp_ex_1.3 x y z)%%<br>%% (+%%<br>%% (if (< x y) (if (< x z) 0 (* x x)) (* x x))%%<br>%% (if (< y x) (if (< y z) 0 (* y y)) (* y y))%%<br>%% (if (< z y) (if (< z x) 0 (* z z)) (* z z))))%%<br>%% %% <br>%%(sicp_ex_1.3 1 2 3)%%<br>%%result was 13 so it worked%%
corrected exercise 1.3https://bbs.gikopoi.com/post/1788895112/152026-09-09T15:22:45+00:002026-09-09T15:22:45+00:00
%%%<br>Updated to catch PhatCat's fix -- if x, y, and z are the same<br>value, the code does not work<br><br>(define (square x) <br> (* x x)) <br>(define (sum-squares x y) <br> (+ (square x) (square y))) <br> <br>(define (sum-greater-squares x y z) <br> (if (> x y) <br> (if (> y z) <br> (sum-squares x y) <br> (sum-squares x z)) <br> (if (> x z) <br> (sum-squares y x)<br> (if (= x y z)<br> (sum-squares x x)<br> (sum-squares y z)))))<br>%%%
fix ex 1.3https://bbs.gikopoi.com/post/1788895112/162026-09-09T15:27:28+00:002026-09-09T15:27:28+00:00
summed all 3 squares if x y z were the same. added a check to just force one variable to zero if all the numbers were equal so theres probably a more elegant solution :P. Code:<br><br>%%#lang sicp%%<br><br>%%(define (square x) (* x x))%%<br><br>%%(define (sicp_ex_1.3 x y z)%%<br>%% (+%%<br>%% (if (= x y) 0 (if (= x z) 0%%<br>%% (if (< x y) (if (< x z) 0 (square x)) (square%% %%x))))%%<br>%% (if (< y x) (if (< y z) 0 (square y)) (square y))%%<br>%% (if (< z y) (if (< z x) 0 (square z)) (square z))))%%<br> <br>%%(sicp_ex_1.3 1 2 3)%%<br>%%(sicp_ex_1.3 2 2 2)%%<br>%%(sicp_ex_1.3 2 1 0)%%
epic phailhttps://bbs.gikopoi.com/post/1788895112/172026-09-09T15:35:08+00:002026-09-09T15:35:08+00:00
Fixed the fix<br><br>%%#lang sicp%%<br><br>%%(define (square x) (* x x))%%<br><br>%%(define (sicp_ex_1.3 x y z)%%<br>%% (+%%<br>%% (if (= x y z) 0%%<br>%% (if (< x y) (if (< x z) 0 (square x)) (square x))))%%<br>%% (if (< y x) (if (< y z) 0 (square y)) (square y))%%<br>%% (if (< z y) (if (< z x) 0 (square z)) (square z)))%%<br> <br>%%(sicp_ex_1.3 1 2 3)%%<br>%%(sicp_ex_1.3 2 2 2)%%<br>%%(sicp_ex_1.3 2 1 0)%%
exercise 1.3https://bbs.gikopoi.com/post/1788895112/182026-09-09T20:55:03+00:002026-09-09T20:55:03+00:00
%%%<br>[(define (square a)<br> (* a a))<br><br>(define (smallest x y z)<br> (if (< x y)<br> (if (< x z) x z)<br> (if (< y z) y z)))<br><br>(define (procedure x y z)<br> (- (+ (square x)(square y)(square z))(square (smallest x y z))))<br><br>(procedure 7 10 10)]<br>%%%
Excercise 1.7https://bbs.gikopoi.com/post/1788895112/192026-09-14T01:50:23+00:002026-09-14T01:50:23+00:00
The full code is VERY long and has multiple things needing to be defined so ill only post what was changed from the procedure defined in SICP. My thought process was: <br>need to compare guesses, so need to know guess-1 and guess-2<br>modify the improve definition to "save" the old guess? (oh no...)<br>OR <br>%%just use (improve guess x) itself as the guess 2%%<br><br>then<br>%%;modified from 1.1.7 for Exercise 1.7%%<br>%%(define (good-enough? guess x)%%<br>%%;(< (abs (- (square guess) x)) 0.001));old/original code [from SICP]%%<br>%%(< ;check if guess is within tolerance%%<br> %%(abs ; stops it from breaking if it gives a negative number%%<br> %%(- ;small difference between subsequent guesses => fraction ~1, so fraction-1 ~0%%<br> %%(/%%<br> %%(abs (square guess))%%<br> %%(abs (square (improve guess x)))) 1)) 0.001))%% <br>...<br>(sqrt 0.00000000000001) ;very small number test<br>(sqrt 1000000000000000) ;very large number test<br><br>answers were correct
Reply to threadhttps://bbs.gikopoi.com/post/1788895112/202026-09-14T01:53:51+00:002026-09-14T01:53:51+00:00
%%where 0.001 was the tolerance to see if the guess was good enough%%
PHATCATTTThttps://bbs.gikopoi.com/post/1788895112/212026-09-14T02:07:37+00:002026-09-14T02:07:37+00:00
the tolerance I specified was kinda wide, which made the big number calculation off by a good amount (oops!). After reducing the tolerance to 0.000000000001 (rest of the code kept the same) i get the same result as my calculator (Casio fx-991EX). Dr racket seems to have rounded the small square roots output to 1e-7, im not sure if this is a fault in my code or just computer stuff (can anyone confirm?)<br><br>%% also i noticed that if im just comparing the guesses,i dont need to square them and then divide. I also had redundant (abs ) functions in the code so heres an improvement%%<br><br>%%(define (good-enough? guess x)%%<br>%%(< %%<br> %%(abs %%<br> %%(- %%<br> %%(/ %%<br> %%guess%%<br> %%(improve guess x)) 1)) 0.000000000001))%%<br><br>(sqrt 0.00000000000001) ;very small number test<br>(sqrt 1000000000000000) ;very large number test<br><br>outputs:<br>1e-7<br>31622776.601683907
Excercise 1.8https://bbs.gikopoi.com/post/1788895112/222026-09-14T14:41:55+00:002026-09-14T14:41:55+00:00
This one was just implementing the formula and then<br>%%replacing the old one in the "improve" procedure%%<br><br>%%(define (improve guess x)%%<br> %%(/%%<br> %%(+%%<br> %%(/ x (square guess))%%<br> %%(* guess 2))%%<br> %%3)%%