3 ms·
This is cool but I still don't get how it is able to distinguish between linear, power, exponential, etc. sequences so easily. Would be incredibly interested in
by nv-vn 11y ago
This is cool but I still don't get how it is able to distinguish between linear, power, exponential, etc. sequences so easily. Would be incredibly interested in reading about the technology they're using for this and how complex it can get.
- cygx 11y agoLinear and geometric sequences are auto-detected, for anything else you'll need to provide a function to compute the next element: 2, 4 ... * # linear 2, 4, 8 ... * # exponential 1, 1 ... * # constant 1, 1, * + * ... * # Fibonacci The last expression is equivalent to the more verbose variant 1, 1, -> $a, $b { $a + $b } ... * that makes use of an 'pointy block' (ie lambda function) instead of the Whatever-*.
- joeyh 11y agoAh so it's similar to the haskell list comprehension syntax, converted to a point-free form (and with added guessing/defaulting due to the ambiguities therein). [x*2 | x <- [1..10]] -- linear [2^x | x <- [1..10]] -- exponential [1 | x <- [1..10]] -- constant IIRC haskell list comprehensions can't do fib without naming the list so it can refer to itself. OTOH, these perl list comprehensions seems unable to express things that combine values from several lists, eg: [ x*y | x <- [2,4..8], y <- [-1,0,1] ] -- [-2,0,2,-4,0,4,-6,0,6,-8,0,8] Course, haskell also has a weak form of [x1,x2..xn] syntax for a linear sequence, as in [2,4..8]. That's always felt a bit of an unnecessary wart in haskell to me, although the simpler [x..y] and [x..] are very handy syntaxes. TBH, I almost never use list comprehensions either, preferring regular functions, and the list monad or applicative. (*2) [1..10] -- linear (2^) [1..10] -- exponential repeat 1 -- constant fibs = 0 : 1 : zipWith (+) fibs (tail fibs) -- fibonacci obvs (*) <$> [2,4..8] <*> [-1,0,1] -- same as [ x*y | x <- [2,4..8], y <- [-1,0,1] ]
- raiph 11y agoFwiw, the Haskell: [ x*y | x <- [2,4..8], y <- [-1,0,1] ] -- [-2,0,2,-4,0,4,-6, 0,6,-8,0,8] could be translated to the Perl 6: [2,4...8] X* [-1,0,1] # (-2 0 2 -4 0 4 -6 0 6 -8 0 8)
- Grim_Reaper 11y agoPython list comprehension similar to Haskell -> https://en.wikipedia.org/wiki/List_comprehension#Python https://en.wikipedia.org/wiki/List_comprehension#Python
- 1ris 11y agoThis is so very Perl. I guess this is Perls answer to list comprehensions.
- koenigdavidmj 11y agoI would assume that it has those too. Due to the main implementation being Pugs for a while, the language absorbed a lot of Haskellisms (chiefly laziness).
- kbenson 11y agoThat's interesting, I always figured Python's list comprehensions where their answer to Perl's map and grep. But in direct answer to your question, no, but it's part of the answer[1]. 1: https://en.wikipedia.org/wiki/List_comprehension#Perl_6 https://en.wikipedia.org/wiki/List_comprehension#Perl_6
- dragonwriter 11y agogather/take is more the general Perl 6 take on list comprehensions.