Boyah Forums

General => The Lobby => Topic started by: Sam on October 07, 2009, 08:14:48 PM

Title: Someone teach me Scheme ;_____;
Post by: Sam on October 07, 2009, 08:14:48 PM
So I'm doing absolutely awful in the class that I'm learning Scheme in. Mostly because Scheme is just.. not fun and I've been lazy in learning it and now I'm so so so far behind.

Today I somehow managed to teach myself functions with lists (what we learned in Week 2 or something like that) and I was SO PROUD that this all worked:
[spoiler]
Quote;;Samantha O'Neill
;;[email protected]
;;CS1101 Lab 6 - Assignment with application in DNA Sequencing

;; A dna-sequence is s
;; (make-dna-sequence symbol symbol symbol symbol symbol symbol)
(define-struct dna-sequence (n1 n2 n3 n4 n5 n6))

;; A dna-fingerprint is a
;; (make-dna-fingerprint string string dna-sequence)
(define-struct dna-fingerprint (first-name last-name dna-seq))

;; A dna-database is either
;; - empty, or
;; - (cons dna-fingerprint dna-database)
(define worcester-db (list (make-dna-fingerprint "Julius" "No" (make-dna-sequence 'A 'C 'T 'G 'A 'T))
                           (make-dna-fingerprint "Rosa" "Klebb" (make-dna-sequence 'T 'C 'U 'C 'C 'T))))
(define boston-db empty)

;;find-by-name: string string dna-database -> dna-fingerprint
;;consumes a first name and last name and produces false if a person is not in that database or returns that database entry if a person is
(define (find-by-name first-name last-name dna-database)
  (cond [(empty? dna-database) empty]
        [(cons? dna-database) (cond [(and (string=? first-name (dna-fingerprint-first-name (first dna-database)))
              (string=? last-name (dna-fingerprint-last-name (first dna-database))))(first dna-database)]
                                    [else (find-by-name first-name last-name (rest dna-database))])]))

;;Test Cases for find-by-name
(check-expect (find-by-name "Rosa" "Klebb" worcester-db)(make-dna-fingerprint "Rosa" "Klebb" (make-dna-sequence 'T 'C 'U 'C 'C 'T)))
(check-expect (find-by-name "Anastasia" "Smith" worcester-db) empty)
(check-expect (find-by-name "Julius" "No" worcester-db)(make-dna-fingerprint "Julius" "No" (make-dna-sequence 'A 'C 'T 'G 'A 'T)))
[/spoiler]

BUT THEN I had to do the same thing except with searching for the dna-sequence.

So I tried...
[spoiler]
Quote;;find-by-dna-seq: dna-sequence dna-database -> dna-fingerprint
;;consumes a dna-sequence and a dna-database and produces empty if the dna-sequence does not exist in that database or the database entry
(define (find-by-dna-seq dna-sequence dna-database)
  (cond [(empty? dna-database) empty]
        [(cons? dna-database) (cond [(=? dna-sequence (dna-fingerprint-dna-seq (first dna-database)))(first dna-database)]
                                    [else (find-by-dna-seq dna-sequence (rest worcester-db))])]))

;;Test Cases for find-by-dna-seq
(check-expect (find-by-dna-seq (make-dna-sequence 'T 'C 'U 'C 'C 'T) worcester-db)(make-dna-fingerprint "Rosa" "Klebb" (make-dna-sequence 'T 'C 'U 'C 'C 'T)))
(check-expect (find-by-dna-seq (make-dna-sequence 'A 'C 'T 'G 'A 'T) worcester-db)(make-dna-fingerprint "Julius" "No" (make-dna-sequence 'A 'C 'T 'G 'A 'T)))
(check-expect (find-by-dna-seq (make-dna-sequence 'T 'A 'G 'T 'A 'G) worcester-db) empty)
[/spoiler]

...and I failed. Does anyone know how to compare two lists? Do I have to compare each of the symbols in the list individually?

Anyway, those were only part a and b of number 1 of a lab that went up to 6. I'm supposed to know how to use set! I do not.

Someone help me not fail.
Title: Re: Someone teach me Scheme ;_____;
Post by: Nyerp on October 07, 2009, 08:34:30 PM
pay attention in class and take notes!!
Title: Re: Someone teach me Scheme ;_____;
Post by: Travis on October 07, 2009, 08:58:06 PM
i know 2 people whose last names are o'neill
Title: Re: Someone teach me Scheme ;_____;
Post by: Daddy on October 07, 2009, 09:08:18 PM
Give me the tutorials they give you.
Title: Re: Someone teach me Scheme ;_____;
Post by: Sam on October 07, 2009, 09:54:34 PM
Quote from: Ensign Halibar on October 07, 2009, 09:08:18 PM
Give me the tutorials they give you.

They don't give me tutorials, just the text book.

http://web.cs.wpi.edu/~cs1101/a09/

if you scroll down to the bottom, the links in the left hand column of the table are the textbook online.

**I've read a good amount of the book and I don't find it helps at all.
Title: Re: Someone teach me Scheme ;_____;
Post by: the shortest route to the sea on October 08, 2009, 02:03:45 AM
POLISH NOTATION!?