Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

修改List的第i项---replace谓词

向下  留言 [第1页/共1页]

1修改List的第i项---replace谓词 Empty 修改List的第i项---replace谓词 周一 三月 26, 2012 2:40 pm

Mercury Liao


Admin

replace(+List, +Index, +With, -ListOut)

List中的第Index项以原子With替换掉,并将结果输出至ListOut

代码:
replace(List, Index, With, ListOut) :-
  Idx is Index - 1, length(Before,Idx),
  append(Before, [_Discard|Rest], List),
  append(Before, [With|Rest], ListOut).


例:

?- replace([w,o,m,a,n],4,e,Output).
传回 Output = [w, o, m, e, n].



适用的Prolog版本:SWI-Prolog

http://prolog.longluntan.net

返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题