Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

What is Lisp good for?

Name: Anonymous 2007-07-26 4:56 ID:oSdzs5zo

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: Anonymous 2007-07-26 5:03 ID:Heaven

I just spend all my time telling people how great lisp is and trying to get them to use it

Name: Anonymous 2007-07-26 5:36 ID:oSdzs5zo

>>2
So, tell me, why is Lisp grate and why should I use it over other languages?

Name: Anonymous 2007-07-26 5:56 ID:JXne1+Xv

its good at being suave as fuck

Name: Anonymous 2007-07-26 6:05 ID:Heaven

Learn it and see

Name: Anonymous 2007-07-26 6:09 ID:QjSFpuPi

It's not really useful for anything outside of University research  departments.

Name: Anonymous 2007-07-26 6:29 ID:oSdzs5zo

>>5
See, that's the problem, I learned it, but I don't see for what I can use it. For everything I do there is (in my opinion) a better language.

>>6
That's the feeling I get, but people say the same thing about Erlang, OCaml, Smalltalk and many other useful languages, so I'm not so sure.

Name: Anonymous 2007-07-26 6:51 ID:Heaven

>>7
See, that's the problem, you may have learned it's syntax and logic but you have not learned what Lisp has to teach you.

Name: Anonymous 2007-07-26 7:11 ID:uJC76620

>>1
How do I achieve Satori?
Fixed.

Name: Anonymous 2007-07-26 7:17 ID:Heaven

>>8
Sage for elitist asshole.

Name: Anonymous 2007-07-26 7:57 ID:LoYvap37

Lisp has been replaced by Haskell

Name: Anonymous 2007-07-26 8:40 ID:oobenoag

>>11
Haskell has been replaced by vb.net

Name: Anonymous 2007-07-26 8:41 ID:oobenoag

>>12
my id is awesome

Name: Anonymous 2007-07-26 8:51 ID:qFwfS+x8

lulz

Name: Anonymous 2007-07-26 9:05 ID:Heaven

lol @ "I learned lisp"

You haven't even scratched the surface. stupid newbie

Name: Anonymous 2007-07-26 9:06 ID:QjSFpuPi

>>7

O'Caml and Smalltalk aren't particularly useful either.

However, Erlang most certainly is.

Name: Anonymous 2007-07-26 9:35 ID:Heaven

THIS IS WHY WE DONT SUBMIT /PROG/ TO REDDIT!

Name: Anonymous 2007-07-26 9:39 ID:Heaven

>>16
erlang looks like it'd be a pretty nice language if the syntax didn't suck so bad.

Name: lispexamples !!74aqDvBw0pj8UoD 2007-07-26 10:09 ID:AYkKzNh1

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


cl-who
> (with-html-output-to-string (s)
    (:div :style (conc "padding:"
                       (format nil "~A" (+ 3 2)))
     "foobar"
     (:p "hi")))
"<div style='padding:5'>foobar<p>hi</p></div>"

Name: Anonymous 2007-07-26 10:18 ID:AYkKzNh1

Lisp is also excellent for abstraction and good at eradicating code duplication

(Really simple example)

Let's say I have a function print-customer-info that takes a list containing customer information and prints it out nicely.

(define (print-customer-info customer-info)
  (let ((name (car customer-info))
        (age (cadr customer-info))
        (street (caddr customer-info))
        (sex (cadddr customer-info)))
    (display (string-append "Name: " name "\n"
                            "Age: " (number->string age) "\n"
                            "Street: " street "\n"
                            "Sex: " sex "\n"))))


And I call it like this:

(print-customer-info '("Dave" 23 "12 Elm Street" "male"))

And it prints out:
Name: Dave
Age: 23
Street: 12 Elm Street
Sex: male


But this stuff is annoying:


  ...
  (let ((name (car customer-info))
        (age (cadr customer-info))
        (street (caddr customer-info))
        (sex (cadddr customer-info)))
   ...


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: Anonymous 2007-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.

Here's one example (in C):


PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HBRUSH fooBrush = CreateSolidBrush(RGB(255, 255, 255));
HOBJECT oldBrush = SelectObject(hdc, fooBrush);
// Do some painting here.
SelectObject(oldBrush);
DeleteObject(foobrush);
EndPaint(hwnd, &ps);


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

Here is one potential "solution" to this problem:


PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
{
    HBRUSH fooBrush = CreateSolidBrush(RGB(255, 255, 255));
    {
        HOBJECT oldBrush = SelectObject(hdc, fooBrush);
        {
            // Do some painting here.
        }
        SelectObject(oldBrush);
    }
    DeleteObject(foobrush);
}
EndPaint(hwnd, &ps);


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):


{
    RAII_BeginPaint paintOp;
    {
        RAII_CreateBrush nbrush(RGB(255, 255, 255));
        {
            RAII_SelectObject newselection(paintOp.hdc, nbrush.brush);

            // Do some painting here.
        }
    }
}


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.

Name: Anonymous 2007-07-26 10:47 ID:Heaven

I'm supposing you EXPERT PROGRAMMERS have used the Win32 API before.
In Lisp,

(NULL (NULL (NULL (NULL (NULL (NULL 0))))))

Name: Anonymous 2007-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:


(require "irc.ss")

;; Connect to server.
(define connection (connect "ANON" "Dave" "irc.freenode.net" 6667))

;; Add an event handler.
(define-irc-handler connection 'privmsg (privmsg-handler msg)
  (display (string-append "I has message!: " msg "\n")))

;; Start the connection thread.
(thread (lambda () (read-message-loop connection)))

Name: Anonymous 2007-07-26 10:48 ID:AYkKzNh1

Do you need moar examples to understand?

Name: Anonymous 2007-07-26 10:52 ID:Heaven

I did submit this to reddit, but it was downvoted to -10 in less than two minutes, so I deleted it.

Name: Anonymous 2007-07-26 10:58 ID:Heaven

>>25
fag

Name: Anonymous 2007-07-26 13:53 ID:rjTKtv7b

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

>>21
WinAPI, not even reading

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

Name: Anonymous 2007-07-26 14:43 ID:Heaven

>>25
THIS IS WHY.

Name: Anonymous 2007-07-26 14:47 ID:fQhPsMRB

Name: Anonymous 2007-07-26 15:00 ID:AYkKzNh1

>>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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-07-26 16:07 ID:fbaS5hKm

>>21
can't you do that with just lambdas, like say, in smalltalk?

Name: Anonymous 2007-07-26 16:09 ID:RkT4ZecV

>>25

lol, idiot

reddit takes themselves far too seriously for us EXPORT PROGRAMMARS to reveal ourselves to them

Name: Anonymous 2007-07-26 17:33 ID:Heaven

I wrote a Haskell compiler in Lisp

Name: Anonymous 2007-07-26 20:21 ID:Heaven

>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: Anonymous 2007-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: Anonymous 2007-07-27 0:43 ID:ZGFrZD/u

>>19
>>20
>>23
FUCKING GET OUT AND TAKE YOUR SHIT LISP EXAMPLES WITH YOU

EVERYONE SHUT THE FUCK UP ABOUT LISP

STUPID FAGGOTS

Name: Anonymous 2007-07-27 1:22 ID:Heaven

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

Name: Anonymous 2009-01-14 15:03

Worse then Perl

Name: Anonymous 2009-02-25 6:19

Wrong I like Lisp.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-08-03 9:04

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

Name: Anonymous 2010-11-13 16:10

Name: Anonymous 2010-12-27 1:45

Name: Anonymous 2011-02-04 14:48

Don't change these.
Name: Email:
Entire Thread Thread List