简体   繁体   中英

Swi-Prolog - how to delete the second element (if exist) in a list?

I need to write a program in swi-prolog that removes the second value of a list. thanks!

I think it could be as easy as:

remove2nd([], []).
remove2nd([X], [X]).
remove2nd([X, Y|Z], [X|Z]).

where you use it as:

remove2nd([1,2,3], X).

and gives you

X = [1, 3].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM