Saturday, December 31, 2005

Inventory Tracking Refrigerator


Tracking inventory of groceries in the house and making weekly shopping lists is not a suitable task for a human being. Sure, one can do it, but it's repetitive, boring and inefficient. I want my fridge to do it for me.




If my fridge had a barcode scanner and a touchscreen, I could scan items as I use them or restock them. The fridge could keep track of what I have, what I use, how quickly I use certain items, etc.




When it comes time to make my grocery list, the fridge should be able to tell me what I've run out of by generating a shopping list. I could then download that shopping list into SplashShopper on my Palm Pilot, add any atypical items and go shopping.

Tuesday, December 20, 2005

Guards in Perl


As is trendy for Perl hackers these days, I've been learning the functional programming language Haskell. When learning Standard ML in college it impressed me with its brevity and new view on programming. However, the course completed with nary a practical application and I left thinking that it was just a research language. A few years later, I tried my hand at Scheme while attempting to customize some reports in GnoTime. I quit after failing to get the templates generating the content I wanted. Now that I've seen some useful applications written in Haskell, I decided to give functional programming another shot.




I'm using Simon Thompson's Haskell: The Craft of Functional Programming as my text. I'm only through the first three chapters, but so far it has clearly explained the concepts and provided practical examples and exercises.




As I worked through some of the exercises with guards, I realized that I had been doing this same thing in Perl for a long time. Haskell's syntax is cleaner with less repetition, but the concept is the same. It's quite obvious, but here are three sample functions which demonstrate guards in Perl and a sample in Haskell for comparison. The function compares two integers and returns -1 if the first is less than the second, 1 if the first is greater than the second and 0 otherwise. Ignore the fact that Perl's <=> operator does this job already.



Haskell



compare :: Int -> Int -> Int
compare a b
| a > b = 1
| a == b = 0
| otherwise = -1


Perl 5



sub compare {
my ($a, $b) = @_;
return 1 if $a > $b;
return 0 if $a == $b;
return -1;
}


Perl 6



sub compare(Int $a, Int $b) returns Int {
return 1 if $a > $b;
return 0 if $a == $b;
return -1;
}

Friday, December 09, 2005

PDA stylus sensor


I've had a Palm Tungsten T for about two and a half years. I generally adapt myself to the quirks of particular hardware, but the steps to open the Tungsten, getting it ready for input, still annoy me.




  1. Remove the screen cover

  2. Slide the button pad downwards (or push the power button)

  3. Depress the stylus so that it will pop out

  4. Extract the stylus




Sometimes I can get the spring in the stylus to pop the stylus out of the slot. That eliminates one step, but it's still too many. When I can't get the stylus to jump for me, the extra extraction step becomes that much more annoying. I originally liked the slide-out button pad because it made the device more compact. Now I would trade the compact size for one less step when opening the device. I think that the proper solution is to add sensors to the Palm.




One approach is to put a sensor in the stylus well so that the Palm can determine when I have removed the stylus. That reduces the steps to




  1. Remove screen cover

  2. Remove stylus




Another approach is to attach a sensor to the screen cover. That reduces the open operation to the same steps as with a stylus sensor. Or, if I'm doing some quick finger tapping, there's only one step.




For my next PDA purchase, I'm going to put more weight on the steps to open factor. As an aside, I think PDAs should have many more built in sensors. Some examples:




  • thermometer

  • barometer

  • accelerometer

  • GPS




Use cases for those sensors will have to wait for another blog post.