Question: I need to write a function ` alicewords / 2 ` that reads in ` alice . txt ` and splits it into words using

I need to write a function `alicewords/2` that reads in `alice.txt` and splits it into words using `split_string/4`. I must split on spaces and remove leading or trailing spaces.
This appears to work, but I don't understand why it works. Can you help explain this concept to me? Thank you so much
alicewords(WordCount) :-
open('alice.txt', read, Str),
read_string(Str,_, Text),
split_string(Text,"","", Words),
length(Words, WordCount),
close(Str).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!