Mapargs/3?

Dear Jan,

The common denominator is that they are both collections of items and although
a compound is of fixed length, predicates that manipulate might be generic enough
to apply to multiple lengthed compounds (depending on operation).

Specifically what is your argument against length( foo(x,y), 2 ) ?

Going back to the original question, what is your argument against
?- map( plus(1), [1,2,3], [2,3,4] ).
?- map( plus(1), a(1,2,3), a(2,3,4) ).

?

Regards,

Nicos Angelopoulos

Well, possibly that is in the lack of typing in Prolog. This type of overloading is key in object oriented languages. For strongly typed languages this leads to no runtime overhead and typically also not to mistakes either as if the object was of some unexpected type it will surely be noticed somewhere along the line. Prolog however is untyped. This implies the above is a runtime switch and misses an opportunity to find errors easily.

A second problem is that if you go this route you probably want to be able to extend this and define map/3 to work on new data types, no? That however is something Prolog cannot do in a sensible way (at least, I only see a couple of rather inelegant ways). Logtalk can do this.

I think that is why I prefer maplist/3 and mapargs/3. I do agree that both approaches have their pros and cons.

1 Like

Multifile hook predicates. :grin::clown_face:

Anyway, I vote for mapargs/3.

2 Likes