Re: "dict"ionary typing?
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 11/26/2013 05:16 PM, Alan Baljeu wrote:
> dict and tag are my prefered words.
Thanks. I think I'll go for these. We can have endless arguments,
but at some point we'll have to make a decision and stick with it.
> I guess there are two main uses for a dict:
> a) as a struct where there are fixed elements of varying types.
> b) as a map where there are variable elements of fixed types.
Not sure I get that.
> On another note, I've been thinking the functions should restrict the type of dictionary they operate on.
>
> M.multiply(F) := point{x:X, y:Y} :-
> X is M.x*F,
> Y is M.y*F.
>
> M should be a point. �But how can I make this explicit? �In fact my preference would be this sort of syntax:
That is explicit because this `function' is defined in the module
'point'. Modules play a role to dicts, similar as they do to
attribute names in attributed variables.
Cheers --- Jan
> multiply(point{x:X0, y:Y0},F, point{x:X, y:Y}):-
> X is X0*F,
> Y is Y0*F.
>
> ?- Point = point{x:3, y:4}, P2 is Point.multiply(3).
>
> or,�
> :- type_decl multiply(point{}, number, point{}).
> multiply(In,F,Out) :-
> Out.x is In.x *F,
> Out.y is In.y *F.
>
> and then also have type declaration for dict. �
>
> Alan Baljeu
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog