Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Look Around You
Jan 19, 2009

So I've been looking around on this forum and there's not very much on functional languages in general, and lisp is awesome family of functional languages.

History and Design
Lisp was invented in 1958 by a really cool dude named John McCarthy who was pretty big in AI research and stuff (he actually just died last October). It's currently the second oldest high level programming language still used today (the oldest being Fortran). There's not one implementation or dialect that's been used consistently, so instead of calling lisp a language, it's actually more correct to refer to it as a family of languages (or dialects) which share common features and a common general syntax.

Lisp consists entirely of s-expressions. An s-expression is essentially a fully parenthesized list. They can contain either atoms or more lists recursively. An atom is either a constant or a symbol. There is no difference in lisp between a statement and an expression in lisp. Functions application is prefix, and it occurs in parens. A lisp program is written the same way the primary data structure in the language is.

This similarity is actually a huge benefit to the language, as it allows the language to use macros extensively. Lisp macros can operate on the actual program just as the program can operate on data. This allows the language to be defined with an extremely small number of fundamental forms. And by extremely small number, I mean that Scheme, one of the major modern dialects, has 12 fundamental forms. Everything else can be implemented in terms of the fundamental forms as macros.

Contemporary lisp

There are 3 major dialects of lisp in use today. The first two, Scheme and Common Lisp have been around for a while, while the third, Clojure, is pretty new. One other thing to note is that there are two major "types" of lisp: lisp-1 and lisp-2. Lisp-1s use a single namespace for functions and variables, while lisp-2s uses multiple namespaces.

Scheme is an extremely minimal dialect of lisp, mostly used for teaching computer science in universities. The canonical book The Structure and Interpretation of Computer Programs was written for the introductory CS course at MIT which used Scheme as it's language of choice due to it's simplicity. The entire language specification is 302 pages in print, including standard libraries and appendices. Scheme is a language defined by a standard, and does not have a single reference implementation. The current version of the standard is R6RS which stands for "the Revised6 Report on the Algorithmic Language Scheme". Scheme is a lisp-1 and features lexical scoping. Scheme also requires proper handling of tail-recursion in it's specification. Popular implementations of Scheme are Racket(formerly called PLT-Scheme) and Gambit.

Common Lisp is the other older major dialect of lisp in use today. Common Lisp is basically the opposite of scheme, though the same people that developed scheme chaired the standards committee for CL. Common Lisp is almost the exact opposite of Scheme however. It's standard requires a ton of features, including a system for OOP. CL is a lisp-2, featuring multiple namespaces. It also has lexical scoping.

Clojure is the newest dialect of lisp on the scene, and it's generated a resurgence of interest in lisp and functional languages in general. Clojure is a version of lisp which is designed to compile to JVM bytecode. It's designed to work very well with Java programs and therefore has some departure from traditional lisps, such as syntactically different primitives for vectors, maps and sets. It's got a reference implementation and has an alternate compiler for generating javascript. One thing notable about Clojure is that Heroku supports Clojure as one of it's main supported languages (and actually included Clojure support before Java support IIRC).

References
Wikipedia
Other sites referenced are linked inline.

