[plt-scheme] Scheme Programming Question (Boolean Connectives)
This is another problem that I am having trouble with.
I really need your help.
Question Details:
Exercise 7. The built-in predicate string<? accepts two strings and
returns true if its arguments are given in lexicographic order, i.e.,
"alphabetical order," where our alphabet includes numeric and special
characters as well as alphbetic characters. That is, (string<? s1 s2)
evaluates to true if s1 is a proper prefix of s2 or if there is a
character c1 in s1 and c2 in s2 where (char<? c1 c2) and the (possibly
empty) prefix of s1 up to (but not including) c1 is equal to the
prefix of s2 up to (but not including) c2.
Define a procedure string<?. Use an internally-defined help procedure
and the built-in procedures char<?, char=?, and string->list in your
solution, but do not use the built-in string<? or other string
comparison predicates. Experiment with test cases of your own using
the built-in string<? procedure before loading your own definition.
> (string<? "abc" "abc")
#f
> (string<? "aaaa" "aaaaaaa")
#t
> (string<? "abcdefg" "abcdefh")
#t
> (string<? "abcdefg" "abcdeff")
#f
> (string<? "walk" "crawl")
#f
> (string<? "bark" "dog")
#t
> (string<? "dog" "bark")
#f
> (string<? "!@#$%&*(" "!@#%&*(")
#t
Hint: Use a local help procedure that expects two lists of characters.
Remember that the two lists may have different lengths, and think
carefully about termination conditions in different cases. If neither
list is empty, the help procedure compares the first characters of the
two lists, and loops only if the two characters are equal. Using and
and or should simplify your code.