RU beehive logo ITEC dept promo banner
ITEC 380
2014fall
ibarland

homelecturesrecipeexamshwsD2Lbreeze (snow day)

hw02
defining functions
`cond` for union types

Due:
Section 01: Sep.08 (Mon) 23:59, on D2L and hardcopy on Wednesday
Section 11: Sep.09 (Tue) 23:59, D2L.
Your submitted file should be named “hw02.rkt” as plain-text (which is what DrRacket saves as).

Standard instructions for all homeworks:

Open DrRacket (either in labs, or you can download it to your own computer from racket-lang.org). The first time you start DrRacket, it will ask you to choose a language; select Language > Use Language... > Teaching Languages > Beginning Student, for now.

Follow the design recipe, steps 4,5,7,8.

  1. (15pts) Write the function has-suffix?, which takes in two strings and returns whether or not the first string ends with (the letters of) the second.1.
    hint:You can avoid needing if or cond with a clever (but standard) use of min or max.
  2. Data definition: A directory-response is one of:

    NOTE: You are given a directory-response: so if you're given a string, you deduce (from this def'n) that its length is in [1,14). This is not something you need to check for, or handle.

    (15pts) Write a function which, given a directory-response, returns a string: either

    corresponding to the three cases in our data-definition, respectively.

    (You can think of this function as being one part of a larger program which queries a campus-directory, such as radford's, and then has to use the response it gets.)

    To think about: As per the design recipe since our data-definition has three different variants, you will have a cond with how many branches? (You don't need to write a template (step 3a) separately from your final code, for this homework.)


1 If in doubt about exactly what constitutes a suffix, here's a definition: We say that string b is a suffix of a if there exists a string p such that a equals p concatenated to b.

We'll see later how, in a declarative language (Prolog), this definition is runnable code.

     

homelecturesrecipeexamshwsD2Lbreeze (snow day)


©2014, Ian Barland, Radford University
Last modified 2014.Oct.28 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.