4 ms·
Micro languages in Clojure via macros and let
- petervandijck 16y agoCool, 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.
- macmac 16y agoThat is a valid concern, although a well designed micro language will likely also reduce the code base significantly and thereby leave less to learn. If it is well constructed it will also serve as an easy way of learning about the domain which you will have to anyway.
- petervandijck 16y agoFair enough. Or, a well designed micro language may just be that, well designed but entirely unnecessary :)
- chc 16y agoEvery codebase and accompanying API is something you have to learn. If you don't want to learn, best not ever do maintenance. A "microlanguage" is just better suited to the problem domain than a normal API.
- anamax 16y ago> 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 16y agoMmm. No. It takes longer to learn a language than an API, in general. I don't think I'm wrong about that?
- s-phi-nl 16y agoSee http://paulgraham.com/progbot.html http://paulgraham.com/progbot.html
- jimbokun 16y agoIn this case, he's trying to make it more idiomatic within the surrounding Clojure code, and thus, more intuitive for the intended user.
- wilig 16y agoIn 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 16y agoMy 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.
- scott_s 16y agoBut are you complaining about Lisp syntax in general, or this DSL implemented using Lisp macros in particular?
- bad_user 16y agoBoth I think. 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.