The Cunning Coder Blog

Tag: programming

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...

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...

The Coming Week and an Itch

by claym on Feb.15, 2009, under Computers and Programming, Life, Teaching English

This week is looking to be quite brutal in terms of school visits.  Usually I have at least one down day in the week to allow myself to prepare for the coming classes, but this week is looking like school visits every day.  Given which schools they are, however, I’m hoping it will be easier than it sounds.  If nothing else, it’ll make the week go by very quickly with how busy I am.

I’ve had the itch to do some software development, but finding the time and an idea for a project has really been dauntig to me.  When I first arrived in Wakkanai, I wanted to make a web app to assist my work, but I found that it wouldn’t have gone over super well with some of my teachers so I stopped development.  Now I just want to write something, anything.  I’m at the point where I’m ready start writing throw away projects just because, hey, it’s something.

1 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...