Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code refactored for beginners, with extensive comments and docstrings #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

gw666
Copy link

@gw666 gw666 commented Mar 7, 2015

Hi--I completely changed things around to make the code to my liking. I apologize for the inadequacies of my commit stream--I'm still learning good git usage.

Feel free to take any part(s) of it you desire. Thanks.

Gregg

PS: It would be nice to get a brief note back from you. I feel I'm dumping code into the void. GW

gw666 and others added 5 commits January 17, 2015 22:09
also added comments to help orient new users
shapes: box, x, diamond, george

segment-lists allow compound shapes to be drawn using
concat; see diamond-x

fcns: flip-horiz, flip-vert; rotate, rotate180, rotate270; below
Abstracted split-up, split-right into higher-level split function.
Source code refactored, with comments and docstrings added, to make it
easy for beginners to get up to speed quickly.

Does not implement image-painter.

To give yourself a chance to complete the exercise as ‘thattommyhall’
intended, delete the bodies of the following functions:

  add-vec
  sub-vec
  scale-vec
  flip-horiz
  rotate
  below
  path
  right-split (uncomment by removing “#_”)
  up-split (uncomment by removing “#_”)
  split

Just evaluate this file to see the “goal” function, square-limit, draw
itself. This version uses the “higher-level” versions of right-split
and up-split.

If you decide to write the code for up-split and derive the
higher-level function ‘split’, you will need to comment out or remove
the versions of right-split and up-split that follow split in the
source code and un-comment the versions that precede split in the
source code.

Enjoy, and please give me feedback if you find my version helpful!
@thattommyhall
Copy link
Member

Hey @gw666, I can't merge it as it has answers in it :-)

I did a talk about the escher stuff for a user group a few weeks ago, which closes some of the exposition gap from just the slides, I'll send the video round soon.

I actually was unsure about using clojure vectors for the project (at the cost of some data abstraction), I like that you added make-vec but kept using the destructuring (if you were to swap out vecs for for instance more efficient tuples you would have to do at least that). Have a look if you can swap out your make-vec for one that returns a tuple https://github.com/ztellman/clj-tuple and see if everything still works.

Have a look at the interpreter project, there is a video for that coming soon too.

@gw666
Copy link
Author

gw666 commented Mar 16, 2015

Hi, Tommy,

Thanks for getting back to me. I really appreciate it.

In the little time I have, I've found a composable way to add multicolor pictures and have been thinking about ways to make the basic picture change over time. It's simple stuff, I'm sure, but I'm learning to think in terms of composition and abstraction.

Two questions:

  1. If I take out the definitions of all the code that you mark as "COMPLETE [THIS]" but leave in the docstrings and the comments (equivalent to adding the docstrings and comments to your original code), would you be interested in using this? (I'm a great believer in supporting the user so that they kill brain cells working on the point of the exercise instead of the bare mechanics.)

  2. If 1) is "yes", would you like for me to integrate clj-tuple?

As always, many thanks for your work!

Best wishes,

Gregg

On Mar 14, 2015, at 6:09 PM, thattommyhall [email protected] wrote:

Hey @gw666, I can't merge it as it has answers in it :-)

I did a talk about the escher stuff for a user group a few weeks ago, which closes some of the exposition gap from just the slides, I'll send the video round soon.

I actually was unsure about using clojure vectors for the project (at the cost of some data abstraction), I like that you added make-vec but kept using the destructuring (if you were to swap out vecs for for instance more efficient tuples you would have to do at least that). Have a look if you can swap out your make-vec for one that returns a tuple https://github.com/ztellman/clj-tuple and see if everything still works.

Have a look at the interpreter project, there is a video for that coming soon too.


Reply to this email directly or view it on GitHub.

@thattommyhall
Copy link
Member

@gw666

Yes to a clean docstring PR, helps with understanding.

I think the 'see if you can easily migrate to clj-tuple' is an interesting extension, so dont want to do it already (you need to change the bits where you return a value so still need to do a make-vec function, rather than returning a vec)

(defn add-vec [[x1 y1] [x2 y2]]
  [(+ x1 x2) (+ y1 y2)])

@thattommyhall
Copy link
Member

Interesting discussion with @shterrett in the room for the blackjack project, exactly the same tension between using the abstraction given in Clojure's defrecord and/or destructuring vs the create set/get pattern advocated in the book

https://gitter.im/SICPDistilled/blackjack

@thattommyhall
Copy link
Member

@gw666 If you want another fun bit of abstraction/composition, check this out https://www.youtube.com/watch?v=Mfsnlbd-4xQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants