meta predicate - Prolog binding arguments -


in sicstus prolog, there's predicate:

maplist(:pred, +list) 

pred supposed take 1 argument - list element. how can pass 2-argument predicate, first argument defined? in other languages written as:

maplist(pred.bind(somevalue), list) 

maplist(p_1, xs) call call(p_1, x) each element of xs. built-in predicate call/2 adds 1 further argument p_1 , calls call/1. indicate further argument needed, helpful use name p_1 meaning "one argument needed".

so if have predicate of arity 2, say, (=)/2, pass =(2) maplist:

?- maplist(=(2), xs). xs = [] ; xs = [2] ; xs = [2,2] ... 

since definition in sicstus' library unfortunately, incorrect, rather use following definition:

:- meta_predicate(maplist(1,?)). :- meta_predicate(maplist_i(?,1)).  maplist(p_1, xs) :-    maplist_i(xs, p_1).  maplist_i([], _p_1). maplist_i([e|es], p_1) :-    call(p_1, e),    maplist_i(es, p_1). 

see this answer more.

just nice further example lists of lists.

?- xss = [[a],[b,c]], maplist(maplist(=(e)), xss). xss = [[e], [e, e]], = b, b = c, c = e. 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -