The Cunning Coder Blog

Reviewing Good Old Currying

by claym on Jul.07, 2010, under Computers and Programming

So, having been facing the idea of going back to America within the next month I decided to get back on top of reviewing all those fun programming concepts that I haven’t used in far too long.  Among them was lambda calculus and function currying.  Since I figure the best way to review things about this are to actually write them all out, here we are.

So, let’s start with the simple part, what is function currying?  Well, function currying is a way of turning functions that take multiple arguments into a series of functions that only take one argument.  In functional programming, this is almost always achieved via lambda calculus and anonymous functions.  Let’s take a look at an ultra simple example.

add x y = x + y

It doesn’t get much simpler than that right? But this add function actually is taking 2 arguments, so what would it look like when curried?

add x y
add x = (\y -> x + y)
(\y -> x + y) y = x + y

Not clear? Well let’s look at it a bit more closely. Since we’re currying we have to make sure that functions only take one argument, so we’re going to evaluate add x on its own. It may seem silly, because after all, you can’t really add one number on its own. This is true, but we’re not actually hellbent on returning a value. Instead, we’re going to return an anonymous function that contains our x value and then pass in y. Still not clear? It will be momentarily.

add 1 2
add 1 = \y -> 1 + y
(\y -> 1 + y) 2 = 1 + 2

So, add 1 returned a function we called lambda y that took one argument and added 1 to it. We then passed that new function our y argument (2) into this new anonymous lambda function and ended up with our answer, 3.

Isn’t functional programming and currying fun?

2 Comments :, , , , more...

Fun with E-mail

by claym on Mar.16, 2010, under Computers and Programming

So I got into work yesterday and I realize I haven’t gotten a fax related to a lesson I have this week.  ”No worries,” I think to myself, “This teacher usually e-mails me plans so I best take a peek there.”  I go to open Outlook and I’m greeted by a rather unpleasant sight, “This program has stopped responding…”  Now, I’m not concerned yet.  Programs sometimes have hiccups, and this could just be one of those little oddities.

I go to open Outlook again, it instantly crashes.  Now I’m suspicious.  This isn’t normal behavior.  I start Google-ing around and find a myriad different things to try.  Start Outlook in Safe Mode, crash.  Try a new profile, crash.  Try a new Windows account, crash.  Run the Office Diagnostic Tool, no problems found.  With every option I explored I was no closer to finding a working solution.  Other mail clients worked fine, it was just Outlook that had the problem.  The only clue I gleaned from this search was that if I used a profile that had no e-mail accounts it worked, if I added my accounts back in the application died.  It was something related to fetching mail.

For some people, they’d probably just write this off and say “Well, don’t use Outlook.”  That’s a completely valid option, but now I have a mystery, and one that I want to solve if for no other reason than morbid curiosity.  When I got home after work I started thinking about it more.  Out of nowhere, I had an idea.  When I was playing with Outlook profiles I had noted that with no accounts, it wouldn’t crash, but with them it would.  Since there are 2 accounts in the profile, what would happen if I just added one back?

I plug in my cunningcoder.org details in the profile, crashed.  Not looking up, but I decide to see what would happen if just my old OSL account were used…  No crash.  Something about my cunningcoder.org e-mail was crashing Outlook but no other mail client.

I hop onto the control panel for my hosting and I notice they updated Dovecot while I was asleep.  Something must have gone wrong with the migration on my account.  I remote into the box and just as an experiment, I move the Mail/ folder to Mail.bak and then try to access my cunningcoder.org e-mail via Outlook.  No crash.  I copy my messages from the back-up back into the new Mail directory, no crash and all my messages are in tact.

I did lose the folder structure I had set up, but all my messages are still there and I have Outlook working again.  Definitely a weird ride, but at least I got all the way to the end.

Leave a Comment :, , , , more...

Continuing to Fight with Ichitaro

by claym on Mar.09, 2010, under Computers and Programming

Continuing along with my last post about trying to get Ichitaro to work I was really happy when AppLocale allowed me to use the application. But I noticed a new annoyance. Though I could manually start the application just fine, this doesn’t make sense for a document viewer. Most of the time you want to just double click the document and have it open, you don’t want to open the viewer, File -> Open and browse to the file you want to view. Though AppLocale will allow you create a desktop shortcut to open the program, it can ONLY be called on programs. I needed to find a way to make it behave slightly more normally.

After searching through the registry for a while I found the key responsible for the open command used for TaroView Documents. I’ll copy paste the relevant key below. Note, this requires that you have AppLocale and the Ichitaro Viewer installed in their default locations and this key was exported on Windows 7 professional.  Modifying the registry is potentially dangerous and I take no responsibility for the results of choosing to modify your own registry.  It will still nag you telling you that this is a “temporary” solution, but you can find a patched version of AppLoc.exe if you really want to get rid of that.

Below is the exported key that solved my problems.  It  will open anything that is registered as a TaroViewDocument to open through the AppLocale’d version instead of the default one.  I hope this helps someone else who was as frustrated as I was:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\TaroViewDocumentFile\Shell\Open\command]@="\"C:\\Windows\\AppPatch\\AppLoc.exe\" \"C:\\Program Files\\JustSystems\\TaroView\\TAROVIEW.EXE\" \"%1\" \"/L0411\" "
Leave a Comment :, , , , , , , , more...

The Fun of Ichitaro on Windows

by claym on Mar.08, 2010, under Computers and Programming

Ichitaro doesn’t like running on English Windows. I’m sure this is the same for virtually every other non-Japanese language setting but I finally had enough. I wanted to be finally be able to use MY computer to open the Ichitaro files I sometimes received from teachers and I was determined to get it to work.

I found that if I switched the non-Unicode language setting in Windows to Japanese it would work. Yay! BUT… This is a system wide change. No any non-Unicode program I have things it should be Japanese and that also messes with the display of certain things like the command prompt (which will use a Yen sign instead of a \). I could change it back when I was done, but each time you alter this system setting it requires a reboot. There must be a better way, I thought.

It turns out there IS a better way, but it’s still not perfect. There’s a program called Microsoft AppLocale (http://www.microsoft.com/globaldev/tools/apploc.mspx). This application will let you point it to an EXE and pick the language it should run it. It even will let you make a shortcut to always run the application through AppLocale. No reboots, not side effects. The only annoyance is that it doesn’t install properly under Windows 7 (You need to tell it to use backwards compatibility) and it will prompt you even when using a shortcut to remind you that AppLocale is just a “temporary solution”. Hopefully it’s right, and Microsoft will release a more robust system level update that will allow it to handle such situations on its own, or software manufacturers will start releasing software in Unicode.

Leave a Comment :, , , , , more...

Working on Open Source

by claym on Apr.17, 2009, under Computers and Programming

I’ve recently become involved in a friend’s open source software project revolving around dictionaries and orthography.  The project has been dubbed glot (http://launchpad.net/glot).  It’s a hobby project, so it may or may not be updated super frequently (it really depends on how much free time the developer’s all have).

It’s going to be my first time actually using Python on a real project, so we’ll have to see how that goes.  So far we’ve been just getting used to Launchpad, evaluating technologies for incorporation, and reading up on standards to support.  There is some code in the repositories, but it’s really just a base that the real project is going to spring forth from.  I’m just happy to be doing something computer sciency again.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...