...nothing is left to guesswork.

Recent Work:
An investigation of connected exceptive constructions and scalarity
Except-phrases and "only" presentation notes
Donkey Anaphora and Variable-Free Semantics

Monday, April 03, 2006

I spent most of this weekend tinkering about with Objective-C. We've gotten the parser functioning pretty well and have even made a primitive front-end for it in Cocoa. The UI helper in Cocoa is really sweet...it's so easy, it reminds me of those 'make your own interactive computer program' programs that we used in middle school. Two really strange problems arose yesterday. First, we were trying to get the text from the NSTextView (which was linked to the text field in our front-end) to store temporarily in a tempfile to feed to the parser. And hooray! We seemed to have found the perfect C function to do this: fmemopen. Except, as we found out after 15 minutes of trying to figure out why it wouldn't recognize fmemopen, we didn't have this or open_mem or anything useful available to us over in BSD-land. So we searched and searched and searched for something; thanks to the internet, it only took us the afternoon. There were some other problems; thinking we had to declare a variable that Yacc already provided; and! (my favorite) forgetting to mention EOF anywhere in the program. But once those things were fixed, the program ran nicely and spat out cute abstract parse trees to the run log.

The other strange problem came while we were implementing the evaluation methods so that we could run [prog eval] and have, say, add1(0) return 1 instead of ADD1 ( NUMBER ) . The implementation went fairly smoothly and straightforwardly; there was one SNAFU where we couldn't inherit any of NSMutableArray's methods in the subclass of it that we created, but we just hacked through that problem by creating the array in the subclass and then creating our own method for adding an object. So we worked thought the errors that the compiler brought up (most of them, perhaps all, were silly things like forgetting to import a header file). Any then we finally had built the program and it ran! Except that add1(0) returned...4! 4! That's right, 4! So we ran the debugger and ran the debugger and ran the debugger...and we couldn't figure out why at one point of the program's run, it had taken the value 0...but then when it had the add1 function applied to it, it became 4! It was maddening. We tried everything, until finally we noticed that the program worked as it should when we type-casted the value as int. And then add1(0) returned 1. Hooray!

One other thing I should mention. I was at first terribly enthusiastic about Objective-C when I first started tinkering with it last weekend. It doesn't feel as clunky and idiosyncratic as C++ (it's dynamic-ness is really nice, too). But then, working with it extensively this weekend, I saw that Objective-C really is still an imperative language and an object-oriented one. Actually, I think OOPLs are pretty neat, and I am excited to have some time to look at OCAML this summer to see a more functional way of doing OOP. And Objective-C has fantastic advantages and is usually fun to work with. But some of the more complicated methods were such a pain in the ass to implement, and I see all over again why functional programming is such a wonder. From my incredibly CS ignorant point of view, functional programming languages seem much easier than imperative ones. And I don't mean that they're better, I just mean that one needs to be so precise and meticulous with a language like C...in ways that Scheme never requires you to be. In Scheme, you need only to think about what the most efficient levels of abstraction are and which algorithm will serve your function best. The worst that can happen in a Scheme program is an endless loop. C has all sorts of goofy errors waiting for you to make them. Functional programming is all about abstract ideas and what must be a Platonic universe, where imperative programming seems to really involve the programmer with the machine. Imperative programming is more of a challenge, and I suppose that's why it intrigues me.


Post a Comment

Links to this post:

Create a Link

<< Home