Now with maps and structs! #11
burakemir
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
And our first announcement: Mangle has maps and structs. These are useful for representing structured data, similar to JSON or protocol buffers.
Proper documentation is in the works, but in short, there are built-in functions
fn:map
andfn:struct
which construct maps and struct constants. Until then, you may want to check out some unit tests.A map expression is simply an apply expression
fn:map( key_1, val_1, ..., key_n, val_n)
with a convenient syntax[ key_1 : val_1, ..., key_n : val_n ]
. A type expression for map types isfn:Map(Key, Val)
and it conforms to .fn:Map(Key2, Val2)
ifKey2
conforms toKey1
andVal1
conforms toVal2
.Structs are written
fn:struct( key_1, val_1, ..., key_n, val_n)
with a convenient syntax{ key_1 : val_1, ..., key_n : val_n }
A type expression for struct types isfn:Struct(key_1, Val_1, ..., key_n, Val_n)
where eachkey_i
is a name constant, and it conforms to another struct type if it is "longer" and has conforming values for matching keys.In both cases, the convenient syntax is shorthand for the apply expression (it still involves a function symbol). Any rule that involves apply expressions could construct an unbounded number of tuples (unlike a proper datalog rule), and one has to be careful about non-termination.
Accessing data from maps and structs happens with the new built-in match predicates
:match_entry(Map, Entry, Value)
(for maps) and:match_field(Struct, Key, Value)
or by checking equality.Beta Was this translation helpful? Give feedback.
All reactions