String parsing [Turbo Prolog]

342 Views Asked by At

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.

1

There are 1 best solutions below

0
lurker On

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.