Does anyone know SCHEME?????

GT578

Senior member
Feb 7, 2000
721
0
0
I am having trouble with my homework and I have no one to ask for help because I live off campus, TAs don't HELP at all...and never answer emails in time to help, and the homework is due Monday morning which forces me to finish this weekend. I am stuck on a problem where you take in a list and return a list with all the duplicates removed. I got it to a point where it does that...but the output is not in order of each item appearing first...meaning: (remove-duplicates '(a a b b c c d c d e a)) -> should return: (a b c d e) instead of those letters in random order ....which is what I can only get. Can someone PLEASE HELP?? ...
 

ManSnake

Diamond Member
Oct 26, 2000
4,749
1
0
My question is do you have to sort them in order
i.e. if the list is (a a c c b b e e d) it returns (a b c d e)

or just in the order they appear in the list
i.e. if the list is (a a c c b b e e d) it returns (a c b e d)

your example doesn't tell me anything.
 

cmdavid

Diamond Member
May 23, 2001
4,114
0
0
(define (remove-duplicates monkies)

(cond ((null? monkies) '())

((equal? (car monkies) (car (cdr monkies)))

(remove-duplicates (cdr monkies)))

(else (cons (car monkies) (remove-duplicates

(cdr monkies))))))

hope this helps...
 

GhettoFob

Diamond Member
Apr 27, 2001
6,800
0
76


<< Do you go to UC Berkeley? >>



Yeah I thought Berkeley was the only school that taught it. I learned it during the fall semester, but I don't remember any of it.
 

cmdavid

Diamond Member
May 23, 2001
4,114
0
0
the Georgia Institute of Technology has now officially replaced all of its introductory (cs 1311) with this stupid language... unbelievably....
 

Mapidus

Senior member
Jun 9, 2001
457
0
0


<<

<< Do you go to UC Berkeley? >>



Yeah I thought Berkeley was the only school that taught it. I learned it during the fall semester, but I don't remember any of it.
>>



No, MIT has a course that uses Scheme called Structures and Interpretation of Progamming Languages or something like that. Cornell also teaches this course, but over the pass few years they have gone from Dylan to Scheme and finally to ML. I think Stanford has the same course also (not sure which functional language they use though), and the Berkeley course also originates from the original MIT course I think.
 

BA

Diamond Member
Dec 3, 1999
5,004
1
0
University of Kansas has it too. Only run into one class with it so far, probably cuz I dropped that class. But I'll have to take it eventually, ughhhh.. Scheme makes me like Java
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
a lot of schools teach functional languages, try ML its lisp and schemes child and i want to commit infaticide.
 

GT578

Senior member
Feb 7, 2000
721
0
0
Mansnake - &quot;if the list is (a a c c b b e e d) it returns (a b c d e)&quot; -> that's what I am asking...

Sandiga - Yeah...I tried that code...and it doesn't work~!!! I found another sample code online that does sort out the duplicates but not in order. I do go to GeorgiaTECH...I really need help...and the TAs are no good.


 

cmdavid

Diamond Member
May 23, 2001
4,114
0
0
(define (remove-duplicates monk )
(reverse (rid-dup monk '())))

(define (rem-dup monk mlist)
(cond ((null? monk) mlist)
((member (car monk) (cdr monk))
(rem-dup (cdr monk) mls))
(else (rid-dup (cdr monk) (cons (car monk) mls)))))

Im a little rusty on this language and hope i nver have to use it again... heres another try w/ a helper function.. i dont remember if this works or not because i uninstalled Dr.Scheme and i dont wanna re-install it..i just typed this up in notepad...
 

GT578

Senior member
Feb 7, 2000
721
0
0
Thanks for the sample codes Sandigga....that last code you posted...it does what I had before. The function returns the items in the list without duplicates but not in the order of appearance...and I still can't seem to find the answer for it. The first code you posted...that is exactly what I made up yesterday night and struggled with it because Dr. Scheme would give an error on the ((equal? (car monkies) (car (cdr monkies))) part which I cannot figure out because if you type (car (cdr monkies)) in with a list instead of monkies on the bottom box ...it works fine. Anyways I will continue to work on it throughout the day and tomorrow ...but if anyone else can help....I'd greatly appreciate it...