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

2017-06-26 Thread philipp . thiess1999
Am Sonntag, 25. Juni 2017 14:24:27 UTC+2 schrieb philipp.t...@gmail.com:
> 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!

Thanks guys for the help!

-- 
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] Re: I can translate a word but how can I translate a setence with drrakket

2017-06-25 Thread Matthias Felleisen

> On Jun 25, 2017, at 4:28 PM, Philip McGrath  wrote:
> 
> At this point it is mostly a question of how restrictive your teacher wishes 
> to be by requiring that you implement this as a single function. If you are 
> using full Racket, it is possible to define a helper function inside of a 
> larger function. Here is the most direct way to translate your existing code:
> 
> #lang racket
> 
> (define *lex*
>   '((cat gato katze)
> (dog perro hund)
> (eats come frisst)
> (jumps salte springt)
> (the el die)))
> 
> (define (translate-sentence satz lexikon sprache)



May I point out that this version introduces (“creates”) a new version of 
translate-word for every “iteration” of translate-sentence even though these 
versions are all the same (observationally)? 


>   (define (translate-word 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
>(translate-word wort (rest lexikon) sprache)]))
>   (cond
> [(null? satz) '()]
> [else
>  (cons (translate-word (first satz) lexikon sprache)
>(translate-sentence (rest satz) lexikon sprache))]))
> 
> Can you see a way to make remove the sprache argument from translate-word?
> 
> -Philip
> 
> On Sun, Jun 25, 2017 at 3:03 PM,  > wrote:
> Thanks guys I got a solution!
> 
> #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))
> 
> ))
> 
>(define (translate2 satz lexikon sprache)
>  (cond((null? satz) '())
>   (else (cons (translator (first satz) *lex* sprache) (translate2 
> (rest satz) lexikon sprache)
> 
> 
> So now I just wanna know if there is a way to make this in one function?
> Is it possible to make a function inside a function and if yes how?
> 
> --
> 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 
> .

-- 
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] Re: I can translate a word but how can I translate a setence with drrakket

2017-06-25 Thread Philip McGrath
At this point it is mostly a question of how restrictive your teacher
wishes to be by requiring that you implement this as a single function. If
you are using full Racket, it is possible to define a helper function
inside of a larger function. Here is the most direct way to translate your
existing code:

#lang racket

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

(define (translate-sentence satz lexikon sprache)
  (define (translate-word 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
   (translate-word wort (rest lexikon) sprache)]))
  (cond
[(null? satz) '()]
[else
 (cons (translate-word (first satz) lexikon sprache)
   (translate-sentence (rest satz) lexikon sprache))]))


Can you see a way to make remove the sprache argument from translate-word?

-Philip

On Sun, Jun 25, 2017 at 3:03 PM,  wrote:

> Thanks guys I got a solution!
>
> #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))
>
> ))
>
>(define (translate2 satz lexikon sprache)
>  (cond((null? satz) '())
>   (else (cons (translator (first satz) *lex* sprache) (translate2
> (rest satz) lexikon sprache)
>
>
> So now I just wanna know if there is a way to make this in one function?
> Is it possible to make a function inside a function and if yes how?
>
> --
> 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.


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

2017-06-25 Thread philipp . thiess1999
Thanks guys I got a solution!

#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))

))

   (define (translate2 satz lexikon sprache)
 (cond((null? satz) '())
  (else (cons (translator (first satz) *lex* sprache) (translate2 (rest 
satz) lexikon sprache)


So now I just wanna know if there is a way to make this in one function?
Is it possible to make a function inside a function and if yes how?

-- 
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.