As Jan says in the hierarchically-above page (which took me some time to click on):
For example (note that \n is a newline):
?- normalize_space(atom(Out), ' \nhello\nworld '). Out = 'hello world'.
So this predicate takes a tagged value to specify the output type (its a special Prolog way of doing things; I would be looking for an options list (which I consider better because you can pass several different flags) or a differently named predicate (which I consider worse because the space of predicates becomes mentally messy))
?- normalize_space(string(X),hello). % atom hello to string X = "hello". ?- normalize_space(atom(X),hello). % atom hello to atom X = hello. ?- normalize_space(atom(X)," hello "). % string to trimmed atom X = hello. ?- normalize_space(string(X)," hello "). % string to trimmed string X = "hello". ?- normalize_space(string(y)," hello "). % the result is not the atom 'y' false. ?- normalize_space(string(hello)," hello "). % the result is not the atom 'hello' false. ?- normalize_space(string("hello")," hello "). % the result is indeed the string "hello" true. ?- normalize_space(atom("hello")," hello "). % the result is not the string "hello" false. ?- normalize_space(atom(X)," hello world "). % inner space is normalized X = 'hello world'. ?- normalize_space(123," hello world "). % just throws ERROR: Type error: `output' expected, found `123' (an integer) ?- normalize_space(atom(hello),X). % throwing as a way of saying "you are going too far" ERROR: Arguments are not sufficiently instantiated