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
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've found paredit mode obnoxious in the repl and useless in the editor and disabled it in slimv, but I'm allergic to metakeys so ymmv

Adbot
ADBOT LOVES YOU

Catalyst-proof
May 11, 2011

better waste some time with you
One day paredit will make sense to me and I'll go through a complete session using it without screaming at my editor like a howler monkey as it moves the cursor around indiscriminately. It took me a couple of tries for Emacs to make sense to me, so you never know.

Beef
Jul 26, 2004
You have to get used to its peculiar way of doing things; it takes a few days of forced paredit usage and the cheat-sheet stickied next to your monitor.

Also, it makes me want to fix the thread title using M-s (splice sexpr)

Look Around You
Jan 19, 2009

Beef posted:

You have to get used to its peculiar way of doing things; it takes a few days of forced paredit usage and the cheat-sheet stickied next to your monitor.

Also, it makes me want to fix the thread title using M-s (splice sexpr)

I probably could've done the title as (define (thread lang . posts) (show posts)) (thread lisp posts) (scheme style) since I don't know CL that well, but I used the explicit lambda and I put it in parens because more parens is better right :haw:

e: the extra parens took it out of the top level too :lol: In my defense I was getting increasingly less focused because I was bored as hell in a recitation but still trying to act like I wasn't doing other poo poo.

Look Around You fucked around with this message at 19:24 on Mar 6, 2012

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

duck monster posted:



This dude owns.

I got a chance to eat breakfast and lunch with Dr. and Mrs. Sussman at Strange Loop last September.

He is amazingly bright and speaks super loving fast when he's talking about math, holy poo poo. She is super nice and I think she knows her husband is way too smart to talk to near-norms like me. She gave me one of his magazines from MIT as a consolation prize I think.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

I love clj and have been digging around the compiler (ugh) and innards for the better part of a year now. I'd love a clojure thread if there's enough interest separate from the lisp thread here.

etcetera08
Sep 11, 2008

TRex EaterofCars posted:

I love clj and have been digging around the compiler (ugh) and innards for the better part of a year now. I'd love a clojure thread if there's enough interest separate from the lisp thread here.

A bunch of people on IRC were going through 4clojure and chatting about it, so there might be. I'd be interested in a discussion about whether or not Clojure (and other similar non-lisp languages) really are the future for concurrency, but I also don't know enough about the subject to participate much.

Beef
Jul 26, 2004
Regarding Clozure, it seems someone just put up a mac appstore app that uses Clozure:

http://clozure.com/pipermail/openmcl-devel/2012-March/013433.html

quote:

Hi CCL Users -

I'm happy to announce that our first app written in Clozure CL has just been released in the Macintosh App Store.

Picture Window is a simple but elegant slideshow viewer. It displays pictures in resizable floating windows that stay in view while you're using other Macintosh apps.

Picture Window was written by our very own Matthew Emerson, and it runs on OS X Snow Leopard and Lion.

If you'd like to support Clozure and Lisp-based apps in a small way, you can purchase a copy in the Mac App Store.
It's only $4.99. You can find it here:

http://itunes.apple.com/us/app/picture-window/id507262984?mt=12

Thanks for your support,


Andrew

h_double
Jul 27, 2001

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.

Hmm weird, I recently installed clisp on Snow Leopard via "brew install clisp" without any problems.

I just started in on Land of Lisp a few days ago and it's fantastic. One of the things I like about Lisp so far is the transparency of it -- it has a lot of high-level elegance and abstraction, but you also get a very good sense of how the program is working "under the hood", in a way that almost reminds me of assembly language. One of my big "whoa" moments was realizing that the REPL (the read-evaluate-print loop, Lisp's interpreter mode) can be written in Lisp as

code:
(loop (print (eval (read))))
Is that loving just like it says on the tin or what?!?

Also I'm very happy with using SLIME + Emacs, makes it very elegant to go back and forth between a source file and the REPL. Granted, I already knew my way around emacs (I have enough fingers, as it were), but given that emacs is built around Elisp, it's given me a fresh appreciation for a lot of things (especially customizations).

MononcQc
May 29, 2007

For people who'd like a lisp made for some concurrency, there are two dialects of lisp running on the Erlang VM, Joxa and LFE. They allow you to access all of the concurrency and fault-tolerance primitives of the Erlang VM, and although I haven't used Joxa much, I know LFE goes the extra mile to keep full compatibility with things like pattern matching.

unixbeard
Dec 29, 2004

