0
votes

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
The following tasks embedded predicates conversion symbols and lines are not used. What does that mean? And can you show some code? This question lacks a lot of essential information, like what form does the "list of users" come in? - lurker
Here is my code: gist.github.com/OlshevskyR/9050037 Need to solve the problem without using the built-in predicates for strings, such as: substr, frontchar, concat, etc. - HSB

1 Answers

0
votes

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.