NetworkVerification / nv

A Framework for Modeling and Analyzing Network Configurations
MIT License
31 stars 2 forks source link

Allow `{ x |-> y}` syntax for initializing dictionaries #64

Closed alberdingk-thijm closed 3 years ago

alberdingk-thijm commented 3 years ago

Introduction and Current Situation

Currently, we allow a user to create maps (dictionary data structures) using the NV syntax createDict v and then updating the map using m[key := e] syntax. For the special case of a map where the type of values is bool, i.e. a set, we provide additional syntactic sugar { e1, e2, ..., en } that (internally) unrolls into (createDict false)[e1 := true][e2 := true]...[en := true] and allows a user to initialize a set far more quickly. It seems useful to implement this functionality for maps which use other types of values as well. Notably, there is a syntax used when printing maps that cannot be used to create them: { x1 |-> y1\nx2 |-> y2\nx3 |-> y3 }.

Proposal

This issue proposes that we add the print formatting of maps as an additional syntactic expression that internally unrolls into a map creation followed by a series of updates, as in the case of sets. In order to handle the fact that the current print formatting does not specify the default value of the map to use when the given value is not found, this issue proposes a modification to the syntax for printing maps and for creating maps:

Benefits

Drawbacks

Considerations