Sorry if the end of this post seems odd, I lost my train of thought towards the end :(

Adbot
ADBOT LOVES YOU

h_double
Jul 27, 2001
Good idea for a thread.

The only thing I really have to add is to recommend How To Design Programs (which you can read online), which is a great and accessible introduction to functional programming via Scheme. It's a bit like SICP-lite, and is a book that most any programmer (especially beginner/intermediate level) can benefit from.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I'd heartily recommend Conrad Barski's Land of Lisp for someone looking to learn Lisp generally and Common Lisp specifically (although in later chapters it touches on Clojure, Scheme and Arc, the focus is on CL throughout). It's fun throughout, moderately opinionated and only slightly triumphalist. And all the examples are games! There is no better motivator to learning how to handle graphs or whatever in Lisp imo than implementing Grand Theft Wumpus.

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice
Here's the obligatory link to the MIT Lectures on LISP. These videos, while older than I am, are very well done and have aged wonderfully. They contain the lectures that go along with the The Structure and Interpretation of Computer Programs book mentioned in the OP.

Look Around You
Jan 19, 2009

oRenj9 posted:

Here's the obligatory link to the MIT Lectures on LISP. These videos, while older than I am, are very well done and have aged wonderfully. They contain the lectures that go along with the The Structure and Interpretation of Computer Programs book mentioned in the OP.

Oh here is a youtube link to a video recording of the 1986 SICP course. I think it's actually the full course on video on the MIT youtube channel, in case you don't want to download it.

E: It's probably the same videos linked above but on youtube instead of needing downloaded.

e2: SCIP -> SICP because I suck at typing.

Look Around You fucked around with this message at 21:44 on Feb 11, 2012

Toekutr
Dec 9, 2008
In case people are interested in books on macros,

http://www.bookshelf.jp/texi/onlisp/onlisp.html

http://letoverlambda.com/textmode.cl/guest/toc

duck monster
Dec 15, 2004

oRenj9 posted:

Here's the obligatory link to the MIT Lectures on LISP. These videos, while older than I am, are very well done and have aged wonderfully. They contain the lectures that go along with the The Structure and Interpretation of Computer Programs book mentioned in the OP.



This dude owns.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

duck monster posted:



This dude owns.
No mention of Hal Abelson's awesomeness is complete without the epiphanous "I suggest we look at it for awhile" moment from SICP.

Marrick
May 29, 2006

Did I rush it? Felt like I rushed it...
My only, and I mean only, gripe about the videos is that they don't always go in order of the book. So, while you're reading about concurrency, the videos are on stream processing. It's a minor nitpick, otherwise they're fantastic. Since they do blow through some topics pretty fast, I found the Brian Harvey CS 61A lectures from Berkeley great for another view: http://www.youtube.com/watch?v=zmYqShvVDh4&feature=list_related&playnext=1&list=SP6879A8466C44A5D5

Meganiuma
Aug 26, 2003

Dijkstracula posted:

No mention of Hal Abelson's awesomeness is complete without the epiphanous "I suggest we look at it for awhile" moment from SICP.

Hal Abelson's a really awesome dude but the picture and video are of Gerald Sussman ;)

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I need to munch some XML, what's the best CL library for this?

Neslepaks
Sep 3, 2003

Otto Skorzeny posted:

I need to munch some XML, what's the best CL library for this?

All XML libraries are terrible, as you know, but we've been using XMLS. At least it's simple, and without dependencies.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I will give it a shot :911:

E: Alright, now would be a good time for me to ask you guys to straighten out my understanding of libraries in Lisp.

XMLS seems to do a fine job for what I want, parsing the XML and spitting out a nice sexpr. When I'm in the repl, I can just (ql:quickload) the library, but that doesn't work in a script (since the init file doesn't get run). Attempting to (require 'xmls) doesn't seem to work, and I'm wondering if it's because quicklisp keeps software in its dists dir whereas sbcl and clisp look for require'd things in some other dir. Or am I going about things completely wrong?

Blotto Skorzany fucked around with this message at 19:20 on Feb 17, 2012

Catalyst-proof
May 11, 2011

better waste some time with you
Oooooh a Lisp threaaaad. I've been trundling along with Common Lisp for about a year now working on personal projects, and I've written some articles about my travels at http://msnyder.info/. I also work extensively in Emacs Lisp and have a thread kicking about for that, as well.

Seconding the recommendation for Land of Lisp, as well as The Little Schemer.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Otto Skorzeny posted:

I need to munch some XML, what's the best CL library for this?

Seeing as how XML is practically the same structure as S-EXPs, parsing XML in Lisp is probably easier than with most languages.

This link is about Scheme, so not exactly what you want, but interesting nonetheless. I recommend reading just about everything on that guy's site (http://okmij.org/ftp/Scheme/index.html) because it's all pretty amazing stuff.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Kilson posted:

Seeing as how XML is practically the same structure as S-EXPs, parsing XML in Lisp is probably easier than with most languages.

I wonder if you could make a Lisp interpreter that used XML instead of S-EXPs.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
You could do so very easily with Racket.

Neslepaks
Sep 3, 2003

Otto Skorzeny posted:

XMLS seems to do a fine job for what I want, parsing the XML and spitting out a nice sexpr. When I'm in the repl, I can just (ql:quickload) the library, but that doesn't work in a script (since the init file doesn't get run). Attempting to (require 'xmls) doesn't seem to work, and I'm wondering if it's because quicklisp keeps software in its dists dir whereas sbcl and clisp look for require'd things in some other dir. Or am I going about things completely wrong?

REQUIRE rarely does what you want, it's better to rely on ASDF or Quicklisp. Why can't you get it to load your init file in script mode?

E; Also, why script mode? If you're using SBCL, why not make a binary?

Neslepaks fucked around with this message at 14:50 on Feb 18, 2012

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Neslepaks posted:

REQUIRE rarely does what you want, it's better to rely on ASDF or Quicklisp. Why can't you get it to load your init file in script mode?

E; Also, why script mode? If you're using SBCL, why not make a binary?
When invoke via sbcl --script, one of the things it does is disable loading your init file. I didn't see a flag to re-enable loading the init file, is there one? I'd much rather let quicklisp do its thing than muck about with that sort of thing myself.


As for script mode, the program I'm writing is a module for a larger program, and the team generally doesn't want captive interfaces. If I do sb-ext:save-lisp-and-die, when it's run it will bring up the REPL, no?

Neslepaks
Sep 3, 2003

Otto Skorzeny posted:

As for script mode, the program I'm writing is a module for a larger program, and the team generally doesn't want captive interfaces. If I do sb-ext:save-lisp-and-die, when it's run it will bring up the REPL, no?

No, no. You specify the top-level function with :toplevel #'butt and when that function exits, the program exits, like you'd expect. You can also use --disable-debugger and --disable-ldb when building the image to make sure it never enters any interactive mode.

Beware of the order of your options though, SBCL is finicky about it. There are three "groups" of them or some poo poo, read the manpage.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Oh, kickass!


e: for any future readers, you probably also want to pass :executable t to save-lisp-and-die

Blotto Skorzany fucked around with this message at 04:41 on Feb 19, 2012

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Meganiuma posted:

Hal Abelson's a really awesome dude but the picture and video are of Gerald Sussman ;)
:suicide: And I don't think this is the first time I've gotten the two confused either!

Strong Sauce
Jul 2, 2003

You know I am not really your father.





How do I run Clojure with the numeric-tower library? Using Windows and I'm completely lost as to what to do. None of the official documentation really mentions what to do either.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
My coding life has improved about 1024x since I installed slimv

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice

Otto Skorzeny posted:

My coding life has improved about 1024x since I installed slimv

Are there any decent 21st century IDEs for LISP/Scheme? MIT-GNU Scheme is nearly as frustrating as Emacs to use. It got to the point where I just didn't want to continue working with Scheme because I didn't have a decent way to work with it.

Of course, I guess I could man up and embrace m-x m-e as the original F5.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

oRenj9 posted:

Are there any decent 21st century IDEs for LISP/Scheme? MIT-GNU Scheme is nearly as frustrating as Emacs to use. It got to the point where I just didn't want to continue working with Scheme because I didn't have a decent way to work with it.

Of course, I guess I could man up and embrace m-x m-e as the original F5.

I don't have enough fingers for emacs, but as I said vim+slimv has treated me real well so far.

Outside of that, I'm told LispWorks is nice, and I think they have a free version you could try.

If you prefer something scheme-y, I've heard nice things about Racket/PLT Scheme, and they have their own IDE called DrRacket.

Blotto Skorzany fucked around with this message at 08:52 on Feb 21, 2012

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
DrRacket is pretty nice, it's got an integrated repl, debugger, macro stepper, etc. If divascheme is still being updated then you can install that and get paredit style structural editing but with vi style modality.

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice
DrRacket rocks, thanks guys!

Look Around You
Jan 19, 2009

Otto Skorzeny posted:

My coding life has improved about 1024x since I installed slimv

Have you been able to get slimv to work with pathogen? It may be just me having trouble using it with (m)vim on OS X but I wanted to make sure it wasn't a pathogen problem first.

etcetera08
Sep 11, 2008

Look Around You posted:

Have you been able to get slimv to work with pathogen? It may be just me having trouble using it with (m)vim on OS X but I wanted to make sure it wasn't a pathogen problem first.

I think your problem is probably because of this:

Slimv Tutorial posted:

You will also need a Python enabled Vim, and the same Python version installed that is Vim compiled against. This is because the communication part of the plugin is written in Vim's embedded Python (unfortunately there is no embedded Lisp for Vim).

I never even bothered to try it with MacVim because of that. I'm sure there are ways around that though.

a cat
Aug 8, 2003

meow.

Strong Sauce posted:

How do I run Clojure with the numeric-tower library? Using Windows and I'm completely lost as to what to do. None of the official documentation really mentions what to do either.

I was about to answer your question, then I found this in the process which pretty much explains exactly what I was going to say better than I could:
http://stackoverflow.com/questions/8706655/using-clojure-math-numeric-tower-or-any-library

Edit: I love Clojure and I've been waiting for a thread like this to show up. Is there any interest in a big Clojure effortpost here? I'm not really a good programmer or anything but I've banged my head against the wall over problems like Strong Sauce's to the point where I can probably point people in the right direction to get started with it at least. It really is an awesome language.

a cat fucked around with this message at 03:01 on Feb 23, 2012

Look Around You
Jan 19, 2009

jstirrell posted:

I was about to answer your question, then I found this in the process which pretty much explains exactly what I was going to say better than I could:
http://stackoverflow.com/questions/8706655/using-clojure-math-numeric-tower-or-any-library

Edit: I love Clojure and I've been waiting for a thread like this to show up. Is there any interest in a big Clojure effortpost here? I'm not really a good programmer or anything but I've banged my head against the wall over problems like Strong Sauce's to the point where I can probably point people in the right direction to get started with it at least. It really is an awesome language.

Why not post it? This is a lisp thread and Clojure is a lisp v :) v

