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

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Oct 5 06:39:13 EDT 2008

(define (string<? x y)
 (define (list-of-char<? x y)
  (cond
   ...))
 ...)

list-of-char<? does the job proper. Use the design recipe for it. Which 
cases can you discern? (taking into account that x and/or y may be empty) 
Your description in terms of prefixes is correct but may put you on the 
wrong track, After we have transformed the strings into lists of chars, the 
natural thing to do is to think in terms of the car and the cdr of the 
lists.

Hope this helps. Jos

----- Original Message ----- 
From: "Geneve" <kyung8653 at gmail.com>
To: <plt-scheme at list.cs.brown.edu>
Sent: Saturday, October 04, 2008 7:13 PM
Subject: [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.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 



Posted on the users mailing list.