PDA

View Full Version : Help with DrScheme


Cronox1
04-15-2004, 07:12 PM
Hi im new to schemce and Im trying out a couple of things.

Im trying to do two different functions

For the first I'm trying to do the reverse of cons so basically I was write a function called revcon that could do this

(revcon '(a b) '(c d))
and give me

(c d a b)

I thought about doing a cons then doing a reverse on it but that didnt work and i was gonna see if any ideas were available for this.

As for my other function I want to make a function that will take a number and an atom will make a copy of the atom however many times of the number given.

So for instance if i called it copy I would have

(copy 4 'd)
and I would get

d d d d

I have tried different things with this but no luck.

If anyone could help me with this I would greatly appreciate it thanks in advance.

GnuVince
04-15-2004, 10:27 PM
For your copy function, try this:

(define (copy n elt)
(if (<= n 0)
()
(cons elt (copy (- n 1) elt))))

Cronox1
04-15-2004, 10:33 PM
Is elt some special function in scheme or is that something you made up?

GnuVince
04-16-2004, 12:27 AM
No, it's short for "element"

Cronox1
04-16-2004, 12:41 PM
For element do you mean thats just the atom im excepting so if im taking in hello as the item to print out 3 times its represented by elt

GnuVince
04-16-2004, 04:46 PM
It's usual to call the items of a list, the elements. So, you give to your function a number n and an element elt with which you want to make a list.

Cronox1
04-16-2004, 04:47 PM
ok many thanks

jemfinch
04-18-2004, 09:09 PM
(revcon '(a b) '(c d))
and give me

(c d a b)

(cons '(a b) '(c d)) would give you ((a b) . (c d)), not ((a b) (c d)).

Jeremy

DrSchemer
11-05-2004, 01:11 PM
I have a program that might work with this

HELPER FUNCTIONS

(define (hours-schemeing youspendyourlifeatthecomputer)
(= 60))


personality:your-name->your-social-status

(define (personality your-name)
(cond
[(> hours-scheming 100) "YOU ARE A NERD and a Douchbag"]
[(= program-in-scheme your-programming-language) (personality (- yourname 1))]
[else "you have a life"]))