Archive for All

How to be Smart

So after reading this blog for a little while, you’re probably wondering “How can I be as smart as this Trotter fella?” Well, let me clue you in on the secret of my skillz. I’m reading Structure and Interpretation of Computer Programs. It may be old, but wisdom never spoils. Read it and get smart.

Comments (3)

Synonyms

Time to play with synonyms. Let me know which versions you like better.

result = 0
0.upto(arr.length) do |i|
  result += arr[i]
end

or

arr.inject{|x,y| x + y}

How about this one?

0.upto(arr.length) do |i|
  arr[i] = 10+arr[i]
end

or

arr.map! {|x| 10 + x}

Higher-order procedures are h0t!

Comments (3)

Oh websense, let me count the ways I hate thee.

So, I’m sure you’re sitting there wondering what kind of bum doesn’t update his blog with more super cool posts about higher order procedures like he said he would. Well, it’s not my fault, honest. I wanted to post cool little blurbs about how fun it can be to map array elements, but big bad Websense said no. Read a little bit more, and I’ll tell you my proposed solution.

Read the rest of this entry »

Comments (3)

Blocks and Closures in Ruby

So, I’ve finally started doing actual research for this presentation beyond asking, “What do I already know?” First stop on the research train? Blocks and Closures in Ruby over at Artima. It’s an interview with Matz (the creator of Ruby for those of you not in the know) discussing how cool it is that Ruby supports blocks and closures. Read on to get an abrievated version of what goes on in the article.

Read the rest of this entry »

Comments

Speechifying

Remember how I said that we would be seeing a lot more about higher-order procedures on this site? Well, I’m giving a talk on using them in Ruby this coming Tuesday. All of my research will be posted here along with the final presentation. So get ready to read, because there’s going to be a lot of information coming at you.

Comments

Quotation

After spending a little time with scheme’s concept of quotation, I must say that I really enjoy it. What makes quotation very nice is that it allows you to express new language constructs in the syntax of the original language. For instance, (+ x y) and ‘(+ x y) share the same syntax. The only difference is that the quotation in the second case prevents the expression from actually being evaluated.

I can already hear you screaming “Wait! What’s the difference between ‘(+ x y) and “(+ x y)”?!?!” Well my friends, the beauty of quotation is that you can use normal scheme’s normal list manipulation to parse ‘(+ x y). There is no need to go searching through strings to determine what is where. Instead, it’s all just a bunch of car’s and cdr’s.

Comments

Perils of Global Variables

I just spent 20 minutes trying to find an annoying bug in my program. The cause of the bug? I accidently used the variable ‘i’ in a for loop instead of ‘i__’. For now, let’s just accept that I have to use global variables and weird names such as i__. It’s part of the requirements of the current project on which I’m working. Anyway, this is a bug that could occur in any number of situations where global variables are present. So, we need a way to quickly hunt and destroy these bugs.

My proposed solution? For any programming language that you work in, you should have a utility that allows you to quickly identify variables within a certain scope and to see what type of value they might contain. This would have allowed me to select the function I was working on and notice that there was an extra variable ‘i’ that was initialized as global.

I can think of another situation in which this type of tool would be handy. It could be used to add macro writing capabillites (ala lisp) to any desired language. It already has full knowledge of the constructs of the language and the functions and variables that exist. And so long as the macro could be compiled to the desired language, macro functionality would be available. Maybe you’ll see this sort of tool available here in the future.

Comments

GRE

In case you’re wondering, it went well. Now it’s time to get into graduate school.

Comments (3)

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »