Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

prolog - changing list of strings to atoms using maplist?

How to change string to atoms using maplist.

This does not work :

 ?- maplist(atom_string,["a","b","c"]).

first because atom_string/2 has arity of two (How do you do partial-function//currying in prolog).

But even if partial-fun worked the complication is that the first argument of atom_string is the unknown i.e. the call is :

  atom_string(A,"atom")

not :

  atom_string("atom",A)

this worked :

?- use_module(library(lambda)).

?- F = Y^X^(atom_string(X,Y)), maplist(F,["a","b","c"],L).
F = Y^X^atom_string(X, Y),
L = [a, b, c].

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This works as intended:

?- maplist(atom_string, Atoms, ["a","b","c"]).
Atoms = [a, b, c].

If this is not what you are after, please explain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...