Have a list of users. Need to enter a character and find all users whose name starts with this character.
!!! The following tasks embedded predicates conversion symbols and lines are not used.
You could do this:
name_starting_with(C, Name) :- % Names that start with C
char_code(C, CC), % Get the character code for C
name([CC|T]), % Query names that start with C (code CC)
atom_codes(Name, [CC|T]). % Convert the found character codes to an atom
On backtrack, this should return each matching name until there aren't any more.
char_code/2
and atom_codes/2
are ISO predicates, but I don't know if Turbo Prolog supports them.
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.