I like the idea of lisp, everyone seems to talk about it in a zen like way and it seems to carry a lot of nerd points, I just really haven't had the motivation to work with it in any real way. What is so good about it? is there a specific domain of problems where it is particularly good?

Catalyst-proof
May 11, 2011

better waste some time with you
That's a superbly difficult question to answer. Imagine if you had a programming language that not only was its own abstract syntax tree, but provided a compile-time expansion language that was itself, giving you the full power of the language to have the compiler write the code that you're too lazy to. That's the top inch of the tip of the iceberg of the answer to your question. I'd recommend http://www.defmacro.org/ramblings/lisp.html as a slightly more in-depth attempt at an answer, but it's very much one of those things you need some practice at to see as useful.

Other, more practical points: Lisp is old as computers, with a battle-tested, comprehensive specification and dozens of implementations to choose from. It's fast, and tools to work with it are as solid as the language (Thinking specifically of SLIME and Emacs), implementing IDE-like functionality decades before IDEs existed (save Smalltalk, I suppose). Garbage collection, object orientation, and a host of other language features you may take for granted existed in one form or another in Lisp as afterthoughts before you were born. There was even a time of the Lisp machines, computers that were Lisp down to the metal, giving you that extensibility, functionality, and expressiveness system-wide.

Other, more vague points: Lisp is closely related to the lambda calculus, an elegant branch of mathematics that formalizes functions as a mathematical construct. Grokking Lisp can very quickly lead to a sort of Zen-like understanding of computation itself. (So I've heard! I am not so arrogant to say I've gotten there myself.)

Catalyst-proof fucked around with this message at 01:39 on Mar 9, 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

unixbeard posted:

I like the idea of lisp, everyone seems to talk about it in a zen like way and it seems to carry a lot of nerd points, I just really haven't had the motivation to work with it in any real way. What is so good about it? is there a specific domain of problems where it is particularly good?

Even without getting into the more zen stuff, Lisp is a really well-executed dynamic language that happens to also be much more performant than other dynamic languages. It's fun to write. It's more expressive than Perl* and more elegant than Python**. The tools built up around it (eg. SLIME/SLIMV) are awesome and make me probably 2x as productive on their own. The idiomatic style grows on you really, really quickly (in my case, the canonical indentation is still suboptimal but I turn on rainbow parens and deal with it, but the semantics are what really matter anyways).



*Except for munging text and a couple other things Perl has poured the whole bowl of sugar on
**Except for format and loop

etcetera08
Sep 11, 2008

Otto Skorzeny posted:

(in my case, the canonical indentation is still suboptimal but I turn on rainbow parens and deal with it, but the semantics are what really matter anyways).

That's one thing I don't understand, having gone through the first 100 pages or so of Land of Lisp.. I don't understand the indentation at all, unless it's specifically explained. I mean, I understand the general format but sometimes there are things just indented a couple spaces or something that doesn't make sense to me. Is there a conventional style guide somewhere I can browse?

Look Around You
Jan 19, 2009

etcetera08 posted:

That's one thing I don't understand, having gone through the first 100 pages or so of Land of Lisp.. I don't understand the indentation at all, unless it's specifically explained. I mean, I understand the general format but sometimes there are things just indented a couple spaces or something that doesn't make sense to me. Is there a conventional style guide somewhere I can browse?

This seems to be a good summary I guess.

etcetera08
Sep 11, 2008

Look Around You posted:

This seems to be a good summary I guess.

Ah this is very helpful, thanks!

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

etcetera08 posted:

That's one thing I don't understand, having gone through the first 100 pages or so of Land of Lisp.. I don't understand the indentation at all, unless it's specifically explained. I mean, I understand the general format but sometimes there are things just indented a couple spaces or something that doesn't make sense to me. Is there a conventional style guide somewhere I can browse?

Tbh vim and emacs auto-indent things according to it and I just live with it. As long as you hit the enter key at the right time you don't need to worry about aligning crap, it's done for you reasonably well.

