Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/26/83; site ihuxe.UUCP Path: utzoo!linus!decvax!harpo!eagle!mhuxt!mhuxi!mhuxa!houxm!ihnp4!ihuxe!aark From: aark@ihuxe.UUCP Newsgroups: net.sources Subject: Pig Latin in C and Lex, meet LISP! Message-ID: <330@ihuxe.UUCP> Date: Fri, 2-Sep-83 17:33:53 EDT Article-I.D.: ihuxe.330 Posted: Fri Sep 2 17:33:53 1983 Date-Received: Sat, 3-Sep-83 10:54:22 EDT Organization: BTL Naperville, Il. Lines: 56 First, Mr. Art Zemon's English-to-Pig-Latin translator, written using Lex, does not translate correctly, at least according to the Pig Latin I learned: - Words beginning with a vowel are translated by appending "way", not "yay". - Sometimes an initial "y" is a vowel, as in "yttrium," and must be treated as such. Zemon's translator does not. - For words that begin with more than one consonant, ALL these consonants, not just the first, are put at the end, then "ay" is appended. (An initial "qu" is a special case that Zemon's translator does not handle either.) Second, this problem can be solved with an even shorter and easier program if you use a language suited to the problem, namely Lisp. (defun englishtopig (sentence) (mapcar 'etop1 sentence) ) (defun etop1 (word) (implode (etop2 (explode word))) ) (defun etop2 (letterlist) (cond ((and (equal (car letterlist) '@) (vowel (cadr letterlist))) (append (cdr letterlist) '(ay))) ((equal (car letterlist) '@) (etop2 (append '(@) (cddr letterlist) (list (cadr letterlist))))) ((and (equal (car letterlist) 'q) (equal (cadr letterlist) 'u)) (append (cddr letterlist) '(quay))) ((and (equal (car letterlist) 'y) (not (vowel (cadr letterlist)))) (append letterlist '(way))) ((vowel (car letterlist)) (append letterlist '(way))) (t (etop2 (cons '@ letterlist))) ) ) (defun vowel (letter) (or (equal letter 'a) (equal letter 'e) (equal letter 'i) (equal letter 'o) (equal letter 'u) ) ) You can't read this program, you say? Maybe you should learn Lisp. You can write many (not all) programs a lot more easily in Lisp than in C, even C augmented with code generators like Lex, and this is one of them. -- Alan R. Kaminsky Bell Laboratories, Naperville, IL ...ihnp4!ihuxe!aark