Code Monkey home page Code Monkey logo

sicp's People

Contributors

awth13 avatar bogdanp avatar cwfoo avatar eroomde avatar leifandersen avatar noahstorym avatar soegaard avatar sorawee avatar spdegabrielle avatar wangjiezhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sicp's Issues

How does the coordinate mapping work?

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

untitled

What am I missing?

random: unbound identifier in module

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.

DrRacket can't install the package

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

Expression will out of momery when sicp package installed on racket-cs

  • My OS Version is MacOS Catilina 10.15.1
  • Racket-CS version is 7.5
  • Details
    When I installed sicp package on dr-racket-cs ,the express will show error "out of memory".The code is
#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!

Default output syntax is `print`, should be `output`

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!

squash-inwards example of the book

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:

diamond-1

(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:

image

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.

paint other image

I want to paint other images like

(paint einstein)

how to implement this? thanks.

filter: contract violation expected: list?

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...

segments->painter fails with list from #lang sicp

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.

vector-ref: contract violation for transforming images of certain sizes

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.

  • Other 182x182 images do NOT work.
  • Increasing the width by one pixel, i.e. 183x182, does NOT work.
  • Either slightly smaller or slightly larger images (181x181, 183x183) as well as other dimensions such as 128x128 or 400x400, seem to work.
  • The image format, i.e. GIF vs PNG, does not matter.
  • The content of the image, such as colors or transparency, does not matter.
  • It seems to be purely an issue of image dimensions.

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.

Some machine time related procedures are not provided yet

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.

SICP not building on the build server

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

segments->painter :: target is not an object

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?

Contract for vector-scale should be real?

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.