google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.98k stars 440 forks source link

adjacent object literals vs adjacent variables #1110

Open dcopso opened 1 year ago

dcopso commented 1 year ago

I'm new to jsonnet and I'm loving it but I see a behavior that I'm surprised by: the + between object literals seems to be optional, but only on object literals:

This program is valid:

{a:1} {b:1}

This program is not:

local left = {a:1};
local right = {b:1};
left right

Changing left right to left + right makes the program valid.

This suggests that variables are not transparent in the same way that functions are. Is this expected?

Also, what is going on with {a:1} {b:1}? Why is that, and expressions such as {}{}, valid?

Thanks!

dcopso commented 1 year ago

This has also been raised in the discussion forum: https://groups.google.com/g/jsonnet/c/RoJIt5vlwX4

CertainLach commented 1 year ago

This is sugar for object coming right after any other expression, it desugars to a + b

Relevant part of the specification: $desugar{expr}(e { objinside }, b) = desugar{expr}(e + { objinside }, b)$