
Not Lisp again.... - spydez
http://funcall.blogspot.com/2009/03/not-lisp-again.html
======
rlm
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 :)

~~~
coffeemug
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!

~~~
moe
What is this snippet supposed to tell me? Looks completely meaningless to me.

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

~~~
moe
Ah thanks for clarifying. Now it makes sense. Are there any real world
applications for this, for us mortal web developers?

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

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

------
brlewis
I loved this same course (spring '87 for me), but I wasn't impressed with the
speed. I came away thinking Scheme was for fun and C was for practical
programming. I've come around since then, and I don't have any performance
concerns about my Scheme-based web site.

~~~
antiismist
What is your scheme-based website? Is it ourdoings or something else? Just
curious because there aren't a lot of them out there that I know of.

~~~
brlewis
OurDoings is it. I still use the "wishful thinking" programming methodology I
learned from SICP. I'm married with 3 kids and a separate day job, and don't
think I could have pulled this off using a less programmable programming
language.

~~~
antiismist
That's cool. Could I interview you about developing web apps using Scheme? I'm
working on a blog post / interview on the topic w/ all the people I know who
do Scheme web development.

Anyway if you are interested I'd love to hear from you, my email is:
idoh@idoh.com

------
elai
Hey you can do this w/ python too!

<code> dx = .000001

def deriv(f): def fprime(x): return (f(x+dx) - f(x))/dx return fprime

def cube(x): return x __3

def printDeriv(x): print (deriv(cube))(x) print 3 _x_ *2

printDeriv(5) </code>

~~~
sketerpot
In general, you can do this in any language which lets you pass functions
around as values, and which supports closures. And languages in which you can
fake it somehow.

------
jeeringmole
An excellent recent book is Peter Seibel's Practical Common Lisp.
<http://www.gigamonkeys.com/book/> The approach is what you might guess from
the title, so it addresses both the fun of Lisp and the building of practical
applications (including web apps).

------
ced
Funny how tail recursion pretty much has "cute optimization hack" written all
over it. It really doesn't feel at home in a first lecture on programming.

~~~
dfox
Tail recursion has profound theoretical implications, so it belongs there. If
your language is properly tail-recursive it completely changes definition of
recursive and iterative.

------
sanj
Summary: tail recursion FTW!

<http://en.wikipedia.org/wiki/Tail_recursion>

~~~
sketerpot
This belongs in the summary: {higher-order functions, closures, potentially-
inefficient elegance} FTW.

------
dbul
Interesting first lecture. I think the great Oscar Waddell (a wizard though no
longer in academia to my knowledge) wrote a Scheme program centered around
beer for our first lecture at IU. Now _that_ caught the attention of many
students and I'm pretty sure the class /grew/ in size for the next lecture.

------
ShardPhoenix
That derivative example is nice, but it reinforces that Lisp is a bit too
"pure"/"mathy" for my taste (that and I really don't like the syntax). My
equivalent of that derivative thing was probably the examples in "Why's
Poignant Guide to Ruby", pretty syntax-highlighting colors and all.

------
diN0bot
the four concerns the author lists at the end are interesting for what they
say about where he's coming from. to me, the joy of programming is more about
programming than speed or efficiency.

that he also put 'harder to understand' and 'capability' in the list is
confusing. he must mean capability in some kind of raw sense, whereas i see
capability as having abstraction and libraries so i can get to the meat
faster. again, abstraction is usually easier to understand.

perhaps when meat is speed and efficiency then our perspectives merge. psyched
about 16 Mb of RAM!

btw, scheme has recently been replaced by python in the intro programming
courses. snap.

~~~
kragen
Read the previous post where he was introduced to Lisp by way of MACRO-11, and
you'll see what he means by "capability".

