1

I got the letters to turn upside down. p to d What I can't seem to do is get a string of words to turn upside down. Like house upside down to ǝsnoɥ. any help would be appreciated. I am just about done. I am using beginning student with list abbreviations.

#;(first (first l2))
#;(first (rest l2))
#;(first (rest (first l2)))

(define (helper character list)
  (cond [(string=? character (first (first list))) (first (rest (first list)))]
        [else (helper character (rest list))]))

(check-expect (helper "p" table-1) "d")
(check-expect (helper "t" table-1) "ʇ")

;;_______________________________________________________________________________

(define (upside-down string)


(upside-down "cat")
Jerry Lynch
  • 83
  • 2
  • 8
  • I figured out another (Easier) way to do this though, using beginng student language. dont think ive ever gone over lambda – Jerry Lynch Feb 18 '13 at 00:39

1 Answers1

1

A couple of comments on your helper procedure:

  • You should add an extra condition for the case when character is not in the list - if that happens, simply return the same character. Otherwise, an error will occur
  • The parameter should not be named list, that's a built-in procedure and it's a bad practice to overwrite it
  • Test it throughly before proceeding.

Once that's sorted out, here's how you could implement upside-down, fill-in the blanks:

(define (upside-down str)
  (<???>                       ; finally, do the opposite of explode on the list
   (map (lambda (c)            ; map over each of the characters
          (<???> <???> <???>)) ; call helper on the character
        (<???> (<???> str))))) ; reverse the exploded string

If you're not allowed to use map or lambda, then implement a convert procedure that iterates over each of the characters in the string and applies helper on each one, returning a list with the result of applying it - basically, implement you own map that always applies helper to each element in the input list:

(define (convert lst)
  <???>)

(convert '("c" "a" "t"))
=> '("ɔ" "ɐ" "ʇ")

Now we can write upside-down using convert:

(define (upside-down str)
  (<???>                   ; finally, do the opposite of explode on the list
   (convert                ; use our shiny new procedure
    (<???> (<???> str))))) ; reverse the exploded string
Óscar López
  • 232,561
  • 37
  • 312
  • 386