Micro languages in Clojure via macros and let
will.groppe.us
will.groppe.us
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.
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. (dosql [a :table1/a b :table1/b]
(filter (and (< a 5) (= b "x"))))
Makes the filter part more readable (to a Lisper), and introduces variable scope in a more idiomatic manner. The macro needs to take care of the :table1/a expansion and substitution within its scope. dosql might already be taken but not important for my point, I think.Maybe you still don't like this, but I think it reads a little better for someone used to Clojure.
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.
I'd like a language that lets me define syntax that's readable by kids with basic english/math skills.
From the languages I've tried, Boo came closest to that, but the error messages it throws are awful, and development seems to have stagnated. Maybe Perl6 will be that language, who knows?
Haskell also seems to have a macro-system, but I wouldn't call Haskell a language readable by kids.
Second point is that since the beginners know nothing, they don't have preconceived notions of what programs should look like. Having just taught an intro to programming course, I am very aware that even the semantics of something like "i = 2" can be misunderstood by beginners. One advantage of the Lisp syntax for beginners is that it's extremely simple and consistent.
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.