from Hacker News

Idiomatic Clojure with LightTable

by imdhmd on 11/18/13, 1:22 PM with 56 comments

  • by ibdknox on 11/18/13, 6:40 PM

    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.
  • by jonase on 11/18/13, 2:33 PM

    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.
  • by jcrites on 11/18/13, 10:23 PM

    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?

  • by dopamean on 11/18/13, 3:37 PM

    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.
  • by peatmoss on 11/18/13, 2:54 PM

    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.
  • by wuschel on 11/18/13, 3:40 PM

    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.
  • by owenjones on 11/18/13, 3:32 PM

    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.

  • by lispm on 11/18/13, 8:22 PM

    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

  • by senand on 11/18/13, 3:21 PM

    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.

  • by agumonkey on 11/18/13, 3:09 PM

    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.
  • by owenjones on 11/18/13, 7:38 PM

    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?

  • by vorce on 11/19/13, 9:00 AM

    I imagine this could be super powerful for Elixir as well (which has awesome meta programming capabilities).
  • by JPKab on 11/18/13, 2:44 PM

    I'm reminded of the recent "What 4Chan thinks of HN":

    "Article that is actually interesting" 0 comments

    This is awesome. Thanks for sharing.