Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Lisp (Clojure) and Tcl compare in terms of abstraction and metaprogramming abilities?

Tags:

clojure

lisp

tcl

Both seem to be good for building extensible API's and code generation.

What are the main differences between them?

What do you see as their strengths, weaknesses, ...

like image 634
StackedCrooked Avatar asked Apr 27 '11 18:04

StackedCrooked


2 Answers

Disclaimer: I'm more familiar with Clojure than Tcl so apoligies to any Tclers if I misrepresent anything. However here are some points I'm generally aware of:

  • Both are extremely flexible - you can use meta-programming to generate and execute pretty much any code you like at runtime.
  • Clojure is a JVM language whereas Tcl is relatively standalone.
    • Advantages of being on the JVM include being able to generate interoperable code for and act as a DSL for libraries in other JVM languages like Java and Scala. Also you get access to the huge range of Java libraries.
    • Disadvantage of being on the JVM is relatively substantial start-up time. So you'd probably prefer Clojure for longer-running server applications rather than command line tools that need to execute quickly.
  • Clojure metaprogramming will get compiled to native code (via JIT in the JVM). Will depend on your application, but I expect this will perform faster than Tcl in most circumstances
  • Both languages are dynamic (a good thing for metaprogramming on average!) and support functional programming
  • Clojure contains some interesting abstractions that are very useful for metaprogramming - in particular the considerable in-language support for sequences
  • I personally find the simlicity of Lisp syntax to be a great advantage for metaprogramming - it's much easier to generate code when there is only one syntactical construct (the s-expression) to worry about...

On average both languages are great for metaprogramming, but if I was choosing between the two:

  • I'd choose Clojure if I was building a server-side application or if I had a particular need for JVM interoperability
  • I'd choose Tcl if I wanted a DSL for managing scripts / tools at the command line
like image 170
mikera Avatar answered Oct 25 '22 22:10

mikera


I think mikera's answer is excellent.

I would add only that where in clojure metaprogramming tends to focus on macros, a grand unified metaprogramming solution without peer, tcl has several small sharp tools available for metaprogramming, among them the "unknown" command, which can be used to do all sorts of nifty tricks. Also interesting is that even though clojure has only a small number of keywords or "special forms", tcl actually has none, which sort of makes tcl it's own dsl, and changing (or extending) the behavior of any command is possible.

One thing i have to disagree with from mikera's answer is the part about clojure's syntax being more amenable to metaprogramming. One of the unpleasant surprises for me when coming to clojure is actually how much syntactic variation there is in clojure, with the various uses of () [] {} "" ^{} #' :key ... and on and on. I totally grok the justification of this type of syntactic sugar, but i actually find tcl's syntax easier to deal with for "ham-handed" metaprogramming and code generation. And tcl's "everything is a string" nature adds to the simplicity.

As for mulit-processing capabilities, immutable data structures, purely functional nature and many other instances of clojure's distinctives, there really is nothing comparable in tcl.

I couldn't agree more with mikera's conclusion.

like image 26
user271608 Avatar answered Oct 25 '22 22:10

user271608