nanaman 0 Newbie Poster

Hi again, new assignment is to creat a spynetwork (where does he get his ideas?) anyway the program is supposed to take a code (i.e. caesars code) as a list of 2 lists, store the code (i've used a table for mine) then use it to decode and encode messages..... I have got all of this working, however, you are supposed to be able to use

(define (a-ciphermachine mapping)
  (let
	(
	(temp-table (a-table))
	)
  (put-code mapping)
  (define (the-ciphermachine op)
        (cond ((eq? op 'encode)      encode)
              ((eq? op 'decipher)    decipher)
              ((eq? op 'destroy)     destroy)
              (else (error "ciphermachine: unknown operation" op))
        )
  )
  
  (define (encode message)
     (change message)
     )
     

  
  (define (decipher message)
  (dechange message)
  )
  
 (define (destroy)
 (sequence
 (put-code destroy-code)
 #t
 )
)
				   
 the-ciphermachine
)
)

to be able to create different machines, i.e. enigma, tom, fred, whatever. all with different codes, and them all work at the same time.
I figured the Let statement would mean that they create their own tables, and would only use their own, however I am getting an unbound variable for temp-table when I run it and try to do anything.
If i declare the table in the main body, it will work, but all machines will use the same code. HELP!

thanks :)

nevermind got this working

nanaman 0 Newbie Poster

Hi again, new assignment is to creat a spynetwork (where does he get his ideas?) anyway the program is supposed to take a code (i.e. caesars code) as a list of 2 lists, store the code (i've used a table for mine) then use it to decode and encode messages..... I have got all of this working, however, you are supposed to be able to use

(define (a-ciphermachine mapping)
  (let
	(
	(temp-table (a-table))
	)
  (put-code mapping)
  (define (the-ciphermachine op)
        (cond ((eq? op 'encode)      encode)
              ((eq? op 'decipher)    decipher)
              ((eq? op 'destroy)     destroy)
              (else (error "ciphermachine: unknown operation" op))
        )
  )
  
  (define (encode message)
     (change message)
     )
     

  
  (define (decipher message)
  (dechange message)
  )
  
 (define (destroy)
 (sequence
 (put-code destroy-code)
 #t
 )
)
				   
 the-ciphermachine
)
)

to be able to create different machines, i.e. enigma, tom, fred, whatever. all with different codes, and them all work at the same time.
I figured the Let statement would mean that they create their own tables, and would only use their own, however I am getting an unbound variable for temp-table when I run it and try to do anything.
If i declare the table in the main body, it will work, but all machines will use the same code. HELP!

thanks :)

nanaman 0 Newbie Poster

Thanks so much for all the help Duoas, rep points coming your way, got the assignment all working and handed in, again thanks :D

nanaman 0 Newbie Poster

Is there anyway to sort a list of numbers (and words alphabetically) into order?

thanks

nanaman 0 Newbie Poster
(define c1 (a-card 7 'clubs))
(define c2 (a-card 8 'spades))
(define c3 (a-card 9 'hearts))
(define c4 (a-card 10 'clubs))
(define c5 (a-card 11 'diamonds))
(define (a-hand c1 c2 c3 c4 c5) (list c1 c2 c3 c4 c5))

The help so far has been fantastic, I now have the single cards working, and am working on constructing the hand, the a-hand function works fine, however the next thing is to impliment "(contents hand) - returns a list of card objects (as constructed by a-card in the hand."

Now i have no problem doing this as i could just simply put

(define (hand c1 c2 c3 c4 c5) (a-hand c1 c2 c3 c4 c5))
(define (contents hand) (list (car hand) (car (cdr hand)) (car (cdr (cdr hand))) (car (cdr (cdr (cdr hand)))) (cdr (cdr (cdr (cdr hand)))))

That the correct way to do it you think?

Thanks again for all the help

*Edit* just tried this way and it is giving me an error of "wrong type in arg1" >.<
*Edit* Just removed the (Define (hand c1 c2 .....) statement and simply type (contents (a-hand c1 c2 c3 c4 c5)) and it works fine :)

Just wondering though, how can i seperate the two things in a card in a hand? would it be

(suit (car hand)) etc?
nanaman 0 Newbie Poster

That is fantastic, however, the reason I was playing with a list was that I need to store 5 cards (a poker hand), would the best way be to make the pair and then store the pair in a list along with the other 5 then?

thanks again

nanaman 0 Newbie Poster
(define (make-card rank suit) (list rank suit))
(define (a-card rank suit) (make-card rank suit))

Using this I can get (a-card) to return the correct value, how do I then get this value to be passed out of the procedure (i.e. so I can recall it and also use it for (card) ?

Thanks

nanaman 0 Newbie Poster

Ok I have to write a program that creats an ADT to store a set of cards that are imput so that i can use the command (a-card rank suit) and (rank card) (suit card) to firstly construct the card and then return its rank and suit. Unfortunately I am struggling alot with this and wondering if someone could prod me in the correct direction.

(define suit (list 'clubs 'diamonds 'hearts 'spades))
(define rank (list 1 2 3 4 5 6 7 8 9 10 11 12 13))
(define (a-card rank suit)
          (list cons rank suit))

any and all prods greatly appreciated, as this is just giving me an error