I mean, I straight up dislike the use of indentation instead of a vertically aligned closing delimiter to tell where a block ends. It takes more time for me to do it, and the problem is worse in Lisp than in Python or Haskell due to the shape the code tends to take, but technical means (from rainbow parens to the worst case scenario of bouncing on the % key) ameliorate this to the point that idgaf. It also seems to be less of an issue if you're factoring reasonably well. Eg this is perfectly readable even without vertically aligned end delimiters:
code:
(defun munge-rule (rule)
  "Takes the sexpr structure of a rule as generated by XMLS and munges it into
  a much more useful format, such that we can build a reasonable alist or hash
  for the whole shebang."
  (labels
    ((rule-name (rule)
       (intern (car (cdaadr rule))))
     (dep-name (dep)
       (intern (caddr dep)))
     (rule-deps (rule)
       (mapcar #'dep-name (cddr rule))))

    (cons (rule-name rule) (list (rule-deps rule)))))
Whereas without those local functions, it would look like barf no matter what indent style was used.

Look Around You
Jan 19, 2009

Otto Skorzeny posted:

Tbh vim and emacs auto-indent things according to it and I just live with it. As long as you hit the enter key at the right time you don't need to worry about aligning crap, it's done for you reasonably well.

I mean, I straight up dislike the use of indentation instead of a vertically aligned closing delimiter to tell where a block ends. It takes more time for me to do it, and the problem is worse in Lisp than in Python or Haskell due to the shape the code tends to take, but technical means (from rainbow parens to the worst case scenario of bouncing on the % key) ameliorate this to the point that idgaf. It also seems to be less of an issue if you're factoring reasonably well. Eg this is perfectly readable even without vertically aligned end delimiters:
code:
(defun munge-rule (rule)
  "Takes the sexpr structure of a rule as generated by XMLS and munges it into
  a much more useful format, such that we can build a reasonable alist or hash
  for the whole shebang."
  (labels
    ((rule-name (rule)
       (intern (car (cdaadr rule))))
     (dep-name (dep)
       (intern (caddr dep)))
     (rule-deps (rule)
       (mapcar #'dep-name (cddr rule))))

    (cons (rule-name rule) (list (rule-deps rule)))))
Whereas without those local functions, it would look like barf no matter what indent style was used.

I think that keeping closing parens all on the same line makes lisp code a bit more readable and understandable tbh. In lisp I'm thinking about things as forms and stuff, and it's easy enough to figure out what's going on by the first term in an s-expression and the subsequent indentation.

I think it goes back to the whole "it's all a list" thing instead of there being a difference between statements and expressions and blocks or w/e in more traditional languages.

Like that lisp code I'd be fine with and it's extremely readable, but

code:
int x(int y, int z) {
  if (y > z) {
    return 1; }
  else {ex
    return 0; } }
would make me want to shoot someone... I think it may be because if statements and function definitions and stuff are really different syntactically.

e: actually, I think part of it is because in lisp, the form is entirely closed in parens (ex: (if (cond) (then) (else)) ) instead of the form being bare and then being followed by the block (ex: if (cond) { this; } else { that } )

Look Around You fucked around with this message at 07:39 on Mar 9, 2012

Beef
Jul 26, 2004
The semi-joke is that you ignore parens after a while, so you use the indentation to follow nesting. Parenthesis are not that important that they need their own specially dedicated line in your code.
In the end, there is no reason to not follow good style, and that includes indentation. You catch a lot of bugs with it and makes your code easier to mentally parse. Something is very wrong when you have to mentally match parens yourself.
We do yell at our students when they can't be bothered to properly break up and indent there code. All you need to do is hit loving tab in Racket/Lisp ffs. Programming projects always have a few points allocated to 'code style'.

Common Lispers have created a general consensus over style from over half a century of formatting their code. You will vastly improve the readability of your code for other lispers if your style fits in their expected pattern.

I would format the above as:
code:
(defun munge-rule (rule)
  "Takes the sexpr structure of a rule as generated by XMLS and munges it into
  a much more useful format, such that we can build a reasonable alist or hash
  for the whole shebang."
  (labels ((rule-name (rule) (intern (car (cdaadr rule))))
	   (dep-name (dep) (intern (caddr dep)))
	   (rule-deps (rule) (mapcar #'dep-name (cddr rule))))
    (cons (rule-name rule) (list (rule-deps rule)))))
'labels' should be formatted like 'let', as it does something similar: you expect a block of definitions and a body. The body expression is the important part so you use indentation to clearly separate the definitions block.

Additionally, most Lispers reserve the '(<expr> <newline>' indentation style for expressions that do not take any arguments, such as for example 'progn' or Scheme's 'begin'.
code:
(progn
  foo
  bar)
This way you can immediately see what expressions are getting what arguments. Such as in the above 'labels' or in 'let', where arguments (the definition block) are treaded differently indentation-wise than the body expression.
Or a function call, where all arguments are equal.
code:
(something-magical foo
		   bar
		   baz)
By following common style, you know foo bar and baz are treated as arguments, whatever something-magical is.
Is something-magical that does some magical macro stuff? Then indent it as such to make it clear to the reader.

For example if something-magical is a macro that does something weird, not treating all its arguments equally at all, then it should be obvious from it's usage:
code:
(something-magical beepboop bo-beep 
  "you are inferior"
  "exterminate"
  "exterminate")

BEEPBOOP you are inferior BO-BEEP.
BEEPBOOP exterminate BO-BEEP.
BEEPBOOP exterminate BO-BEEP.
In fact, that's exactly why you have the otherwise superfluous &body argument in defmacro. Smart editors like emacs+slime will use that fact to automatically indent your code differently depending on the definition:
code:
(defmacro something-magical (pre
			     post
			     &body sentences)
  "Print out all lines in sentences, prepending foo and appending bar.
This is a horrible macro written by a horrible programmer trying to
make a point. Do not do this, ohgod." 
  (loop for expr in sentences
	do (format t "~A ~A ~A.~%" pre expr post)))
Dear god how did I end up with such wall of text.


I recommend reading Tutorial on Good Lisp Programming Style by Norvig and Pitman. It will make you a better programmer, no matter the language.

etcetera08
Sep 11, 2008

Beef posted:

:words:

Wow, great advice. Thanks.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Otto Skorzeny posted:

Tbh vim and emacs auto-indent things according to it and I just live with it. As long as you hit the enter key at the right time you don't need to worry about aligning crap, it's done for you reasonably well.

I mean, I straight up dislike the use of indentation instead of a vertically aligned closing delimiter to tell where a block ends. It takes more time for me to do it, and the problem is worse in Lisp than in Python or Haskell due to the shape the code tends to take, but technical means (from rainbow parens to the worst case scenario of bouncing on the % key) ameliorate this to the point that idgaf. It also seems to be less of an issue if you're factoring reasonably well. Eg this is perfectly readable even without vertically aligned end delimiters:
code:
(defun munge-rule (rule)
  "Takes the sexpr structure of a rule as generated by XMLS and munges it into
  a much more useful format, such that we can build a reasonable alist or hash
  for the whole shebang."
  (labels
    ((rule-name (rule)
       (intern (car (cdaadr rule))))
     (dep-name (dep)
       (intern (caddr dep)))
     (rule-deps (rule)
       (mapcar #'dep-name (cddr rule))))

    (cons (rule-name rule) (list (rule-deps rule)))))
Whereas without those local functions, it would look like barf no matter what indent style was used.

I hate cdaddadadaddar crap, I've been spoiled by clojure's pervasive destructuring. Here's how I would do that in clojure, if anyone is curious what destructuring can do for you.

code:
(defn munge-rule [[_ [[_ rule-name]] & rule-deps]]
  "Takes the sexpr structure of a rule as generated by XMLS and munges it into
   a much more useful format, sucha that we can build a reasonable alist or hash
   for the whole shebang." 
  (let [dep-names (map (fn [[_ _ dep-name]]
                         (keyword dep-name))
                       rule-deps)]
    (cons (keyword rule-name) (list dep-names))))
I didn't even try to run this, but I'm pretty sure I matched the structure your code describes. Clojure uses vectors instead of lists in cases where the code is not for execution, such as variable bindings. Anywhere you can bind a variable (comprehensions, function parameters, let, etc) you can destructure. Vectors in the destructuring form take apart sequences, maps take apart maps. They're recursive, and there's a bunch of really useful things you can do that I don't show. I turned the names into keywords instead of symbols because that's the idiomatic thing in clojure.

Catalyst-proof
May 11, 2011

better waste some time with you
Common Lisp definitely has destructuring binds. Also no one should still be using car, cdr, and its offspring over nth.

Beef
Jul 26, 2004
As you should always choose the most specific/applicable function.

Use
(car foo) if foo is a cons
(first foo) if foo is a list

cdadr magicians will be shot on sight, use loving defstruct or abstract datatypes.

I suspect they are used in Land of Lisp to make the code examples easier to write, in the sense that you take less time to copy them from the book. A little how those write-your-own-game books were also programs optimized for number of characters.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
ca*d*a*r bullshit isn't so bad if you actually name it something meaningful. That said I don't think I'll ever forget

Beef posted:

cdadr magicians will be shot on sight, use loving defstruct or abstract datatypes.

hahahhah

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
cdaddaddaar has the compelling advantage of that it's a lot more fun to say.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Fren posted:

Common Lisp definitely has destructuring binds. Also no one should still be using car, cdr, and its offspring over nth.

Do they work everywhere or do you need to use destructuring-bind explicitly?

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

Beef posted:

Style stuff

Thank you for a really informative and helpful post!

Re: the labels bit, I had been mentally mulling over that for a while, the let-style definitely looks better.

Re: the cdadr stuff, what should I read up on wrt. destructuring? I tried to insulate myself from the cdadr bullshit (as it was eloquently put) with those local functions (as the docstring from that fragment implies, basically I want to take some information from a bunch of intermittently nested lists and put it into an alist and a hash; the stuff comes from an XML file that represents the dependency graph for a build system which XMLS sexpr-izes), but if there's a better way to implement those defs I'd like to learn it :)

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
Well, IIRC this is the main form for destructuring in CL. The link on there for destructuring lambda lists explains the syntax.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Anyone going to Clojure/West this weekend?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Plorkyeran posted:

cdaddaddaar has the compelling advantage of that it's a lot more fun to say.

This is almost exactly the justification Sussman gives in the SICP video lectures.

theratking
Jan 18, 2012
Have any of you tried Arc by Paul Graham? I learned CL from his books and I've noticed he is in the process of designing this new dialect of Lisp.

From the looks of his website, it doesn't seem very popular / finished, but I was wondering if any of you have gotten around to playing with it.

shrughes
Oct 11, 2008

(call/cc call/cc)

theratking posted:

Have any of you tried Arc by Paul Graham? I learned CL from his books and I've noticed he is in the process of designing this new dialect of Lisp.

From the looks of his website, it doesn't seem very popular / finished, but I was wondering if any of you have gotten around to playing with it.

It's a hundred-year language, in that it'll take a hundred years for it to become useful.

theratking
Jan 18, 2012
That's too bad, I always liked Graham, my first foray into lisp was from his book ANSI common lisp that my teacher gave me.

I had hoped he would come up with something cool.

on a side note: do any of you have good resources for learning lisp-like macros? Is there something like defmacro in Scheme or should I just use CL.

edit: a d

Look Around You
Jan 19, 2009

theratking posted:

That's too bad, I always liked Graham, my first foray into lisp was from his book ANSI common lisp that my teacher gave me.

I had hoped he would come up with something cool.

on a side note: do any of you have good resources for learning lisp-like macros? Is there something like defmacro in Scheme or should I just use CL.

edit: a d

Scheme has macros but they're a bit different than CL. Scheme uses hygenic macros vs. CL's non-hygenic ones. There's a lot of debate about which is "better"; CL macros are simpler, but scheme's are safer.

e: Here is an FAQ about scheme's macros.

tef
May 30, 2004

-> some l-system crap ->

theratking posted:

Have any of you tried Arc by Paul Graham? I learned CL from his books and I've noticed he is in the process of designing this new dialect of Lisp.

Well, he talked about it, how important it would be, how ground changing, etc.

Then he released a bunch of lisp macros.

Notably: A bunch of lisp macros that went out of their way to *elminate* unicode support in the host language, MzScheme.

quote:

From the looks of his website, it doesn't seem very popular / finished, but I was wondering if any of you have gotten around to playing with it.

The thing is, every lisp user does this - after a certain period of time they end up writing macros, and re-writers so they can write in their own little special dialect. Paul Graham isn't unique or special in this regard.

pgroce
Oct 24, 2002

tef posted:

The thing is, every lisp user does this - after a certain period of time they end up writing macros, and re-writers so they can write in their own little special dialect. Paul Graham isn't unique or special in this regard.

By this definition, the limit of lisp as lisp approaches completion is...Haskell. :v:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Paul Graham is too busy raking in money hand over fist doing YCombinator. Can't say I would fault him for stagnating on Arc.

Dirty Frank
Jul 8, 2004

STupid newbie question time:

I've been going through the Land of Lisp and one of the examples (orc-battle) isn't working for me.

its crashing on line 54, when performing the following command:

(ash *player-strength* −1)

with the error "*** - CASE: variable −1 has no value"

I replaced this with:

(floor (/ *player-strength* 2))

which works, but I'd love to know what is actually happening here?

here is the full game

and here is the error and back trace

Edit: I figured it out, its a copy past error: minus symbol is not the same as dash symbol.

Dirty Frank fucked around with this message at 11:06 on Mar 22, 2012

Neslepaks
Sep 3, 2003

That's an awesome variable name, I'm gonna start using it.

Adbot
ADBOT LOVES YOU

Beef
Jul 26, 2004
What, the *earmuffs* ?

  • Locked thread