Warning: Undefined array key "activated" in /homepages/45/d270899679/htdocs/wp/wp-content/themes/compositio-wordpress-theme-heb/compositio/functions.php on line 102

Warning: Undefined array key "preview" in /homepages/45/d270899679/htdocs/wp/wp-content/themes/compositio-wordpress-theme-heb/compositio/functions.php on line 102
 Miscellaneous Debris – Archive

בקטגוריות: Uncategorized

20 Feb 2004

Note to all CS/programming folk:
I’m looking for good reading material on closure functions and other concepts of non-OO stateful functions.
Any good links on where to read up on that?

11 תגובות על



22 בFebruary, 2004 בשעה 01:40

For intro to functional programming

Read SICP. It covers programming from all angles, but naturally gives special consideration to functional programming and closures.



22 בFebruary, 2004 בשעה 02:13

man perlref… if you’re into perl.



22 בFebruary, 2004 בשעה 07:34

I’m not, so I’d rather not go there – most of the info I found while googling was perl-oriented. Since I am unused to perl syntax, which tends towards brevity (if not outright obfuscation), I’d rather find some clearer explanations somewhere. 🙂



22 בFebruary, 2004 בשעה 08:14

Can’t blame you: Perl syntax is undoubtedly confusing at the beginning, and closures are confusing.

Let’s ask it this way: where will you be using them? Are you interested just because you’ve heard they’re useful? Do you just want to learn what they are?

GLib (part of gtk, http://www.gtk.org) provides a closure mechanism in c (and thus for many languages that have glib bindings, including c++ which I mention because I think you know well). But unfortunately these closures, because they’re not part of the language, are clunky to set up and use.

Since they are used there extensively, you might want to look into LISP and similar languages (Scheme etc.). Or you could be bold and try OCaml; here’s a pretty good tutorial. Learning OCaml looks to me like a very good investment: although you are not likely to get a job programming it, if you manage the learning curve you’ll probably be a better programmer for it.



22 בFebruary, 2004 בשעה 08:17

My interest in this is basically academic. I heard what they do, wanted to know more. Pure interest.

I’m reading the book Folger linked to, since I am somewhat familiar with Scheme syntax and it is – parenthetical verbosity aside – quite legible.

I’ll check out the OCaml tutorial too, just to see what it is.



22 בFebruary, 2004 בשעה 08:33

That book is a classic. I never knew it was online so I should thank Ori for the link!

OCamle’s functional programming bits won’t be too mysterious to you if you don’t find Scheme odd.



22 בFebruary, 2004 בשעה 09:01

Not too mysterious, but it does seem needlessly over-complicated. The use of different syntax for similar functions can be really confusing, or maybe it’s just that I’m used to how C-derivatives look.
And still, the quite arbitrary rules for ‘;’ and ‘;;’, similar constructs such as tuples, unions, enums or lists each having their own unique delimiter, and usually a different one for definition and for use (|, *, :: and so on) – all these seem quite, well, pointless.



22 בFebruary, 2004 בשעה 08:18

Might I add that OCaml is no toy language! It is hard to write in (just getting a program past the type-checking compiler is hard) but programs fly when they’re ready.



22 בFebruary, 2004 בשעה 12:28

Dynamic Languages

Well, I think this year I actually found myself using closures in Perl, when previously I was getting all glassy-eyed reading about them.

Now, if you don’t like Perl, there are quite a few other dynamic languages that emulate this feature. The obvious one is Javascript. Here’s someone explaining how he implemented a closure in Javascript that’s very similar to what I did in Perl:


He also has a good one-line description of closures, “basically, anonymous inner functions, which retain the surrounding context”. If you have a function that takes a callback/function reference as an argument (like, say, a sort function, or in my case, a function that runs an arbitrary database query and executes my function on each row), you can write the function inline, using variables that are in the calling scope.

It’s basically this sort of useful magic that lets you easily skip over what seem like insurmountable barriers. Or just saves you typing and passing variables around.



22 בFebruary, 2004 בשעה 14:51

Re: Dynamic Languages

That’s basically what I figured. What got me started about this whole mess is reading about an upcoming feature in C# offering anonymous functions, and someone mentioning that this will allow using closures. Naturally, I decided to find out what the hell those were. 🙂

Something I stumbled on but can not now find – a concept similar to closures, functions that yield execution rather than returning, and resume from the same spot once they are called again.



22 בFebruary, 2004 בשעה 23:03

Introduction to Anonymous Methods and Higher-Order Procedures in C#

For official details on closures in the next release of C#, see Introduction to Anonymous Methods and Higher-Order Procedures in C# in msdn academic alliance (sounds like an interesting web site).

In Scheme, you only have lexical closure. Called functions always extend the current environment (the list of variables available in the current scope). I always considered that to be the perfect way to program. I assumed C-derivatives didn’t have this feature for historical and technical reasons, not because it wasn’t warranted.

Maybe one day we’ll get a real functional language from Microsoft. 🙂

טופס תגובות

Warning: Undefined variable $user_ID in /homepages/45/d270899679/htdocs/wp/wp-content/themes/compositio-wordpress-theme-heb/compositio/comments.php on line 59

פעם היה לי לייבג'ורנל. עכשיו הוא כאן, מגובה.