|
|
|
|
|
by brudgers
3449 days ago
|
|
I like Clojure. It's data-centricness is something that it shares with certain ways of programming in Common Lisp. In particular the use of lists in Common Lisp. For example, a list holding a schedule of appointments ;;; adapted from
;;; https://www.ida.liu.se/ext/caisor/archive/1978/001/caisor-1978-001.pdf
(((JAN 12 2014)
((9 15) (10 00) (SEE ANDERSON))
((10 45) (11 00) (SEE LUNDSTROM))
((13 15) (16 00) (ATTEND Y COMMITTEE MEETING)))
(((JAN 13 2014)
((9 30) (10 00) (ATTEND NEW PRODUCTS PRESENTATION)))
A lot of what Clojure brings is more efficient abstractions. For example Common Lisp has two key-value stores a-list and hash tables that Clojure collapses into one thing and then rolls together with hashes and sets as much as possible. |
|
1) Clojure prefers maps over cons cells. This means that I always know exactly what I'm looking at. I don't have to guess that the second times are the end-times...I know because it' named :appt/end.
2) We don't overload data types. Have a date? Use a date type. In the CL example we see symbols and numbers sometimes used for descriptions, sometimes for times, etc. Here in Clojure we have #inst ... which creates an actual DateTime object. Now I no longer wonder what I'm looking at, I know it's a date.
3) Clojure prefers data over DSLs. What this calendar example shows is some sort of domain specific language that not only has to be parsed by a program, but it also has to be parsed by a human.
4) Got a meeting description, use a actual string....what's up with the use of symbols as strings (I never understood that about CL).
5) From the perspective of a data modeler...in the CL example if you want a meeting to last over midnight or for longer than a day, it looks like you're sunk.
But thanks for the example, it's fun to see how data modeling is done in other languages.