

Micro languages in Clojure via macros and let - macmac
http://will.groppe.us/post/943063292/micro-languages-in-clojure-via-macros-and-let

======
wilig
In most general of terms a programming language would be ideal for a problem
domain if the domains problems could be expressed directly in the language.
You would sit down with the domain experts and have a conversation, that
conversation could be converted directly to code. In fact if the language was
expressive enough the experts could express the problems directly to the
computer. No current language, that I'm aware of, achieves this goal. However
Clojure by nature of it being a Lisp, allows you to easily add to the language
to bring it closer to the domain it will be used in.

It's certainly no silver bullet, and does add to the learning curve of new
programmers, but if used properly can be a great tool for writing concise and
correct code.

~~~
bad_user
My problem is that the code linked in the article looks ugly as hell. Even the
micro-language created.

Compare this ...

    
    
        (filter (and (< :table1/a 5) (= :table1/b "x")) (collect :table1))
    

To this ...

    
    
        from row in table1
        where row.a < 5 and row.b == "x"
    

Also, compare this ...

    
    
        (collect :projects :invoices [:projects/id :projects/name 
               (as :inv_id :invoices/id) :invoices/date])
    

To this ...

    
    
        from proj in projects
        from inv in invoices
        select { proj.id, proj.name, inv_id => inv.id, inv.date }
    

For me the ideal programming language would be one readable by humans.

~~~
shaunxcode
But can the sql be made to work w/ a non-sql storage engine? The lisp code
facilitates this abstraction while raw sql is just that.

~~~
bad_user
That's not sql ... that's Linq from .NET. You can query with it whatever you
want: in-memory data-structures, DB, Xml, LDAP.

Here's a MongoDB provider that has basic Linq support:
<http://github.com/samus/mongodb-csharp>

Of course, the actual syntax of LINQ is baked in the compiler's rules, and you
can't invent new syntax in the way LISP lets you to.

But why is that have to be the case? There's nothing stopping a compiler from
being extensible, other than hard-work. I played with Boo for a month ... it
comes very close to that. Perl6 also lets you do it, but it remains to be seen
how good it is.

~~~
shaunxcode
touche, I should have studied your examples longer as the second one it is
clearly not straight sql. I have always been a bit jealous of linq and I agree
there should be a language which allows the compiler to be extended. Smalltalk
allows this to some degree particularly the research done by SCG:
<http://scg.unibe.ch/research/helvetia/examples>

------
petervandijck
Cool, but what about code maintainability? Why add microlanguages? I'm sure
your microlanguage is superintuitive to you, because you wrote it, but I, as a
new coder on your code, don't want to learn it.

~~~
anamax
> I'm sure your microlanguage is superintuitive to you, because you wrote it,
> but I, as a new coder on your code, don't want to learn it.

I'm sure your API is superintuitive to you, because you wrote it, but I, as a
new coder on your code, don't want to learn it.

I'm sure your library is superintuitive to you, because you wrote it, but I,
as a new coder on your code, don't want to learn it.

~~~
petervandijck
Mmm. No. It takes longer to learn a language than an API, in general. I don't
think I'm wrong about that?

