News for hackers. Stuff that matters.
Re:Not Lisp again.... by rlm on Thursday March 05, 2009 @04:17PM (#504763)
This is the essence of that "This is so cool"-feeling that arises when you first really _get_ programming.

And almost makes me want to invest in SICP or something similar to see what all this LISP-talk is about :)

Re:Not Lisp again.... by coffeemug on Thursday March 05, 2009 @05:15PM (#504834)
You know, if you keep learning you will never cease to have this feeling.

  ?- append([1, 2, 3], [4, 5, 6], X).
  X = [1, 2, 3, 4, 5, 6].

  ?- append([1, 2, 3], X, [1, 2, 3, 4, 5, 6]).
  X = [4, 5, 6].

  ?- append(X, [4, 5, 6], [1, 2, 3, 4, 5, 6]).
  X = [1, 2, 3].
And the definition of append:

  append([], X, X).
  append([X | Y], Z, [X | O]) :- append(Y, Z, O).
Magic!
Re:Not Lisp again.... by anatoly on Thursday March 05, 2009 @06:23PM (#504917)
Ah, thank you for rekindling that memory.

Prolog, where you just type what you want to achieve, and it goes ahead and does it for you. I really couldn't wrap my head around it for some time. I read up on backtracking and chased around derivations on paper to satisfy myself that something like append really worked.

Re:Not Lisp again.... by moe on Thursday March 05, 2009 @05:57PM (#504887)
What is this snippet supposed to tell me? Looks completely meaningless to me.
Re:Not Lisp again.... by Ezra on Thursday March 05, 2009 @06:23PM (#504918)
Basically what's going on is this, but with lists:

3 + 5 = X?

X = 8

3 + X = 8?

X = 5

5 + X = 8?

X = 3

In most programming languages, you can't infer a parameter by specifying a result.

(Though that's not strictly what's going on here, either)

You could further say something like X + Y = 8 and get

X = 0, Y = 8

X = 1, Y = 7

etc. for some definitions.

Which is, as the OP was getting at, sometimes incredibly useful.

Re:Not Lisp again.... by moe on Thursday March 05, 2009 @06:25PM (#504921)
Ah thanks for clarifying. Now it makes sense. Are there any real world applications for this, for us mortal web developers?
Re:Not Lisp again.... by Ezra on Thursday March 05, 2009 @06:40PM (#504941)
If you're asking "are there potentially awesome applications of this?" then the answer is probably "yes".

If you're asking "is there anything in the wild that I would know of and uses this?" then the answer is probably "no".

Most of the prolog projects I've ever seen are pretty inbred; implementing compilers or interpreters, hooks for another language-type things. Though it must be said that I'm not deeply embedded in the prolog community.

Re:Not Lisp again.... by gommm on Thursday March 05, 2009 @07:22PM (#504983)
In my 4th year university project we worked on an expert system for a card game in Prolog... For doing an expert system based AI, prolog is pretty good...
Re:Not Lisp again.... by oconnor0 on Thursday March 05, 2009 @06:11PM (#504904)
It tells you that Prolog's list append function has far more general applicability than just appending lists. Because of the way Prolog is designed you can use that function definition to do destructuring pattern matches on lists - to find differences, etc.

It means the tools you write for one use can be used completely differently than you intended, and in ways that continue to give you those "whoa!" moments.

Re:Not Lisp again.... by newt0311 on Thursday March 05, 2009 @06:26PM (#504922)
As has already been mentioned, thats not a function, it is a functor. It indicates a relation between two objects. Specifically, it tells the prolog runtime that a list appended to an empty list is just the list itself and that the resultant list and the first list argument should have the same prefix. Another thing to note is that the append function piggy-backs on the prolog version of list-appended cons-cells so that append function example is a bit deceiving. However, the power of prolog should not overlooked. For example, a call to append(X, Y, [1, 2, 3]) would have returned all possible values of X and Y which append to [1, 2, 3]. Something much harder in other languages.

An extremely (imho) good source for information on logic programs and how they are implemented is here: http://www.ida.liu.se/~ulfni/lpp/

A more practical guide to actually compiling these logic programs efficiently (or as efficient as they can be) is documented in Modern Compiler Design by Dick Grune et al. They actually describe the workings of a somewhat simplified workings of a Warren Abstract Machine (WAM) which can (to my knowledge) now approach to within an order of magnitude of standard programming languages. Pretty amazing when the generality of logic programming is considered. Details on the WAM here: http://en.wikipedia.org/wiki/Warren_Abstract_Machine

Re:Not Lisp again.... by aguha on Thursday March 05, 2009 @05:59PM (#504889)
Relations, not functions. Prolog.
Re:Not Lisp again.... by Hexstream on Thursday March 05, 2009 @06:23PM (#504919)
You mean if one keeps learning after SICP? Bad example, because SICP tells you how to implement exactly this functionality (among other things).
Re:Not Lisp again.... by coffeemug on Thursday March 05, 2009 @06:50PM (#504949)
If one keeps learning, dreaming, and building in general. I am just saying that no matter how many amazing things you've discovered, there's always more in store. Just never stop looking.
Re:Not Lisp again.... by gamache on Thursday March 05, 2009 @05:04PM (#504820)
And Hal Abelson knows how to give fledgling programmers that Eureka moment in spades. This article mirrors my experiences very closely -- I came into the class Spring 1998 with BASIC and assembly experience, thinking I knew how to program.

SICP couldn't be worth any more if it were printed on gold leaf, but having Abelson and Sussman there to teach it really seals the deal.

Re:Not Lisp again.... by lliiffee on Thursday March 05, 2009 @04:21PM (#504771)
Read the full text online right now:

http://mitpress.mit.edu/sicp/full-text/book/book.html

If you meant an investment of time, then, well yes. But SICP is really, really fun.

Re:Not Lisp again.... by michael_dorfman on Friday March 06, 2009 @07:45AM (#505415)
....and don't forget the SICP video lectures! http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussma...

The best 20-hour introduction to CS you can find, or your money back!

Re:Not Lisp again.... by rlm on Thursday March 05, 2009 @04:28PM (#504780)
I both meant an investment of time and money :)

I don't like reading entire books on the computer. It just feels better on paper ;)

Re:Not Lisp again.... by xenophanes on Thursday March 05, 2009 @05:44PM (#504875)
I agree about paper books.

Does anyone who feels the same have a kindle? Supposedly the screen is more like paper. Wondering how well that works...

Re:Not Lisp again.... by jrockway on Thursday March 05, 2009 @05:50PM (#504882)
It is very much like paper. (The display area is smaller than the average hard-cover book, however, but that doesn't bother me too much.) The only thing I don't like about the Kindle is that you can't skim to get an overview of the book or newspaper... you basically have to use the table of contents or read it in order. Not so bad for books, kind of annoying for local news.

(The killer feature of the Kindle, though, is the effortless buying feature. When you have to pay $30 and go to the store or wait 5 days for shipping, you tend to not buy books. When you can click a button and start reading on a paper-like screen instantly, it becomes much easier to read all the books that you've been "meaning to" read. But I digress.)

Re:Not Lisp again.... by derefr on Thursday March 05, 2009 @06:16PM (#504910)
Someone should really make a hybrid E-Ink/LCD reader. A transparent LCD overlay (with backlight) for skimming, that switches off after you stare at the same page for a few seconds and re-displays the current rendered page on the E-Ink display underneath.
Re:Not Lisp again.... by chrisconley on Thursday March 05, 2009 @06:09PM (#504903)
Don't forget about our Hacker News SICP Book Club too: http://groups.google.com/group/hacker-news-reads-sicp
Re:Not Lisp again.... by jjames on Thursday March 05, 2009 @05:35PM (#504860)
Wish there was a way to read this online but The Little Schemer http://www.ccs.neu.edu/home/matthias/BTLS/ made the first couple chapters of SICP a little easier for self study.
Re:Not Lisp again.... by discojesus on Thursday March 05, 2009 @08:26PM (#505028)
there is (sort of); it's available nearly in its entirety on Google Books.