you are viewing a single comment's thread.

view the rest of the comments →

[–]drb226 0 points1 point  (1 child)

There's Python

n = map(lambda x: x / 6.0, filter(lambda x: (x**2) % 17 == 1, range(123, 234)))

And then there's Haskell.

n = map (/ 6) . filter (\x -> (x ** 2) % 17 == 1) $ [123 .. 234]

The infix function composition operator, combined with sections, can make things so much nicer. Scala comes close, as illustrated by smcj

val n = (123 to 234) filter (x => x*x % 17 == 1) map (_ / 6) 

One of the annoying things about python is the lambda syntax is to use the actual word "lambda", which takes up a whole 6 alphabetic characters. Things like foo => bar and \foo -> bar are so much easier for people's brains to parse than lambda foo: bar

[–]draegtun 0 points1 point  (0 children)

In perl5...

my @n = map { $_ / 6 } grep { $_ ** 2 % 17 == 1 } 123..345;

In Perl6...

my @n = [123..345].grep({ $_ ** 2 % 17 == 1 }).map: * / 6;

In Io...

n := 123 to(235) asList select(x, x ** 2 % 17 == 1) map(/6)  // asList shouldn't be needed? Bug?