Re: Some thoughts on dicts in SWIPL 7

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 02/18/2014 11:58 AM, Carlo Capelli wrote:
> 
> 
> 
> 2014-02-18 11:48 GMT+01:00 Jan Wielemaker <[email protected]
> <mailto:[email protected]>>:
> 
>     On 02/18/2014 11:27 AM, Carlo Capelli wrote:
>     >
>     > I forgot: a pattern that could be handy could be a member_dict/2, to
>     > avoid this kind of code
>     >
>     > (member(F, T.foreignKeys), F >:< _{pkCol:PkCol, fkTable:FkTable,
>     > fkCol:FkCol})
> 
>     I think I'm missing something:
> 
>     16 ?- A is _{a:1, b:2}.Key.
>     A = 1,
>     Key = a ;
>     A = 2,
>     Key = b.
> 
>     What am I missing?
> 
> 
> What I meant: porting older code, that was like
> 
> table(T, ..., ForeignKeys),
> member(foreignKey(PkCol,FkTable,FkCol), ForeignKeys)
> 
> I initially wrote
> 
> member(_{pkCol:PkCol, fkTable:FkTable,fkCol:FkCol}, T.foreignKeys),
> 
> and that worked. Then I realized that if I add a field to foreignKeys,
> it will fail...

Yes.  You mean T.foreignKeys is a list of dicts and you want to do a
member and then only get dicts that have at least a certain set of
keys?  That would apply for any extraction.  The psi-term ideas are
the way to go here, otherwise we'll end up with a (sub-)dict version
for all access predicates ...

	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.