News for hackers. Stuff that matters.
Re:Idiomatic Clojure with LightTable by ibdknox on Monday November 18, 2013 @01:40PM (#6755975)
I think this is one of my favorite features that we've added to Light Table recently and it shows one of the benefits of being connected to a running process of the language you're working with: you can use the tools of that language to write code for you. There's nothing that makes this Clojure specific - you could do these same things in any other language too.
Re:Idiomatic Clojure with LightTable by DanielRibeiro on Monday November 18, 2013 @01:51PM (#6756049)
OP here: thanks Chris for the amazing capabilities in Light Table. It is the piece of software I'm most excited about these days.
Re:Idiomatic Clojure with LightTable by ibdknox on Monday November 18, 2013 @02:22PM (#6756270)
You are quite welcome! And that's what I love to hear - we're pretty excited too :)
Re:Idiomatic Clojure with LightTable by owenjones on Monday November 18, 2013 @02:36PM (#6756361)
Just had his conversation with a coworker, I've never felt comfortable editing any of the my other IDE's including my favorite VIM.

Lighttable's datastructure based configuration makes it so nice.

Thanks Chris & Co. keep up the awesome!

Re:Idiomatic Clojure with LightTable by peterashford on Monday November 18, 2013 @10:32PM (#6759095)
Emacs has made people comfortable modifying it for decades.
Re:Idiomatic Clojure with LightTable by Derbasti on Monday November 18, 2013 @01:50PM (#6756042)
I would imagine that it works particularly well for lisps, since lisps can easily transform running code to source code and vice versa.
Re:Idiomatic Clojure with LightTable by ibdknox on Monday November 18, 2013 @02:09PM (#6756192)
actually the tools for doing this in other languages have gotten a lot better than they used to be. Using esprima you can do some pretty neat code rewriting in JavaScript and Python includes ast tools in the standard lib. Plus if more new languages start to include things like gofmt by default then we'll end up with more of this stuff as first class. Either way though, it's nearly always the case that the platform itself has the best tools for doing this, so at the very least if gives you the best possible chance. :)
Re:Idiomatic Clojure with LightTable by jonase on Monday November 18, 2013 @09:33AM (#6754425)
If someone is interested in how kibit is implemented I've got some slides at http://jonase.github.io/kibit-demo/. It's quite easy and a good (I think) introduction to core.logic.
Re:Idiomatic Clojure with LightTable by jcrites on Monday November 18, 2013 @05:23PM (#6757598)
Does LightTable have autocompletion for Clojure or might it in the future?

How does autocompletion work for Lisp-like languages? I'm wondering if the verb-subject ordering makes it more difficult to build effective autocompletion.

In languages with a syntax like C, code phrases benefiting from autocompletion focus on a particular thing in subject-verb-object order:

  obj.method(param);
Consequently I can engage auto-completion by typing the following, where <cursor> is the location of the text cursor in the editor:

  obj.<cursor>
I type variable name and the "dot" (or equivalent), and the IDE can make informed suggestions about methods to show: methods defined on obj, or methods taking obj's type as their first input.

When writing code, I usually know what object I'm working on (autocompleting the variable name is useful but not crucial, since it's usually on preceding lines). What I want to know, and the area in which autocompletion helps me most, is finding out what methods are relevant to that specific object (e.g. defined by the object).

When I'm writing quick prototype code, I use an approach that's almost like single static assignment:

  A a = new A();
  B b = a.foo();
  C c = b.bar();
Using autocomplete, I can explore objects and methods while staying within the IDE. When combined with in-IDE documentation, writing new code is extremely effective.

How do you effectively autocomplete in a Lisp language?

  (<cursor>
If I type that, there's no object yet, so what autocompletions can show up? A list of all functions?

  (<cursor> obj ...)
If I type this line and move my cursor back to the first parenthesis, then it makes sense that autocompletion could understand the context, but moving the cursor backwards is inconvenient. It's not a fluent way to write code.

I have not used autocompletion in Lisp-based languages. How do IDEs or REPLs solve this problem? It seems like a similar problem will affect pure-style functional programming languages like Haskell. Static typing is not the criterion, since Python has effective REPL autocompletion.

Does the lack of a natural opportunity to present relevant autocompletion information inhibit the development of advanced editors for these languages?

Re:Idiomatic Clojure with LightTable by lemming on Monday November 18, 2013 @08:39PM (#6758660)
I'm not sure how LightTable works, but I can talk about how it works in Cursive. There's really not a lot of magic but there are a lot of tricky details. It seems like you're mostly talking about object method calls there - you're right that in the most common case (start typing the method name without putting the object after it first) you really can't do much. Currently in that case we propose all methods for all available classes, which is everything in java.lang and everything that's imported - I think most Clojure solutions do this. However this still misses some cases like (warning: totally invented api):

  (let [entry (.getEntry my-map)
        key   (.getK|
Here you can't easily tell that you want the key of your map entry here since the MapEntry class isn't imported. I'm planning some improvements where I'll walk up the AST from the completion point and get the types of all variables on the way and propose all methods from them, but that requires type inference which I don't have yet (although it's on the list). IntelliJ has also really shown how you can push the bar here with some lateral thinking, they propose chained method calls etc based on the type, so there's a lot of cleverness you can do with a little thought (and a good test suite).

Completion for functions etc is obviously easier although in the case of protocols the problem is similar - you'll get all the protocol methods suggested since they're just fancy functions, but you won't get proper context-sensitive completion unless you've put the object implementing the protocol after the symbol you're completing - the most you can hope for is some sort of error message later that what you've entered doesn't look consistent.

Edit: one thing I forgot to mention is that in the completion list for methods we show the full signature as well as the list of all classes that have a method with that signature, which helps a lot in choosing the right method.

Re:Idiomatic Clojure with LightTable by chongli on Monday November 18, 2013 @07:52PM (#6758467)
Erik Meijer has complained about this in the past. The answer is that it require a change in thinking. Object-oriented programming encourages the programmer to think about objects first (duh) and later ask what methods are available to them. Functional programming is the opposite. You think of the verbs first; the nouns themselves are interchangeable. So the simple answer is this:

    (fo<cursor>
Pressing tab (or whatever invokes your auto-complete) would pop up a list of options such as this:

    (foo
    (foo-bar
    (foo-bar-baz
As for exploration, Clojure has tools such as doc and find-doc to help you search for a particular function.
Re:Idiomatic Clojure with LightTable by seanmcdirmid on Tuesday November 19, 2013 @07:51AM (#6760779)
So the noun is encoded after the verb. I've seen scheme libraries like this, and makes me wonder there really are some non trivial purely verb libraries out there for functional languages?
Re:Idiomatic Clojure with LightTable by d0m on Monday November 18, 2013 @08:00PM (#6758497)
Although I see your point, I think it's being a bit unfair because I could tell you the same thing:

  new <cursor>
What would tab show you? All the possible objects?

You at least need a base to get started.. in lisp, it's not uncommon to have functions defined as (character-move), so (character-<tab>) works well. But even without that, since lisps use functions at its root instead of objects, it makes sense to know the ones you want to use.

Re:Idiomatic Clojure with LightTable by dopamean on Monday November 18, 2013 @10:37AM (#6754762)
I've been wanting to learn Clojure and recently bought the book Clojure Programming (not to be confused with Programming Clojure) and I'm curious to know if others believe it is a good idea for a Clojure novice such as myself (lisp and JVM novice too) to use kibit while learning. Any advice would be greatly appreciated. Thanks.
Re:Idiomatic Clojure with LightTable by dandrews on Monday November 18, 2013 @11:33AM (#6755091)
You're new to Lisp and JVM? (Perhaps new even to Emacs?) The activation energy required to get going in Clojure can be a bit daunting. Cool tool that it may be, I think that kibit should wait until you can drive around with some confidence. Premature optimization and all that, y'know.
Re:Idiomatic Clojure with LightTable by dopamean on Monday November 18, 2013 @11:59AM (#6755282)
Yup, new to Lisp and JVM. All of my experience, brief as it has been, is in Ruby. I've only taken a cursory glance at the book I purchased and frankly I think I'll be ok picking up Clojure. It just may require a lot of focus. Is Emacs the typical editor Clojuristas use? I use vim though I have recently switched to Sublime.
Re:Idiomatic Clojure with LightTable by cliftonk on Monday November 18, 2013 @12:19PM (#6755425)
I use emacs for anything with S-expressions and vim for everything else, but you should be careful with information overload. It's very easy to get started with LightTable if you want to play with Clojure, so I'd recommend that approach to work through book examples.

If you're new to Lisp, I'd recommend working through Land of Lisp [1], and pg's On Lisp [2] in order. They're both Common Lisp books, but they will introduce you to and expand your mind on (respectively) what's possible with all the power Lisp gives you. Virtually everything you learn in those books will be very nice tools to have in your toolbox as a Clojure dev.

As for the best starting Clojure book, Clojure Programming [3] is excellent. It has great OOP -> FP examples, is fairly extensive and well-written.

[1] http://landoflisp.com [2] http://www.paulgraham.com/onlisptext.html [3] http://www.clojurebook.com

Re:Idiomatic Clojure with LightTable by trevorhartman on Monday November 18, 2013 @12:38PM (#6755578)
https://github.com/tpope/vim-fireplace is where it's at for vim/clojure tools.
Re:Idiomatic Clojure with LightTable by cjo on Monday November 18, 2013 @12:22PM (#6755453)
I've heard good things about using emacs-live (https://github.com/overtone/emacs-live) to get you up and running quickly.
Re:Idiomatic Clojure with LightTable by cliftonk on Monday November 18, 2013 @01:19PM (#6755823)
+1 for emacs live
Re:Idiomatic Clojure with LightTable by leephillips on Monday November 18, 2013 @12:09PM (#6755354)
Vim can work very well with Clojure (I use it). Look into ScreenSend, which lets you send code from the editor to a repl. You can use it with Python as well, and anything with interactive evaluation. You might also want to install paredit, which keeps your parentheses sorted out for you.
Re:Idiomatic Clojure with LightTable by jballanc on Monday November 18, 2013 @12:28PM (#6755488)
Correction, you must install paredit (and spend half a day familiarizing yourself with how it works). It'll make your learning experience 10x easier.

As for Emacs vs Vim, I also use Vim for Clojure development. There's definitely a bias toward Emacs in the community, but that doesn't mean that you have to go with Emacs. In fact, there are now useful plugins/packages to work with Clojure in Vim, Sublime, IntelliJ, Eclipse, as well as Emacs. There's even two editors written in Clojure itself: Clooj (https://github.com/arthuredelstein/clooj) and the afore-linked LightTable.

Re:Idiomatic Clojure with LightTable by edoloughlin on Monday November 18, 2013 @06:50PM (#6758181)
Correction, you must install paredit

Or the newer Smartparens: https://github.com/Fuco1/smartparens/wiki

Re:Idiomatic Clojure with LightTable by michaelsbradley on Monday November 18, 2013 @06:49PM (#6758174)
(> smartparens paredit) ;; true

https://github.com/Fuco1/smartparens

Re:Idiomatic Clojure with LightTable by wuschel on Monday November 18, 2013 @10:45AM (#6754806)
(Confession: I am a novice to clojure/scheme/JVM myself.)

I admit that I have not tried kibit yet. However, LightTable/REPL is a great tool for this endeavour. If only clojure could have an error tracking report that would be comparable to the wonderful implementation that can be found with the python IDLE.. but I guess that is too much to ask?

Re:Idiomatic Clojure with LightTable by mrgoldenbrown on Monday November 18, 2013 @10:49AM (#6754825)
Can you elaborate on what you mean by "error tracking report" in IDLE? Either I'm missing something cool about IDLE or I am totally misunderstanding. Thanks!
Re:Idiomatic Clojure with LightTable by wuschel on Monday November 18, 2013 @10:54AM (#6754852)
Sorry, what I meant was the TraceBack. It helped a great deal when learning programming and hunt those nasty bugs:

  Traceback (most recent call last):
    File "C:/Users/wuschel/Desktop/error-track.py", line 3,   in <module>
      newstrin = teststrin + 3
  TypeError: cannot concatenate 'str' and 'int' objects
In clojure, you get those error reports in java lingo - I don't know how fast you can get use to that kind of error messages when you do not know Java. Now, this one is obvious, but it just should serve as an example:

  clojure.lang.Compiler$CompilerException: 
  java.lang.RuntimeException: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: b in this context, compiling:(null:4:1)
Re:Idiomatic Clojure with LightTable by mrgoldenbrown on Monday November 18, 2013 @11:02AM (#6754900)
OK, this makes sense. I'm slightly disappointed though, I was hoping to learn a secret new python feature :)
Re:Idiomatic Clojure with LightTable by mseebach on Monday November 18, 2013 @10:41AM (#6754785)
Kibit looks neat, I haven't tried it. I think the generally applicable advice is to get comfortable with the core first, then add tools and libraries at the speed you're comfortable with, making sure that you understand what each component does.
Re:Idiomatic Clojure with LightTable by cgag on Monday November 18, 2013 @05:01PM (#6757424)
Running `lein kibit` is super low effort once you've got lein set up, and even having used clojure for years it still reminds of features of clojure.core that I forgot pretty regularly. I think as a noob it would really help you in learning the core lib.
Re:Idiomatic Clojure with LightTable by sandbags on Monday November 18, 2013 @11:18AM (#6754991)
I cannot see any problem with using kibit.

Quite often my experience when learning a new language is "Am I doing this right? Or even close to right?"

If kibit can turn your code into idiomatic Clojure then you have a tool for exploring your solutions and how close they look to Clojure as it might be written by a native.

It can also prompt questions "Why do it this way rather than this way?" which could be a good learning opportunity.

I see no harm, only benefit.

Matt

Re:Idiomatic Clojure with LightTable by cjo on Monday November 18, 2013 @12:07PM (#6755336)
I think it would only be good if its used as a learning tool and not a code-writing tool, compare:

write the best code you can -> run kibit -> spend an hour reading the docs and every blog post you can find about a feature you didn't know about -> repeat

write the best code you can -> run kibit -> show off your awesome code, you're a rockstar!

Re:Idiomatic Clojure with LightTable by sandbags on Monday November 18, 2013 @12:17PM (#6755406)
I agree with you although I think that's an unlikely scenario.

kibit, so far as I understand it, is a pattern matching solution that can replace one structure with another - more idiomatic - structure. It doesn't add anything and, hence, can't actually solve your problems for you.

Re:Idiomatic Clojure with LightTable by Anderkent on Monday November 18, 2013 @01:26PM (#6755884)
Well, the problem comes up when it gives you proposals that are not equivalent, because it doesn't understand macros and/or local scope :)
Re:Idiomatic Clojure with LightTable by Edmond on Monday November 18, 2013 @11:50AM (#6755214)
You could try our product (www.crudzilla.com)

here's a short video demoing coding in clojure and other jvm languages:

http://www.youtube.com/watch?v=AqeOS2hqtMg

Re:Idiomatic Clojure with LightTable by miloshadzic on Monday November 18, 2013 @07:24PM (#6758336)
It's easy to get carried away with everything. My advice: start with an editor you know and use everything vanilla. You'll appreciate better tools more once you spend some time and get a feel for the pain points.
Re:Idiomatic Clojure with LightTable by peatmoss on Monday November 18, 2013 @09:54AM (#6754531)
That is quite impressive. I wish I'd have known about kibit 6 months ago. Since I'm still a Clojure novice, I guess I still stand to benefit from it. Moving from "can bang out technically workable code" to "effectively uses the whole range of core functions" is a long slog. Next time I'm writing Clojure I'll definitely be running kibit over it.
Re:Idiomatic Clojure with LightTable by wuschel on Monday November 18, 2013 @10:40AM (#6754778)
I find LightTable to be a great tool when it comes to get a first impression of clojure. Installing, configuring and getting the grasp of emacs, or configuring Sublime Text with SublimeREPL can be a lot of hassle under Windows based OS. LightTable helped me to save a lot of time here.
Re:Idiomatic Clojure with LightTable by owenjones on Monday November 18, 2013 @10:32AM (#6754734)
This is awesome, I've been excited about Lighttable since I first heard of it. I wish it was in time to back it.

It get's better with every release, can't wait for the finished product.

Re:Idiomatic Clojure with LightTable by lispm on Monday November 18, 2013 @03:22PM (#6756708)
Not to mention that Symbolics Zmacs already did this. It for example has code conversions built-in to change code between various UI libraries or Lisp variants.

ftp://ftp.ai.sri.com/pub/mailing-lists/slug/930331/msg00240.html

Re:Idiomatic Clojure with LightTable by senand on Monday November 18, 2013 @10:21AM (#6754684)
That's awesome, thanks for sharing!

I hope that with the recent addition of plugins, LightTable will also be able to provide code inspection à la IntelliJ IDEA, since that's the feature I miss most.

Re:Idiomatic Clojure with LightTable by lemming on Monday November 18, 2013 @04:27PM (#6757168)
shameless plug

You could try Cursive (http://www.cursiveclojure.com). It's pretty new but it's based on IntelliJ so we get a lot of features for free. We don't have a lot of inspections yet but they're coming soon (including kibit-in-the-editor type inspections).

Re:Idiomatic Clojure with LightTable by agumonkey on Monday November 18, 2013 @10:09AM (#6754606)
going off-road: more and more I wish for non lisps in s-exp syntax, so you can reuse pattern matching on ast and other niceties.
Re:Idiomatic Clojure with LightTable by S4M on Monday November 18, 2013 @10:38AM (#6754767)
Re:Idiomatic Clojure with LightTable by cjo on Monday November 18, 2013 @10:57AM (#6754873)
thing is if you take a modern language and add s-expressions, then you may as well add macros and at that point there's a good chance it just became a lisp

If you go here (http://www.paulgraham.com/icad.html) and search for the heading 'What Made Lisp Different' it may better explain it

Re:Idiomatic Clojure with LightTable by agumonkey on Monday November 18, 2013 @11:44AM (#6755176)
I guess Racket amongst other things makes me want a lisp system with languages as lib-dsl sharing s-exp syntax.
Re:Idiomatic Clojure with LightTable by chongli on Monday November 18, 2013 @12:03PM (#6755311)
S-expressions (or lack thereof) basically define a language as being a lisp or not.
Re:Idiomatic Clojure with LightTable by klibertp on Tuesday November 19, 2013 @03:56AM (#6759982)
You don't need s-exps to have pattern matching on ast or macros, especially hygienic, pattern based ones. There's sweet.js and macros for python as examples. All you really need is an API for manipulating AST, be it built-in or 3rd party. S-exps are especially nice if you want defmacro-style macros, but I don't believe they should be used very much.
Re:Idiomatic Clojure with LightTable by owenjones on Monday November 18, 2013 @02:38PM (#6756382)
Hmm every form I try and evaluate seems to be reduced to a one line function. Is this working as intented?

Even in the example given it's reduced the function to a 1 liner, I assumed because it was short enough that it's still legible. Is this trying to tell me my functions are too long?

Re:Idiomatic Clojure with LightTable by ibdknox on Monday November 18, 2013 @02:42PM (#6756423)
Clojure doesn't have a real code formatter unfortunately. I posted a slightly better version that preserves formatting if nothing changes and tries to use the clojure pprinter to format as best as it can.
Re:Idiomatic Clojure with LightTable by vorce on Tuesday November 19, 2013 @04:00AM (#6760001)
I imagine this could be super powerful for Elixir as well (which has awesome meta programming capabilities).
Re:Idiomatic Clojure with LightTable by JPKab on Monday November 18, 2013 @09:44AM (#6754487)
I'm reminded of the recent "What 4Chan thinks of HN":

"Article that is actually interesting" 0 comments

This is awesome. Thanks for sharing.

Re:Idiomatic Clojure with LightTable by sejje on Monday November 18, 2013 @10:12AM (#6754622)
It's probably super relevant that the percentage of the community who has the ability to comment about neat Clojure code is extremely limited (1% maybe? perhaps even less) compared to the percentage that can comment on some techno-political drivel.
Re:Idiomatic Clojure with LightTable by peatmoss on Monday November 18, 2013 @09:55AM (#6754538)
To be fair, the article is only an hour old, and it's not even seven o'clock on the left coast.
Re:Idiomatic Clojure with LightTable by thejosh on Monday November 18, 2013 @10:56AM (#6754870)
you posted this pretty quick after the article. come back after a day to see if it actually turns out that way :)
Re:Idiomatic Clojure with LightTable by username223 on Monday November 18, 2013 @10:21AM (#6754681)
To be fair, the author should probably have added "GitHub", "GooGle", and a couple of other keywords to maximize ROI.