Articles, Blog

racket values video 3.9/4 — decompose values

December 13, 2019

Here’s doctor racket. The language is set to Intermediate
Student with Lambda, and we’re going to require
picturing-programs so that we can work with images a bit,
among other things. control-T reads in the definitions…
control-D gives us real estate just for interactions… Here’s an image to mess around with. First, let’s figure out how many pixels wide this image is… We get at that using image-width. So, there’s 269 glowing dots
across here. The image height… it’s a little bit less. Here’s how we get just some of the image. We can crop a hundred pixels off the top… Or, we can crop a hundred pixels off the left. We can also crop numbers. e is a number
mathematicians like, it’s approximately two point seven something… that hash sign means, #i means it’s
an inexact number. We can convert it into an exact number, so that
we know it’s not an approximation, using inexact->exact. We can also round it down to the nearest
integer… The floor of e… And again, we can make that quantity
exact, if we need it to be exact. Recall that We can view a decimal as an improper fraction. However, pointing and clicking with a
mouse isn’t always convenient. We can get at the numerator
int denominator separately using… function numerator and function denominator. For the skeptical among you, we can
reconstitute numerator and denominator… and get two -2.55 back. We can pull pieces out of strings of
characters. So, I’m using the characters that are numerals
here, to make it clear what pieces I’m pulling
out. I’m pulling out of piece 3 to 6. So, that’s from position 3 (counting
from zero), to just before position 6. Same thing works with other characters,
so here’s a… some alphabetic characters I’m going to pull out position 3 to position 6… and it’s the corresponding characters of
this string.

No Comments

Leave a Reply