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?
Lisp dialects are general purpose and multi-paradigm.
Lisp is good for writing mini-languages for specific problem domains:
The LOOP macro: (loop for x across "hi" collect x) => (#\h #\i)
qsort (defun qsort (list)
(when list
(loop with (x . xs) = list
for y in xs
when (< y x) collect y into lt
else collect y into gte
finally (return (append (qsort lt) (list x) (qsort gte))))))
In a general sense, what I am doing is mapping the values of a list to some variables. But I really don't want to manually type out that for every single variable, do I?
So I can write a macro let-from-list that does this for me, so the code then looks more like this:
(define (print-customer-info customer-info)
(let-from-list (customer-info) (name age street sex)
(display (string-append "Name: " name "\n"
"Age: " (number->string age) "\n"
"Street: " street "\n"
"Sex: " sex "\n"))))
Which is a lot nicer. Of course, there's already a simple way to do this in Scheme. But the point is, if it wasn't built-in, I could add it myself.
Name:
Anonymous2007-07-26 10:33 ID:AYkKzNh1
More examples
I'm supposing you EXPERT PROGRAMMERS have used the Win32 API before.
Here's something that pisses me off. Pairs of functions that must be called as such. I.e. one that allocates, and one that deallocates.
(Sorry if there are any errors in the code, although there shouldn't be because I kick ass.)
For some of you, that may not seem too bad. But I'm guessing you've at least written on big graphical app and it starts to get messy the more objects you create, use, free and besides from being difficult to follow, it looks like shit and takes ages to code.
I mean, it certainly looks better. It's structured. You can see clearly how everything happens. But it starts to span across the screen. And I'm still sick of typing EndFoo, DeleteFoo, SelectFoo, CloseFoo, etc.
In C++, another "solution" (fucking horrible hack) is to rely on lexical scoping (see: wikipedia- RAII):
Using templates, one can do something when the objects are created, and then automatically do the EndFoo, DeleteFoo, etc. when it is destroyed.
In Lisp, using macros, one can simply have:
(begin-paint hwnd (hdc ps)
(with-new-brush (rgb 255 255 255)
(select-brush hdc
;; do painting here
)))
It's important to remember that we are using syntactic abstractions as well as semantic abstractions. In C, well, forget any of that. In C++, welcome to object and template hell. In Lisp, welcome to Satori.
I'm supposing you EXPERT PROGRAMMERS have used the Win32 API before. In Lisp,
(NULL (NULL (NULL (NULL (NULL (NULL 0))))))
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:
>>19 Lisp is good for writing mini-languages for specific problem domains
Instead of using real laguages suited for these problems. See >>6
>>20 Lisp is also excellent for abstraction and good at eradicating code duplication
Like any other language
(But the point is, if it wasn't built-in, I could add it myself.) <- lol right, like in no other language
>>24 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?
Is that really so much of a problem? You can't do it in c, yes, c is old, but you can in many other languages (see perl).
>>27 Instead of using real laguages suited for these problems.
Wait, there's a language specifically for looping and iteration?
Like any other language
No. C is not, C++ is not. Many are not.
WinAPI, not even reading
Yes, disregard the meaning behind the explanation because of something trivial like the library it uses.
Is that really so much of a problem?
Not that much. It was demonstrating one of the things you can do with macros and syntactic abstraction.
You can't do it in c, yes, c is old, but you can in many other languages (see perl).
Can't do what, good syntactic abstraction? Or good semantic abstraction? I agree on both points, and that of a lot of other languages.
...
You seem to misunderstand. But hell, I don't care to try to convince anyone if they are uninterested.
Name:
Anonymous2007-07-26 15:24 ID:y3sQDGWD
>>30 Wait, there's a language specifically for looping and iteration? Not that much. It was demonstrating one of the things you can do with macros and syntactic abstraction.
I think i understand why i will never understand you. In my eyes language is nothing but a tool to create programs. In your eyes, language itself is self-sufficient; who cares about actual programs when you have such AWESOME syntactic abstraction and semantic abstraction? Enjoy your Satori, also see >>6
Name:
Anonymous2007-07-26 15:53 ID:fbaS5hKm
>>31
no, you get it wrong. Lisp has convenient abstractions which are useful but not required to get working programs, the same way subroutines and recursion are useful but not required to write anything. Instead of using real laguages suited for these problems.
And if you don't have those languages, you have to either write an interpreter or deal with copypasta cause your language lacks abstractions.
(let me here state that some languages which are not lisp don't lack such abstractions, i.e. nemerle; btw look at http://nemerle.org/MacroUse if you want good examples)
Name:
Anonymous2007-07-26 16:07 ID:fbaS5hKm
>>21
can't you do that with just lambdas, like say, in smalltalk?
>But hell, I don't care to try to convince anyone if they are uninterested
I'm interested. I saved your examples. I didn't save the other guy's post because he didn't say anything useful. He may be right, but he didn't prove it.
Name:
Anonymous2007-07-26 23:40 ID:y3sQDGWD
>>32
WHAT ARE THE USES
CAN YOU TELL ME ALREADY
NOT ``I FAP TO ABSTRACTION``, BUT PRACTICAL USES OF LISP
Name:
Anonymous2007-07-27 0:43 ID:ZGFrZD/u
>>19 >>20 >>23 FUCKING GET OUT AND TAKE YOUR SHIT LISP EXAMPLES WITH YOU
>>37
There' no shame in being illiterate. You might even get The President's wife to teach you how to read. Keep trying and don't give up.
Oops, you can't understand this post can you?
>>21 You can't comprehend how to write a wrapper function.
void cpaint(PAINTSTRUCT ps){
HDC hdc = BeginPaint(hwnd, &ps);
HBRUSH fooBrush = CreateSolidBrush(RGB(255, 255, 255));
HOBJECT oldBrush = SelectObject(hdc, fooBrush);
SelectObject(oldBrush);
DeleteObject(foobrush);
EndPaint(hwnd, &ps);}
______________________________________________ http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
I prefer to be true to myself, even at the hazard of incurring the ridicule of others, rather than to be false, and to incur my own abhorrence.