aboutsummaryrefslogtreecommitdiff
path: root/examples/sentences.fco
blob: ba1c10f2b97595b0b9b71163c445dc8c631029bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# See: https://rosettacode.org/wiki/Determine_sentence_type

def classify(xs)
    def sentence_type(s)
        def ends_with?(s c)
            if =(tail(s) "")
                =(s c)
            else
                @ends_with?(tail(s) c)
            end
        end
        if ends_with?(s "?")
            +(s " -> Q")
        elif ends_with?(s "!")
            +(s " -> E")
        elif ends_with?(s ".")
            +(s " -> S")
        else:
            +(s " -> N")
        end
    end
    map(sentence_type xs)
end

def main()
    map(display
        classify(
            list("Hi there, how are you today?"
                 "I'd like to present you the washing machine 9001."
                 "You have been nomiated to win one of these!"
                 "Just make sure you don't break it")))
end