andrewducker: (Monkey in charge)
[personal profile] andrewducker
Julie was around for the weekend, although she then vanished off this afternoon to slave over a report. It was very relaxing - and I'm leaving plenty of holes in my schedule to make sure we both get more relaxing time, at least until her work calms down again.

Meantime, I've discovered that C# 3.0 allows you to write code like this:
doggies.ForEach(
    dog => dog.Paws.ForEach(
        paw => paw.Claws.ForEach(
            claw => claw.Clip())));

which is the equivalent of the code from the other day, only even more concise. I don't think it's actually any more readable though. Lambda functions seem to be pretty neat - but I haven't spotted many places I'll be using them so far. Maybe when I've played with them a bit more...

Date: 2008-04-06 11:31 pm (UTC)
From: [identity profile] martling.livejournal.com
Ever used a functional language?

Date: 2008-04-07 01:04 am (UTC)
From: [identity profile] figg.livejournal.com
If the answer is no, you should consider changing it to a yes.

Aside, here is a raytracer written in LINQ (Those C# 3.0 extentions)
http://blogs.msdn.com/lukeh/archive/2007/10/01/taking-linq-to-objects-to-extremes-a-fully-linqified-raytracer.aspx

Date: 2008-04-07 06:24 am (UTC)
From: [identity profile] call-waiting.livejournal.com
If you mean 'changing it to a yes because C# 3.0 has functional features', I'd say that should still be no since C# is 'multi-paradigm' rather than 'functional' and it's possible to use it for years without using a single functional feature or idiom ;)

Date: 2008-04-07 09:22 am (UTC)
From: [identity profile] khbrown.livejournal.com
But is there anything that LISP didn't do better, 40 years ago, other than gain market and mindshare?


Date: 2008-04-07 09:30 am (UTC)
From: [identity profile] khbrown.livejournal.com
Are these examples of fundamental inadequacies in the language itself, or just a reflection of its emerging prior to these technologies?

Presumably you can write anything in any Turning-complete language with a greater or lesser degree of difficulty, depending on what libraries and so forth are available to make the job easier?

Date: 2008-04-07 11:09 am (UTC)
From: [identity profile] drdoug.livejournal.com
I don't think using a functional language for UI code is a good plan anyway - it's the wrong tool for the job. Like trying to use a scalpel to cut down a tree, or a baseball bat to play snooker. You could probably do it if you're careful but you'll get little pleasure from the exercise, and the skills you need to do it are not really the ones that show the tool to its best advantage.

Date: 2008-04-07 11:56 am (UTC)
From: [identity profile] khbrown.livejournal.com
Useful to remember for the next time the LISP does/did X line comes up :-)

Date: 2008-04-07 07:35 pm (UTC)
From: [identity profile] call-waiting.livejournal.com
I think there's a fairly clear consensus is that OO is more or less 'the' way to do GUI programming, as it's fundamentally an object oriented task, and both are quite closely related to the way humans perceive and comprehend their physical environment. In fact, I find it hard to imagine a sensible way of programming GUIs in, say, a pure functional language that didn't involve reinventing OO to a large degree.

A case in point seems to be this 'simple' example of a trivial GTK+ application written in Haskell:

http://www.cse.unsw.edu.au/~chak/haskell/gtk/BoolEd.html

Ow, my aching head.

Date: 2008-04-07 07:24 pm (UTC)
From: [identity profile] martling.livejournal.com
Yes, I've always wanted a language that would let me do some bits procedurally, some functionally, etc.

F# looks potentially interesting.

Date: 2008-04-08 02:21 pm (UTC)
From: [identity profile] martling.livejournal.com
Can you have higher order functions in C#?

That's what really gives you the ability to reduce stuff like the above example to a one-liner along the lines of:

map(clip, descend([paws, claws], doggies))

Date: 2008-04-08 02:51 pm (UTC)
From: [identity profile] martling.livejournal.com
What's a higher order function?

A function that deals with other functions, i.e. takes them as arguments and/or returns them.

The "descend" there is a function that takes a list of functions and then a list of values.

If the values are of type dog, the functions must be of types that chain together from that, e.g. paws is a function of type (dog -> list of paws), claws is (paw -> list of claws), and then the return value of the overall descend will be a list of claws.

The fact the type system is able to understand and enforce things like that is the cool thing.

With function pointers alone, any implementation of descend would have to set in advance the types of the functions it took. Using common forms of reflection, you'd pass in the names of functions as strings and have to do any type checking at runtime.

The descend function would be a line or two in a functional language and implicitly typed, yet formally provable to be typesafe at compile time.

Date: 2008-04-08 03:56 pm (UTC)
From: [identity profile] martling.livejournal.com
More generally, the limitation on function pointers is that they must be pointers to predefined functions. You can't e.g. take a function, compose it with another function, and return the result as a new function. Although C# delegates appear to give you a limited form of closures (where you take a function, bind some but not all of the arguments to given variables or constants, and return the resulting function that now takes fewer arguments).

Date: 2008-04-07 12:33 pm (UTC)
From: [identity profile] johnbobshaun.livejournal.com
Neat. That kind of syntax always brings to mind Ruby to me, although Smalltalk works in much the same way. I *think* this would be the equivalent in Ruby (although I'm a little rusty).

doggies.each do |dog|
dog.Paws.each do |paw|
paw.Claws.each do |claw|
claw.Clip()
end
end
end

Date: 2008-04-07 01:08 pm (UTC)
From: [identity profile] johnbobshaun.livejournal.com
Oops. Forgot that it would kill my formatting.

And, yes, totally.

March 2026

S M T W T F S
1 2 3 4 56 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 29th, 2026 09:54 pm
Powered by Dreamwidth Studios