このディレクトリの索引 # I am trying to write a procedure order(List,Result) that has a List # as input and returns a list Result of ordered pairs such that: # # the first element of the ordered pair is the position of the pair in the list, and # the second element of the ordered pair is the element # from List n the corresponding position. # Example: # # if List = [a,b,c,d], the procedure order(List,Result) # outputs the list: Result = [(1,a), (2,b),(3,c),(4,d)]. # # I am struggling with the counter for the position of the pair in the list. # I have made attempts such as: # # increment(Accum,Total):- # Total is Accum + 1. # order([],[]). # order([Head|Tail],Result):- # order(Tail, NewTail), # NewCount is Count + 1, # increment(NewCount,Count), # Result = [(Count,Head)|NewTail]. # Please help anyone? order(List,Result) :- findall((N,E),( append(L0,[E|_],List), length([_|L0],N)), Result).