Skip to content

Instantly share code, notes, and snippets.

@ultrox
Last active December 25, 2020 15:50
Show Gist options
  • Save ultrox/c64ac996195f6702059aec69179f59e5 to your computer and use it in GitHub Desktop.
Save ultrox/c64ac996195f6702059aec69179f59e5 to your computer and use it in GitHub Desktop.
Guided pluralize functions
; Problem: Design a function that pluralizes a given word.
; (Pluralize means to convert the word to its plural form.)
; For simplicity you may assume that just adding s is enough to pluralize a word
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; What is an appropriate signature for this function?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Which of the following purpose statements is best?
;; NOTE: Delete the one's you think are not good enought.
;; Pluralize s.
;; Produce plural string.
;; Add "s".
;; Produce the given string with "s" added to the end.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Which of the following stubs is best?
;; NOTE: Remove ;; from the one you need fit's
;; (define (pluralize str) 0)
;; (define (string str) str)
;; (define (pluralize str) "")
;; (define (longer str) 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Which of the following check-expects is appropriate?
;; NOTE: Uncomment(remove ;;) all that apply, delete the rest.
;; (check-expect (pluralize "cat") "s")
;; (check-expect (pluralize "cat") "cat")
;; (check-expect (pluralize "dog") "dogs")
;; (check-expect (pluralize "grass") "grasss")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Continuing with the given problem, we now have a signature, purpose, stub and
;; several examples. Here is the template for this function.
(define (pluralize str)
(... str))
;; code the body by replacing (... str) with the proper body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment