[plt-scheme] Scheme Programming Question (Boolean Connectives)

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Oct 5 10:22:12 EDT 2008


1. HtDP, Section 17. Read up on all three cases.

2. docs: string->list

Good luck -- Matthias





On Oct 4, 2008, at 1:13 PM, Geneve wrote:

> 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.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.