Code Monkey home page Code Monkey logo

Comments (10)

sorawee avatar sorawee commented on June 18, 2024 1

That's a regression caused by me (see ce24736). I will push a fix soon, and you should be able to switch back to #lang sicp after that (feel free to keep using #lang racket, too!)

from sicp.

soegaard avatar soegaard commented on June 18, 2024

Hi Rick,

This is a bit subtle. The language #lang sicp uses mutable pairs while
#lang racket uses immutable pairs.
If you create a list in #lang sicp you will get a list consisting of
mutable pairs (printed as mcons) and
since the segments->painter is expecting a Racket list consisting of
immutable pairs (printed as cons) you get
the error.

Best advice: Use #lang racket to work with the painter language.

/Jens Axel

2016-03-26 12:55 GMT+01:00 Rick van de Loo [email protected]:

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
https://github.com/sicp-lang/sicp/blob/master/sicp-pict/prmpnt.scm#L114.
The snippet above works if instead of using #lang sicp, #lang racket/base
is used.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#4

Jens Axel Søgaard

from sicp.

soegaard avatar soegaard commented on June 18, 2024

I'll see if I can get segments->painter to accept both kind of lists.

/Jens Axel

2016-03-26 14:29 GMT+01:00 Jens Axel Søgaard [email protected]:

Hi Rick,

This is a bit subtle. The language #lang sicp uses mutable pairs while
#lang racket uses immutable pairs.
If you create a list in #lang sicp you will get a list consisting of
mutable pairs (printed as mcons) and
since the segments->painter is expecting a Racket list consisting of
immutable pairs (printed as cons) you get
the error.

Best advice: Use #lang racket to work with the painter language.

/Jens Axel

2016-03-26 12:55 GMT+01:00 Rick van de Loo [email protected]:

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
https://github.com/sicp-lang/sicp/blob/master/sicp-pict/prmpnt.scm#L114.
The snippet above works if instead of using #lang sicp, #lang racket/base
is used.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#4

Jens Axel Søgaard

Jens Axel Søgaard

from sicp.

soegaard avatar soegaard commented on June 18, 2024

This commit
0da6a81

fixes the problem.

Update the sicp package either using raco or the DrRacket package manager
to get the changes.

Thanks for the bug report.

/Jens Axel

2016-03-26 14:36 GMT+01:00 Jens Axel Søgaard [email protected]:

I'll see if I can get segments->painter to accept both kind of lists.

/Jens Axel

2016-03-26 14:29 GMT+01:00 Jens Axel Søgaard [email protected]:

Hi Rick,

This is a bit subtle. The language #lang sicp uses mutable pairs while
#lang racket uses immutable pairs.
If you create a list in #lang sicp you will get a list consisting of
mutable pairs (printed as mcons) and
since the segments->painter is expecting a Racket list consisting of
immutable pairs (printed as cons) you get
the error.

Best advice: Use #lang racket to work with the painter language.

/Jens Axel

2016-03-26 12:55 GMT+01:00 Rick van de Loo [email protected]:

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
https://github.com/sicp-lang/sicp/blob/master/sicp-pict/prmpnt.scm#L114.
The snippet above works if instead of using #lang sicp, #lang
racket/base is used.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#4

Jens Axel Søgaard

Jens Axel Søgaard

Jens Axel Søgaard

from sicp.

vdloo avatar vdloo commented on June 18, 2024

Great! Thanks for the quick reply :)

from sicp.

adityaathalye avatar adityaathalye commented on June 18, 2024

GOOD GRIEF! I spent a whole day wondering what in the world was wrong with my code.

Thank you for the question and the answer. I wish I had checked sooner.

I can concur that declaring #lang racket instead of #lang sicp is the fix.

I pushed a commit to my repo, fixing the language declaration, and with details in the commit message.

Use 'racket', not 'sicp' in ex2-44 picture lang file adityaathalye/sicp@c8b62c3

from sicp.

sorawee avatar sorawee commented on June 18, 2024

Hmm. Provided that @soegaard made segments->painter to accept both mutable and immutable lists, there should not be any problem, right? Can you provide us a code example that leads to a problem?

from sicp.

adityaathalye avatar adityaathalye commented on June 18, 2024

Hmm. Provided that @soegaard made segments->painter to accept both mutable and immutable lists, there should not be any problem, right? Can you provide us a code example that leads to a problem?

Updated my earlier comment to keep things in context: #4 (comment)

from sicp.

sorawee avatar sorawee commented on June 18, 2024

I believe this is fixed by 4152068. Closing. Feel free to reopen it if you find any other issues.

from sicp.

adityaathalye avatar adityaathalye commented on June 18, 2024

I just updated lang-sicp locally and can confirm SHA 4152068 fixes the bug. Thank you!

from sicp.

Related Issues (20)

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.