Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: simple arithmetic expressions #289

Open
jknack opened this issue Mar 27, 2015 · 6 comments
Open

feature request: simple arithmetic expressions #289

jknack opened this issue Mar 27, 2015 · 6 comments

Comments

@jknack
Copy link

jknack commented Mar 27, 2015

It will be awesome if we could do simple arithmetic expressions. A good example of this is a dynamic thread pool configuration based on the number of available processors:

threads.max = ${runtime.processors} + 1

I realize it is probably tricky to implement, but probably you can implement in lisp or prefix notation:

threads.max = (+ ${runtime.processors} 1) // or

threads.max = + ${runtime.processors} 1

I'm looking for a simple arithmetic evaluator (not a complex or full expression language)

Thanks

@havocp
Copy link
Collaborator

havocp commented Mar 30, 2015

Thanks for the suggestion. This is a slippery slope I'm not super comfortable with. I don't want to end up defining and maintaining a programming language ... in most cases (if everything follows the suggested conventions in the docs and examples) you could write code in your real programming language to merge in stuff like this.

@cprice404
Copy link

+1 on avoiding that slippery slope :) hocon can already do a ton of things and supporting all of them makes it more difficult to port it to other languages.

@wxiang7
Copy link

wxiang7 commented Feb 15, 2016

+1 for this awesome feature, which helps a lot especially when we need some basic date calculation in configuration files.

GCL, the internal general configuration language from Google would be a good example for this feature.
There's no public spec sheet for this language, but this thesis could be helpful GCL Viewer
and more simpler jsonnet

@mrubin
Copy link

mrubin commented Jul 30, 2018

+1 for this request. See Terraform for an example.

@havocp
Copy link
Collaborator

havocp commented Jul 30, 2018

I almost think a better path would be to allow dropping in extra jars to add support for YAML, Jsonnet, etc. - some discussion of that in #169 - bonus, that's probably a good bit easier to implement than adding an expression language to HOCON.

Arithmetic expressions on their own are a lot of specification, but then the "not a programming language" principle that keeps HOCON at a fixed-ish size and complexity level has also been dropped, and it's unclear what the replacement principle is.

https://blog.ometer.com/2015/09/07/json-like-config-a-spectrum-of-underoverengineering/ talks about this some.

to be clear, it's a bit academic because even if I loved the extend-HCON-with-expressions idea I definitely don't have time to do it and don't think it would be easy for anyone to do...

@jimmydevine
Copy link

+1 - Just throwing in my 2 cents as my configuration needs include offsets which depend on other offsets, such as
START_AUX_OFFSET = 100
AUX_FIELD_OFFSET = ${START_AUX_OFFSET} + 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants