As a continuation of Using Lisp or Scheme for runtime configuration of Java programs, I am looking at having a Java property file "replacement" which can contain code in addition to plain Java strings. Java property files look like:
key1=value1
key2=value2
...
For fun I am playing with an elderly JScheme (due to size) but came to think of that it would be useful to have a file format that would be compatible with Clojure. This would allow the usage of the same syntax for just small "read my configuration"-usages as well as larger systems using Clojure. The idea is then that the values can now be evaluated instead of just being static strings.
I am not very experienced with Scheme or Clojure, but it appears that vector is available in both, but the short-cut syntax is different (#(...) compared to [...]).
Is there a syntax for representing a "Java property" data structure which is both valid Scheme and Clojure programs? Please show actual code.
EDIT: After looking at the (props ...) suggestion and brushing up my Lisp skills some more with ELisp and JScheme, I found that
(list
"key1" "value1"
"key2" "value"
)
might be the simplest way to do this with a syntax not too far from a property file.
Assuming you don't want to create scheme reader macros to read clojure map literals (and clojure doesn't support custom reader macros), how about defining a "props" function:
(props 'key1 value1 'key2 value2 ...)
Now in clojure define props as
(def props hash-map)
and similarly in scheme, then you can just eval the props expression in either language.
you can get a bit more funky and make props a macro that quotes the keys (assuming the keys are symbols) or leave it as is and get more flexibility at the cost of having to quote the keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With