Strong Sauce
Jul 2, 2003

You know I am not really your father.





jstirrell posted:

I was about to answer your question, then I found this in the process which pretty much explains exactly what I was going to say better than I could:
http://stackoverflow.com/questions/8706655/using-clojure-math-numeric-tower-or-any-library

Edit: I love Clojure and I've been waiting for a thread like this to show up. Is there any interest in a big Clojure effortpost here? I'm not really a good programmer or anything but I've banged my head against the wall over problems like Strong Sauce's to the point where I can probably point people in the right direction to get started with it at least. It really is an awesome language.

Unfortunately lein support doesn't work too well on Windows, especially since I didn't want to really install wget/curl. I ended up doing this:

java -cp "C:\Program Files (x86)\Clojure\clojure-1.3.0.jar;C:\Program Files (x86)\Clojure\math.numeric-tower-0.0.1.jar" clojure.main

then typing in

(require '[clojure.math.numeric-tower :as math])

in the REPL

edit: even better, just add the jar path to CLASSPATH

Strong Sauce fucked around with this message at 04:16 on Feb 23, 2012

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
Lein works fine on windows. You don't even need to "install" wget, just download the binary and put it on your path. It even gives you urls to to it if you run the bat and it can't find it!

Though frankly, I don't understand why they made the wrapper a loving bat file. It seems like it would be waaay less trouble to just write it in vbscript or jscript or something. I'm pretty sure WSH has url downloading in it.

SavageMessiah fucked around with this message at 04:24 on Feb 23, 2012

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I got lein loaded after I figured out that having Clojure 1.3.0 required running the latest version of lein, 1.7.1.

Anyways, when I finally got that going and tried running `lein deps` it just failed saying it could not find it so I gave up on it.

It may work, but it is a pain to install on Windows.

etcetera08
Sep 11, 2008

I'm reading through Land of Lisp and working on OS X. I had trouble brew install'ing CLISP so I'm running Clozure CL for now. Is this an acceptable implementation? I am sort of unsure of how much variation there is between all the different versions.

shrughes
Oct 11, 2008

(call/cc call/cc)

etcetera08 posted:

I'm reading through Land of Lisp and working on OS X. I had trouble brew install'ing CLISP so I'm running Clozure CL for now. Is this an acceptable implementation? I am sort of unsure of how much variation there is between all the different versions.

Yes it is. Another good implementation is SBCL.

Edit: According to Wikipedia, "Clozure CL is used by ITA Software for the business logic of a new Airline Reservation System for Air Canada[2]."

If ITA is using it, you know it's not crap.

Beef
Jul 26, 2004
SBCL is great. As far as I know it has about the best optimizing compiler for CL.

Commercial companies like to use Clozure, Allegro CL or Lispworks because they can get fixes overnight or even ask for specific features or platforms.


Speaking of CLISP, any news around their JIT?



PS. Yay, a Lisp thread!

Beef fucked around with this message at 15:56 on Mar 5, 2012

Catalyst-proof
May 11, 2011

better waste some time with you

etcetera08 posted:

I'm reading through Land of Lisp and working on OS X. I had trouble brew install'ing CLISP so I'm running Clozure CL for now. Is this an acceptable implementation? I am sort of unsure of how much variation there is between all the different versions.

Clozure's fantastic. I'm going to be publishing an article Real Soon Now that uses it's foreign function interface support extensively.

Adbot
ADBOT LOVES YOU

Beef
Jul 26, 2004
Protip: Use ParEdit mode in emacs to write Lisp. It constantly keeps your parens balanced. Every other editor seems primitive once you have gotten used to it.

  • Locked thread