Archive for February, 2006

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)

(define trotter? taking-gre?)

‘nough said. I’ve got the GRE today, so don’t expect to see any witty computer posts.

Still, I’ll leave you with one snippet of life-code to tide you over:

Read the rest of this entry »

Comments

Higher Order Procedures

Higher order procedures are something that I will talk about a lot here, so let’s get straight what they are. Higher order procedures are procedures that take a procedure as an argument or have a procedure as the return value. That being said, read more to see them in action.

Read the rest of this entry »

Comments

Ruby Tip: Eliminate Chains of Or’s

Do you have code that looks like this?

if ((var == 'foo) or (var == 'bar') or (var == 'other') or (var == 'stuff'))
  do things
end

If your answer is yes, then try this little trick to make your code more legible:

if ['foo', 'bar', 'other', 'stuff'].include?(var)
  do things
end

As an added bonus, you can use ‘%w’ to make the array creation cleaner:

%w|foo bar other stuff|

I love how Ruby makes my code squeeky clean.

Comments

Programming Languages

Is there a single best language to use for all programming tasks? I’m not sure. However, I am pretty sure that there are some languages that are unfit for almost any task. Here’s my take on the languages that I have seriously used.

  • Visual Basic – Great mocking up the UI of a new program. Terrible for everything else.
  • Java – Pretty cool, but too many rules.
  • Ruby – Ahh… very nice. I like the dynamic nature. I also like the ease with which I can throw around procedures.
  • Lisp – Sad to say, but I really haven’t studied this one enough. What I have studied, however, I am in love with. I’ve been following Abelson and Sussman and have thoroughly enjoyed everything I’ve learned. Raymond is right, learning lisp really does make you a better programmer.

So yes, that’s my brief summary of the languages I know. I’ll get more in depth later on why I like Ruby and Lisp so much. For now, just realize that you’ll be seeing a lot of Lisp and Ruby around these parts.

Comments

life-code: To-Do List

To give you an idea as to what life-coding is all about, have a look at the code for how to complete to-do list:

define do-task-list
  for item in task-list
    perform item
  loop
end

Though it says nothing about how to make task-lists or how to perform the action, it does provide a concrete definition of how to execute a to-do list. Over time, you’ll see these bits of code start to get integrated into a definitive system.

Comments

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