Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Melzzzzz Newsgroups: comp.lang.forth Subject: Re: Unfeasible? Date: Sun, 6 Dec 2015 01:01:33 +0100 Organization: albasani.net Lines: 87 Message-ID: <20151206010133.3820da9e@maxa-pc> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net G8SfZfcrRLEDCE+dSHYhCwY0GAxPP1ixuXs2eHpZTXpkTvl0ujtX0HRElco65Lfc8KrKa1UkpfY22Fsb+Q8ieQ== NNTP-Posting-Date: Sun, 6 Dec 2015 00:01:33 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="zoBjT4E8DG2Xti1EcWx6liuHnIhqbkgHJ50wj+dR7t5qsSGKuLwE0qUHnK0Em85pDUXlhxpAvX7H0BGPUYgs8sCeuL//1+eodirnRhoEkj3iB++kIBQH8WCMa5e+13vJ"; mail-complaints-to="abuse@albasani.net" X-Newsreader: Claws Mail 3.13.0 (GTK+ 2.24.28; x86_64-unknown-linux-gnu) Cancel-Lock: sha1:J2g2VCye9rCjDNScZbihDInAWfg= Xref: csiph.com comp.lang.forth:44095 On Thu, 3 Dec 2015 20:22:07 -0000 (UTC) "WJ" wrote: > One has a function "get_list" that produces a list. > He has another function "test" that determines whether > a member of the list passes muster. > He has a function "foo" that is used to transform > an element of the list. > > The task is to iterate through the list while > printing each element with its index and collecting > the transformations of the elements that fit the bill. > > Wouldn't this be painful in the Toy Language (ANS Forth)? > > Ruby: > > def get_list; ('aa'..'zz').step(36).to_a ; end > def test s; s == s.reverse ; end > def foo x; x.upcase ; end > > get_list.each_with_index. > grep->((x,i)){printf "%2d - %s\n", i, x; test x}{|x,_| foo x} > > 0 - aa > 1 - bk > 2 - cu > 3 - ee > 4 - fo > 5 - gy > 6 - ii > 7 - js > 8 - lc > 9 - mm > 10 - nw > 11 - pg > 12 - qq > 13 - sa > 14 - tk > 15 - uu > 16 - we > 17 - xo > 18 - yy > ==>["AA", "EE", "II", "MM", "QQ", "UU", "YY"] > Haskell ;) [bmaxa@maxa-pc haskell]$ ghc unfeasible.hs [1 of 1] Compiling Main ( unfeasible.hs, unfeasible.o ) Linking unfeasible ... [bmaxa@maxa-pc haskell]$ ./unfeasible 0 - aa 1 - bk 2 - cu 3 - ee 4 - fo 5 - gy 6 - ii 7 - js 8 - lc 9 - mm 10 - nw 11 - pg 12 - qq 13 - sa 14 - tk 15 - uu 16 - we 17 - xo 18 - yy ["AA","EE","II","MM","QQ","UU","YY"] [bmaxa@maxa-pc haskell]$ cat unfeasible.hs import Text.Printf import Data.Char get_list = takeEvery 36 [[a,b] | a <- ['a'..'z'], b <- ['a'..'z']] where takeEvery n (x:xs) = x : (takeEvery n $ drop (n-1) xs) takeEvery _ [] = [] main = do putStrLn $ unlines $ map (\(a,b) -> printf "%2d - %s" (a::Int) b) $ zip [0..] get_list print $ map (map toUpper) $ filter (\x -> x == reverse x) get_list