7 ms·
> One of the most impressive things Larry demonstrated was the sequence operator, and Perl 6's ability to intuit sequences. say 1, 2, 4 ... 2**32 > This c
by haberman 11y ago
> One of the most impressive things Larry demonstrated was the sequence operator, and Perl 6's ability to intuit sequences.
say 1, 2, 4 ... 2**32
> This correctly produced a nice tidy list of just 32 values -- rather than the 4,294,967,296 you might expect.
Someone with more time than me needs to find an IQ test that is based around sequence questions like this and plug them all into Perl 6. So we can find out what Perl 6's IQ is and whether it has achieved AI.
- sp332 11y agoTry putting two spaces at the beginning of a line to stop HN from eating the asterisks. > say 1, 2, 4, 2**32
- ubernostrum 11y agoThank you. I spent far too long trying to figure out what sequence would start "1, 2, 4" and then have 232 be the 32nd item.
- haberman 11y agoOops, sorry! Fixed it.
- Someone 11y agoDon't be ashamed. http://oeis.org/search?q=1%2C2%2C4%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C232&sort=&language=&go=Search http://oeis.org/search?q=1%2C2%2C4%2C_%2C_%2C_%2C_%2C_%2C_%2... does not know it, either, it gives me http://oeis.org/A115346 http://oeis.org/A115346 That has 46 terms before hitting the right pattern. It also gives http://oeis.org/A188668 http://oeis.org/A188668 which has only four terms before hitting 1, -2, 4, ..., -232. I guess one could try and tweak either to get a matching sequence, but I don't see a trivial way to do it that is mathematically 'nice'. It is easier to start with http://oeis.org/search?q=0%2C0%2C1%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C_%2C200&sort=&language=&go=Search http://oeis.org/search?q=0%2C0%2C1%2C_%2C_%2C_%2C_%2C_%2C_%2..., though. It gives me http://oeis.org/A242067 http://oeis.org/A242067 "Number of triangular numbers between n^2 and n^3 (excluding the bounds)." So, this sequence 'must' be "n plus number of triangular numbers between n^2 and n^3 (excluding the bounds)."
- odbol_ 11y agoAnd therein lies the problem with Perl.
- dragonwriter 11y ago> This correctly produced a nice tidy list of just 32 values 33, not 32, right? (20 through 232, inclusive)
- kbenson 11y agoYes, 33 (although HN ate your double asterisk, like it did the original comment's initially). # perl6 -e 'say +(1, 2, 4 ... 2**32).elems;' 33
- nv-vn 11y agoThis 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)
- mightybyte 11y agoThis would probably be useful. http://oeis.org/ http://oeis.org/
- raldi 11y agoDouglas Hofstadter proposed something like this long ago, only the task was to find analogies in sequences. For example, what number in the sequence 1 2 3 4 5 4 5 4 3 2 1 corresponds to the second 3 in this one? 1 2 3 2 3 2 1 If that seemed too easy, what's the corresponding number in this one? 5 4 3 2 1 2 1 2 3 4 5 How about this? 1 2 3 4 5 6 7 6 5 4 5 4 3 2 1
- 72deluxe 11y agoWith things like this, it makes me glad I write C++ (and that gets bashed enough!). I do not miss the days of maintaining a Perl codebase (and trying to decipher what on earth code was doing). This is insane.
- Mithaldu 11y agoPerl is a language sufficiently different from the main bulk of languages that one must make an earnest effort to learn it before one can read it. Your complaint is similar to someone declaring Japanese insane just because of the way its writing system looks like gigantic and erratic complexity to the inexperienced.
- 72deluxe 11y agoAh yes but it is mainly because many languages borrow C-style syntax so you can understand it without many brain gymnastics. You are correct, however. I did try learning Japanese and was just as unsuccessful at that as with Perl; I did maintain an old Perl codebase at one point and learned enough to get by but I would never jump at the opportunity to do it again!
- Mithaldu 11y agoHow much of the reference docs and available books did you read? Or did you, like many, just read code and hunt for the bits that weren't obvious?
- a8da6b0c91d 11y agoTo be fair Japanese writing is insane and they know it. It's far too difficult.
- oldmanjay 11y agoYou pretty clearly have an emotional attachment to Perl, which is sort of lovely to see, but it's causing you to be undeservedly condescending to people who don't have that attachment, which is not lovely.
- Ovid 11y agoThe range operator (..) is also pretty cool, since we're all lazy now. Here's an infinite lazy list of prime numbers in Perl 6 (declared as a constant because you presumably don't want to change 'em): constant primes = grep { .is-prime }, 1 .. *;