Articles, Blog

racket definitions video 1/4 — domesticate values

December 3, 2019


We’re used to links in a web page
standing for other pages. We’re also used to items in a pull-down menu standing for actions that we’re choosing. Let’s look at how we can set identifiers
in a program to stand for values. Basically, we’re going to tame, or
domesticate, those values. Let’s make jumbo stand for… well this elephant. Now we don’t have to catch it anymore,
it comes when it’s called. Let’s make lucky stand for a number that
I don’t want to have to remember all the time. Let’s define words to stand for a
whole bunch of words that would be way too tedious to type time, and time, and time, and time again. Now, whenever I type lucky or words or jumbo, they simply evaluate to the values they stand for. Click run or perhaps type Control-T and each of
them evaluates inside of the program. See? Lucky evaluated to that lucky number. words evaluated to all those words jumbo evaluated to that exuberant elephant. There’s another way of looking at this
evaluation process, and we can do this in Intermediate Student with Lambda language. Click the
stepper. The green is before, the purple is after: each
step changes green to purple. lucky becomes that number; words evaluates to all those words;
jumbo to that elephant. Let’s try one extra layer of steps. I’ll define new identifiers to stand for something in terms of the
already defined identifiers. So, in case I forget
what I called my lucky number, I defined a new identifier. Or I can take the reciprocal of my lucky number without having to
remember it. Or I can define something to stand for a smaller
but still exuberant elephant. With the words, I might just be
interested in the first… let’s say 20 characters of all those
words. So I define a new identifier to
stand for that. Now whenever I type those identifiers they evaluate to new values. And the stepper turns out to be a good
way to learn about it how these evaluation steps take place. Just
highlight the parts that we’re interested in
stepping through. Now, when I click the stepper… opening up a little bigger, I can say
jump to the beginning of the selected area. Now the green lucky, of course, evaluates
to its new value which is that number. So, if I step I see that I have to evaluate a new lucky to that number, and then one over that number. jumbo evaluates to that elephant, So, if i step, it looks like I have to evaluate that
expression, which is a smaller elephant. That’s what small-jumbo stands for. opening-words — we first evaluate what
words itself is, and now we evaluate the substring expression, and it’s just the first
20 characters. So now we see how small-jumbo, inverse-lucky and opening-words evaluate. Now, how about a third layer
of steppings… is that gonna make things horribly complicated? Let’s define an identifier mirror-small-jumbo to be our small-jumbo, that exuberant elephant
except it’s being exuberant in the opposite direction. So again, when I type mirror-small-jumbo
it’s going to evaluate to a new value. Let’s highlight it… Click on the stepper… and again we’re gonna save ourself time by jumping to the beginning of the selected
area. So, small-jumbo should evaluate
to that small elephant. But… I’m gonna need to click first… to make it take that step. And now flip-horizontal of that small elephant, that tells us the
final value of mirror-small-jumbo. So, that’s how these defined identifiers work, and if I click Run they’ll all evaluate to their values.

No Comments

Leave a Reply