Re: [racket-users] I can translate a word but how can I translate a setence with drrakket

2017-06-25 Thread Matthias Felleisen


I think you want this: 

#lang racket

(define *lex*
  '((cat   gato   katze)
(dog   perro  hund)
(eats  come   frisst)
(jumps salte  springt)
(the   el die)))

;; I also took the liberty of cleaning up your original code, 
;; using full Racket because it is what your teacher/you chose 
(define (translator wort lexikon sprache)
  (cond ((null? lexikon) '(Wort wurde nicht gefunden))
((member wort (first lexikon))
 ((sprache->selector sprache) (first lexikon)))
(else (translator wort (rest lexikon) sprache

(define (sprache->selector sprache)
  (cond
((equal? sprache 'english)  first ) 
((equal? sprache 'spanisch) second) 
((equal? sprache 'deutsch)  third)))

;; the code you want: 
(define (translator* worte lexikon sprache)
  (map (lambda (ein-wort) (translator ein-wort lexikon sprache)) worte))

;; the example: 
(translator* '(the dog jumps) *lex* 'deutsch)


The question you should ask now is how to get from here to there 
systematically. It is never about coding, but always about finding the code 
systematiclly. 

See http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html





> On Jun 25, 2017, at 8:24 AM, philipp.thiess1...@gmail.com wrote:
> 
> Hello today I made a translator for drRakket cause its a task of my teacher.
> 
> 
> 
> I did it for one word but now I have to make it with a whole setence. I know 
> I have to work with cons somehow but I just dont get how to make it. My 
> teacher doesnt understand it himself (he uses a pdf which gives all the tasks 
> and wont give us solutuions) so you guys are my only hope.
> 
> 
> Here is my current code (Sorry for the german ( wort means word, lexikon is 
> the list with all the words in 3 langauges) and sprache means language)
> 
> 
> 
> #lang racket
> 
> (define *lex*
> '((catgato   katze)
>  (dog   perro  hund)
>  (eats   come  frisst)
>  (jumps   salte   springt)
>  (the   el   die)))
> 
> 
> (define (translator wort lexikon sprache)
> 
>  (cond ((null? lexikon) '(Wort wurde nicht gefunden)) 
> 
>((or (equal? wort (first (first lexikon))) 
> 
> (equal? wort (first (rest (first lexikon 
> 
> (equal? wort (first (rest (rest (first lexikon))
> 
> 
>   (cond
> ((equal? sprache 'english) (first (first lexikon))) 
> 
> ((equal? sprache 'spanisch) (first (rest (first lexikon 
> 
> ((equal? sprache 'deutsch) (first (rest (rest (first lexikon)) 
> 
>)  
> 
> 
> 
> 
>(else (translator wort (rest lexikon) sprache)) 
> 
>))
> 
> 
> So (translator 'cat *lex* 'deutsch) will give the german word for cat which 
> is Katze.
> 
> 
> But now I have to change the code that (translator '(the dog jumps) *lex* 
> 'deutsch) will give me "die hund springt".
> 
> Can anyone help me? You are my last hope!
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [racket-users] I can translate a word but how can I translate a setence with drrakket

2017-06-25 Thread Jos Koot
Surely this is homework.
I am not giving you all detauils, just some hints.
First of all: Look in HtDP.

Your translator works for single words.
Let translate-sentence be the procedure for translating a list of words.
Following HtDP it can look like:

(define (translate-sentence sentence lexicon sprache)
 (cond 
  ((null? sentence) ...)
  ((else
(cons 
 (translate (car sentence) ...)
 (translate-sentence (cdr sentence) ...)

There are many more ways to do the same.
If you are acquanted with procedure map, you could write something like:

(define (translate-sentence sentence lexicon sprache)
 (define (translate-word word) (translate word lexicon spache))
 (map ...))

Jos

-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com] On 
Behalf Of philipp.thiess1...@gmail.com
Sent: domingo, 25 de junio de 2017 14:24
To: Racket Users
Subject: [racket-users] I can translate a word but how can I translate a 
setence with drrakket

Hello today I made a translator for drRakket cause its a task of my teacher.



I did it for one word but now I have to make it with a whole setence. I know I 
have to work with cons somehow but I just dont get
how to make it. My teacher doesnt understand it himself (he uses a pdf which 
gives all the tasks and wont give us solutuions) so you
guys are my only hope.


Here is my current code (Sorry for the german ( wort means word, lexikon is the 
list with all the words in 3 langauges) and sprache
means language)



#lang racket

(define *lex*
'((catgato   katze)
  (dog   perro  hund)
  (eats   come  frisst)
  (jumps   salte   springt)
  (the   el   die)))


(define (translator wort lexikon sprache)

  (cond ((null? lexikon) '(Wort wurde nicht gefunden)) 

((or (equal? wort (first (first lexikon))) 

 (equal? wort (first (rest (first lexikon 

 (equal? wort (first (rest (rest (first lexikon))


   (cond
 ((equal? sprache 'english) (first (first lexikon))) 

 ((equal? sprache 'spanisch) (first (rest (first lexikon 

 ((equal? sprache 'deutsch) (first (rest (rest (first lexikon)) 

)  




(else (translator wort (rest lexikon) sprache)) 

))


So (translator 'cat *lex* 'deutsch) will give the german word for cat which is 
Katze.


But now I have to change the code that (translator '(the dog jumps) *lex* 
'deutsch) will give me "die hund springt".

Can anyone help me? You are my last hope!



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.