Saturday, September 18, 2010

Daily, 2010/09/17: semantic play!

Announcement items:
  • Last A#1 thoughts: Haven't read Ch 3?  Do so, EVEN NOW!
  • A#2: out later today, due in 1 to 1.5 weeks
  • "TestFest" for A#2: out later today
  • Advice for A#2: work from the textbook!
High-level comment:

I got so swept away with the fun yesterday that I forgot to actually do the announcements.  For what it's worth, they're above.

What had me swept away?  This was our first chance to do some really exciting exploration of semantics!  (More on that below.)  In a few short lines of code, we repeatedly and radically altered the semantics of our language.  The code we came up with encapsulates very succinctly what it means to "get identifier binding right". 


Details:


We had a sense of how our with construct should work, and used a bunch of test cases to clarify that sense. 

However, as we actually wrote the code, we got to see how small changes in the code could alter that semantics, usually by "breaking" things we wanted! 

For example, when we corrected our code to perform substitution inside of with expressions that didn't rebind the identifier we were working on (e.g., a with on y when we're substituting for x), this fixed a bunch of test cases, but not {with {x 1} {with {x {+ x 1}} x}}.  We had to go back and substitute inside of named expressions (no matter what the newly bound identifier) to fix that test case.

When we were done, we had a pretty clear sense, both intuitively and in code, of how substitution defines the semantics of our language.  We'll rely on that sense to "keep us honest" as we work on optimizing away the inefficiency we saw in {with {x 1} {with {y x} {with {z y} z}}}

At the very end, we even made a change that (mostly, at least) didn't "break" the semantics: lazy versus eager evaluation of the named expressions in a with.  We saw how this can radically alter performance, which is somewhat interesting now and will get much more so soon. 

However, the eager-to-lazy change did alter the semantics of this expression:

{with {x y} {with {y 1} x}}

Why?  Which semantics is correct, or are they both right?  What does your intuition of how substitution should work tell you?  Do we need to fix one of these evaluation schemes (eager or lazy) to match the semantics of substitution?  If so, how?

Cheers,

Steve

No comments:

Post a Comment