When I hear Bash/Perl/Ruby/Java/C/ML/Erlang/Smalltalk/etc I know what I'm dealing with, I know what they are good for and when to use them, but what about List? Don't get me wrong, I like Lisp, I just don't see for what I could use it.
So, what are you doing with Lisp and why exactly Lisp over any other PL?
Name:
Anonymous2007-07-26 10:47 ID:AYkKzNh1
Another good one is callbacks. I.e. you have some library and you get given an object, and you add callbacks to it that get called on certain events.
e.g...
void on_click(foo *foo_object)
{
//...
}
//...
int main()
{
foo my_foo;
my_foo.add_callback(ON_CLICK, on_click);
// and moar callbacks
my_foo.add_callback(ON_PRESS, on_press);
my_foo.add_callback(ON_FOCUS, on_focus);
my_foo.add_callback(ON_KEYDOWN, on_keydown);
}
K, you can see where I'm going with this, right?
You get to a point where there's loads of my_foo.add_callback. And that's annoying.
When you syntactically define a function, it's made available as a function. Why can't I do this for callbacks? WHERE'S THE ABSTRACTION?
Well, in Lisp you can do, and I have done and do all the time:
(define-callback (onclick-ev foo)
on-click my-foo
(display "ZOMG YOU CLICKED!"))
Here's the same example with comments illustrating what it means:
;; to define called onclick-ev
;; a callback with parameter foo
(define-callback (onclick-ev foo)
on-click ;; for the 'on-click' event
my-foo ;; add it to the my-foo object
(display "ZOMG YOU CLICKED!"))
irc library
Here's what using IRC library looks like, as a good example: