November 05, 2024, 04:06:44 PM

1,531,344 Posts in 46,732 Topics by 1,523 Members
› View the most recent posts on the forum.


Someone teach me Scheme ;_____;

Started by Sam, October 07, 2009, 08:14:48 PM

previous topic - next topic

0 Members and 1 Guest are viewing this topic.

Go Down

Sam

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.
1.8mb is too huge for a sig nigga

Nyerp

pay attention in class and take notes!!

Travis

i know 2 people whose last names are o'neill

Daddy

Give me the tutorials they give you.

Sam

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.
1.8mb is too huge for a sig nigga

the shortest route to the sea


Quote from: Socks on January 03, 2011, 09:56:24 PM
pompous talk for my eyes water and quiver with a twitch like a little bitch

Go Up