0

Is there any way in which I can convert a string to list separated by spaces.The string has to be entered by the user. Suppose How are you today ? is the string entered by the user,I want to store it in a list say L, L=['How','are','you','today','?']. How can I do this??

  • Possible duplicate of [convert string to list in prolog](https://stackoverflow.com/questions/18224717/convert-string-to-list-in-prolog) – Anderson Green Feb 22 '18 at 03:13

2 Answers2

0

SWI-Prolog offers tokenize_atom

?- [library(porter_stem)].
?- tokenize_atom('How are you today ?', L).
L = ['How', are, you, today, ?].

note that quoting atoms is necessary only when the lexical representation aliases some other type (notably variables)

CapelliC
  • 59,646
  • 5
  • 47
  • 90
0

?- split_string("How are you today ?", " ", "", L).

per this site.

Lrrr
  • 4,755
  • 5
  • 41
  • 63
Ralff11
  • 16
  • 2
  • this is giving me folllowing error- `ԀERROR: main/0: Undefined procedure: split_string/4 Exception: (7) split_string([97, 46, 98, 46, 99, 46, 100], [46], [], _G1077) ?` –  Nov 23 '14 at 07:33
  • 1
    split_string works in SWI-Prolog version 7. instead ?- atomic_list_concat(L, ' ', 'How are you today ?'). – Ralff11 Nov 23 '14 at 07:56