Re: new map type (Re: Ann: SWI-Prolog 7.1.0)

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 11/22/2013 07:00 PM, Alan Baljeu wrote:
>   - The system introduces `maps' as primary citizens.  Maps are
> 
>     collections of key-value pairs, optionally typed. Maps are
>     supported by read and write.  The syntax is
> 
>     type{key1:value1, key2:value2, ...}
> 
> 
> This will be very nice.  Incidentally in my project I have compiled 
> names into indices in class-generated objects, so I won't be needing
> the map for that.
>     Keys in a map can be addressed using the functional notation
>     Map.Key.  User functions on maps can be accessed as Map.Compound
>     (e.g., Vector.multiply(V2)).
> 
> 
> When you say functional notation, I am a little leary of confusion
> 
> regarding when something gets applied:
> plus(Map.key, 2,3) does this work?
> plus(Map.Key, 2,3) does this work?  Does it backtrack if Key is non-ground?

It is equivalent to

	get_map_ex(key, Map, V),
	plus(V, 2, 3).

(the _ex version raises an exception if key is not in Map).  This rewriting
is done by expand_goal/2.

> The notation Vector.multiply(V2) *might* be okay, but I'm skeptical.  I 

> suppose this implies:
> Vector  .multiply(V2) % good
> Vector.  multiply(V2) % error

I assume people will get used to that.

> But in any event, is there a meaning to this example, or is it a bad choice 
> of words?  The only thing I can think of is not very Prolog-like:
> 
> V2 = V1.scalar_multiply(3), or
> Number = Vector.dotProduct(V2)

Sorry, bad wording.

> Will/do other systems support maps?

I don't think it is my power to decide on that :-)  Vitor (YAP) will surely
consider this and I think is quite likely to follow.  Otherwise, I think the
`market' will decide.  Implementing all the changes was not a big deal.  If
people appreciate them in SWI-Prolog, I guess they will start asking the
other systems to consider this.  Then there could be small changes to the
various details to get a wider accepted implementation.  If you use these
features, you should be prepared to live with the idea that this might not
be the final word in all details.  I do not expect major changes from here.

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.