sicp-lang / sicp Goto Github PK
View Code? Open in Web Editor NEWA SICP language for Racket.
License: GNU Lesser General Public License v3.0
A SICP language for Racket.
License: GNU Lesser General Public License v3.0
External links don't work.
Contributors links don't work:
4 Contributors
The following individuals contributed to the implementation and documentation of SICP language:
Abelson & Sussman wrote Structure and Interpretation of Computer Programs. <----
Daniel Coore designed and implemented the original image display code in MIT Scheme. <----
I want to paint other images like
(paint einstein)
how to implement this? thanks.
There is no documentation for cons-stream
and amb
.
Hi ,
Please add the racket topic to this repo - I think others will be interested and this will help them find it at https://github.com/topics/racket
https://help.github.com/en/articles/classifying-your-repository-with-topics
Kind regards,
Stephen
(define (ceiling->exact n)
(inexact->exact (floor n)))
See
sicp/sicp-pict/mit-support.scm
Line 16 in 62e7e0d
Hi,
I'm trying to folow SICP with DrRacket but when trying to install the package this error is returned
ssl-make-client-context: requested protocol not supported;
SSL not available; check `ssl-load-fail-reason'
requested: 'auto
context...:
/usr/share/racket/collects/openssl/mzssl.rkt:672:0: encrypt->method
/usr/share/racket/collects/openssl/mzssl.rkt:747:0: make-raw-context
/usr/share/racket/collects/openssl/mzssl.rkt:736:0: make-context
/usr/share/racket/collects/openssl/mzssl.rkt:764:0: ssl-make-client-context
/usr/share/racket/collects/openssl/mzssl.rkt:1061:0: ssl-secure-client-context
/usr/share/racket/collects/openssl/mzssl.rkt:779:0: get-context
/usr/share/racket/collects/openssl/mzssl.rkt:615:18
/usr/share/racket/collects/ffi/unsafe/atomic.rkt:73:13
/usr/share/racket/collects/openssl/mzssl.rkt:1590:0: wrap-ports
/usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
/usr/share/racket/collects/net/http-client.rkt:67:0: http-conn-open!
/usr/share/racket/collects/net/http-client.rkt:274:0: http-conn-open
/usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
/usr/share/racket/collects/net/url.rkt:202:0: http://getpost-impure-port
/usr/share/racket/collects/net/url.rkt:305:0: get-pure-port/headers
/usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
...
don't know if is my problem or if I can bypass it by downloading directly here from github or whir raco command in the shell
It seems that instead of frame-coord-map
, this implementation maps the points in the unit square to the actual output device by manipulating the transformation matrix. I played a little bit, but can't grasp how it's done.
Take this painter as an example:
(define line (vects->painter (list (make-vect 0 0) (make-vect 1 1))))
The transformation matrix right before it draws the line is #(198.0 0.0 0.0 -198.0 0.0 200.0)
. I verify the mapping by hand using the formula. It correctly maps '(0 0)
to '(0 200)
, and '(1 1)
to '(200 0)
. (I use #(200.0 0.0 0.0 -200.0 0.0 200.0)
for easy calculation.)
But when I run the following code:
(define bm (make-bitmap 200 200))
(define dc (new bitmap-dc% [bitmap bm]))
(send dc set-initial-matrix (vector 198.0 0.0 0.0 -198.0 0.0 200.0))
(send dc draw-line 0.0 0.0 1.0 1.0)
It just gives this picture
What am I missing?
SICP package not listed in category “Other Languages in the Racket Environment”
it is instead listed in Miscellaneous Libraries
From the "A Picture Language" section, the implementation of squash-inwards
is said to shape like diamonds the given painters. Like the image of Rogers:
(define (squash-inwards painter)
(transform-painter painter
(make-vect 0.0 0.0)
(make-vect 0.65 0.35)
(make-vect 0.35 0.65)))
(paint (squash-inwards einstein))
Although with the following snippet applied to Einstein image I get the following result:
The other implementations of the book like flip-vert
and rotate90
are working fine, but looking at the implementation of transform-painter
I can't understand how it works after subtracting the mapped vector edges by the new origin. I found this question on stack overflow which sums up precisely where I lack understanding.
SICP exercise 2.32 reads
We can represent a set as a list of distinct elements, and we can represent the set of all subsets of the set as a list of lists. For example, if the set is (1 2 3), then the set of all subsets is (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)). Complete the following definition of a procedure that generates the set of subsets of a set and give a clear explanation of why it works:
(define (subsets s) (if (null? s) (list nil) (let ((rest (subsets (cdr s)))) (append rest (map <??> rest)))))
My solution is this:
(define (subsets s)
(if (null? s)
(list nil)
(let ((rest (subsets (cdr s))))
(append rest (map (lambda (ss) (cons (car s) ss)) rest)))))
which totally works, but since the default output syntax is print
, I get this in the REPL:
> (subsets (list 1 2 3))
(mcons
'()
(mcons
(mcons 3 '())
(mcons
(mcons 2 '())
(mcons
(mcons 2 (mcons 3 '()))
(mcons
(mcons 1 '())
(mcons (mcons 1 (mcons 3 '())) (mcons (mcons 1 (mcons 2 '())) (mcons (mcons 1 (mcons 2 (mcons 3 '()))) '()))))))))
>
and I don't think this is very noob friendly. I expected something more like the write
output provides:
> (subsets (list 1 2 3))
{() {3} {2} {2 3} {1} {1 3} {1 2} {1 2 3}}
Which still isn't exactly the way it shows list results in the book, but it's still way more legible. Forgive me if this isn't up to the language pack to decide, it seems to me that when I do #lang sicp
it should automatically set this output format--I am not totally sure how DrRacket works, so this may not be possible.
In any case, thank you for an excellent method of following along with SICP!
#lang sicp
(/ (+ 5
4
(- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3
(- 6 2)
(- 2 7)))
And also I tried other exercises in sicp.
but I will work well when I use #lang racket
.
When I uninstalled dr-racket-cs
then installed drracket
and reinstalled sicp packge ,it will work well!
Hello, thanks for keeping up such project. It's been really helpful for my SICP studies. However I can't make it work for the exercise 2.49, I hope this doesn't come as do my homework type of issue, but debugging the code seems a bit cryptic for me.
#lang sicp
(#%require sicp-pict)
(define tl (make-vect 0 10))
(define tr (make-vect 10 10))
(define bl (make-vect 0 0))
(define br (make-vect 10 0))
(define segments
(vects->segments
(list bl tl tr br bl)))
(define origin (make-vect 0 0))
(define frame (make-frame origin tl br))
(paint ((segments->painter segments) frame)) ;; fails with "target is not an object. target: #f"
When I check the code here, there's a call to send
which in turn use dc
from (current-dc)
whereas it seems to be #f
at the start. I don't know anything of racket but I suspect that the current-dc
call should take another value at this point. But how do I arrive to that?
There is something odd about filter when the sicp package is required. Here's my code.
(require sicp)
(print-as-expression #f) ; for printing lists
(#%require r5rs/init) ; for printing lists
(filter (lambda (x) #t) (list ))
()
(filter (lambda (x) #t) (list 1))
; filter: contract violation
; expected: list?
; given: (1)
; [,bt for context]
I don't know what caused filter to act so strangely...
Hi @NoahStoryM and @sorawee
Right now sicp
doesn't build on the build server [1].
The reason is that the build server uses version 8.5, but the new typed/sicp
relies on improvements to typed/racket
which are in the development version only.
(The type Image-Snip%
was added recently.)
Therefore we need to wait until the next release before merge the changes.
So in short: I am reverting the changes for now. When the new release is out,
I'll remerge the changes again.
I am sorry for the inconvenience.
[1] https://pkg-build.racket-lang.org/server/built/fail/sicp.txt
Hi,
I ran into a problem while doing exercise 2.49 from SICP. The segments->painter procedure from prmpnt.scm gives a contract violation if it's given a list defined in the sicp lang.
#lang sicp
(#%require sicp-pict)
(define (make-vect x y)
(cons x y))
(define (xcor-vect vect)
(car vect))
(define (ycor-vect vect)
(cdr vect))
(define (make-segment vect-origin-to-start vect-origin-to-end)
(cons vect-origin-to-start vect-origin-to-end))
(define outline-segments
(segments->painter
(list ; <- culprit
(make-segment (make-vect 0.0 0.0) (make-vect 0.0 0.99))
(make-segment (make-vect 0.0 0.0) (make-vect 0.99 0.0))
(make-segment (make-vect 0.99 0.0) (make-vect 0.99 0.99))
(make-segment (make-vect 0.0 0.99) (make-vect 0.99 0.99)))))
(paint outline-segments)
for-each: contract violation
expected: list?
given: (mcons (mcons '(0.0 . 0.0) '(0.0 . 0.99)) (mcons (mcons '(0.0 . 0.0) '(0.99 . 0.0)) (mcons (mcons '(0.99 . 0.0) '(0.99 . 0.99)) (mcons (mcons '(0.0 . 0.99) '(0.99 . 0.99)) '()))))
argument position: 2nd
The violation occurs here. The snippet above works if instead of using #lang sicp
, #lang racket/base
is used.
Some procedures under topic "machine time", like process-time-clock
and with-timings
, are not provided yet, while they are listed in the MIT/GNU Scheme docs. And this fact is verified with mit-scheme, installed by brew install scheme
under macOS.
I came across this issue in this blog, in which the author defines a procedure on top of with-timings
to print the run/gc/actual time of a procedure.
Hi Jens,
The following code works as expected until the last line.
#lang sicp
(#%require sicp-pict)
(paint einstein)
(paint (flip-horiz einstein))
(paint (flip-vert einstein))
(define wave (load-painter "wave.gif"))
(paint wave)
(paint (flip-horiz wave))
(paint (flip-vert wave))
At this point it throws the error:
vector-ref: contract violation
expected: vector?
given: 0
argument position: 1st
other arguments...:
The image in question is this one: wave.
Only some transformations cause errors. These include flip-vert
, rotate90
, and rotate180
. Others such as flip-horiz
and rotate270
did not fail.
But if you increase the height of the image by one pixel, that is, change the size from 182x182 to 182x183, all of these transformations work as expected.
Based on this information, I tried several other things.
I encourage you to try using the image in question, which is part of the online SICP book, and see for yourself if you get the same error.
I'm trying to do exercise 3.5 and it makes use of the random
procedure, which is apparently not provided by the SICP language. It is provided by the racket language though.
The invariant for vect
is that the coords should be reals. However, vector-scale
can break this invariant. E.g.,
(vector-scale (sqrt -1) (vect 1 2))
results in
(vect 0+1i 0+2i)
(define (solve f y0 dt)
(define y (integral (delay dy) y0 dt))
(define dy (stream-map f y))
y)
print y: undefined; cannot use before initialization
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.