Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Perl6

Name: Anonymous 2011-02-12 6:10

Fibonacci in Perl6.

my @fib := (0, 1, *+* ... *);

Can your toy language do this?

Name: Anonymous 2011-02-12 6:16

raduko star can.

Name: Anonymous 2011-02-12 6:24

Name: Anonymous 2011-02-12 6:32

(define (Π f n m)
  (let ((x (future
            (lambda ()
              (let/ec k
                (do ((x n (+ x 2))
                     (r 1 (* r (f x))))
                  ((> x m) (k r)))))))
        (y (let/ec k
             (do ((x (add1 n) (+ x 2))
                  (r 1 (* r (f x))))
               ((> x m) (k r))))))
    (* y (touch x))))

(define (fact x)
  (Π values 1 x))


Compile with -Ofast -funroll-loops -funsafe-loop-optimizations -funsafe-escape-continuations-optimizations -fomg-optimized.

Name: Anonymous 2011-02-12 6:55

>>4
Better:
[code]
(define (Π f n m (c (processor-count)))
  (let* ((t (lambda ()
              (let/ec k
                (do ((x n (+ x c))
                     (r 1 (* r (f x))))
                  ((> x m) (k r))))))
         (xs (do ((x (sub1 c) (sub1 x))
                  (xs '() (cons (future t) xs)))
               ((zero? x) xs)))
         (x (t)))
    (map (compose (curry apply *) touch) (cons x xs))))[/cpde]

Name: Anonymous 2011-02-12 6:55


(define (Π f n m (c (processor-count)))
  (let* ((t (lambda ()
              (let/ec k
                (do ((x n (+ x c))
                     (r 1 (* r (f x))))
                  ((> x m) (k r))))))
         (xs (do ((x (sub1 c) (sub1 x))
                  (xs '() (cons (future t) xs)))
               ((zero? x) xs)))
         (x (t)))
    (map (compose (curry apply *) touch) (cons x xs))))

Name: Anonymous 2011-02-12 7:03

>>5,6
Disregard that.

(define (Π f n m (c (processor-count)))
  (let* ((t (lambda (a)
              (lambda ()
                (let/ec k
                  (do ((x (+ n a) (+ x c))
                       (r 1 (* r (f x))))
                    ((> x m) (k r)))))))
         (xs (do ((x (sub1 c) (sub1 x))
                  (xs '() (cons (future (t x)) xs)))
               ((zero? x) xs)))
         (x ((t 0))))
    (foldr * x (map touch xs))))

Name: Anonymous 2011-02-12 7:23

Name: Anonymous 2011-02-12 8:37

>>1
The right question would be: "Should it be able to do it?"

How often do you need a specialised sequence operator distinct from the normal ".." range operator. The operator isn't bad per se and I'm sure if you do need it it's very useful but I think it belongs into a math library, not the core language.

Name: Anonymous 2011-02-12 8:49

>>1
My toy language can do this:

my@d=((<♦ ♠ ♥ ♣>X~(2..10,<J Q K A>))Z=>[2..9,10 xx 4,1|11]).pick(*);my@p=[],[];sub a{@^c.push(@d.pop)};sub b{[+]@^c».value};for@p {.&a;.&a;say '-'x 33;loop {if .&b!<22 {"{$_».key} > 21".say;last};say .&b,"\n{$_».key}";last if prompt('(h)it (s)it? ')~~'s';.&a}};say 'Winner:'~ %([max]@p.grep({.&b<22})).keys

Name: Anonymous 2011-02-12 8:59

>>10
VALID PERL, PERL 6 AND APL CODE!

Name: Anonymous 2011-02-12 13:49

>>9
SOSNOOLY

Name: Anonymous 2011-02-12 16:25

Can Perl6 do this?
#include <stdio.h>
int main(void) {
    struct num{ unsigned int a:3, b:3, c:2; } n = {0};
    unsigned char *c = &n;
    do do printf("%hhu\n", *c);
    while(!(n.a-- && !++n.b));
    while(++n.c);
    return 0;
}

Name: Anonymous 2011-02-12 17:25

>>13
VALID PERL 6 CODE, THREAD OVER

What were you expecting?

Name: Anonymous 2011-02-12 20:08

>>13
wait what

Name: Anonymous 2011-02-12 22:06

>>3
It's beautiful!

Name: Anonymous 2011-02-13 0:54

>>13
do do

Name: Anonymous 2011-02-13 4:23

>>17
while while

Name: Anonymous 2011-02-13 5:57

>>18
return

Name: Anonymous 2011-02-13 9:33


>,>,>++++++++[-<------<------>>]++++++++++[-<<[-<+>>+<]<[->+<]>
>>]<[-<<+>>]<[-]>>>>>>>>>>>>+<<<<<<<<<<<<<[->>+>+>+>+[->>>>[->>
>>>>>>+<<<<<<<<]>>>>[-<<<<+>>>>>>>>+<<<<]>>>>[-<<<<+>>>>]<<<<<<
<<<<<<<]>>>>>>>>>>>>>>+>+>+[-<<<<<[->>>>>+<<<<<]>[->>>>>+<<<<<]
>>>>>>+[<[->>+>+<<<]>>[-<<+>>]+>>>>[-]+++++++++<<<<[>[->+>+<<]+
>[<->[-]]<[-<[-]>]>>-[-<<+>>]>[->+>+<<]+>[<->[-]]<[-<<<<[-]>>>>
]>>-[-<<+>>]<<<<<<]+>+[[-]<-<<———-<+>>>>]<[[-]<[-]>]<]<<[-<<<<<
+>>>>>]>[-<<<<<+>>>>>]<<]<<<<<<<<<<<<<<]>>>>>[-]+++++++++++++++
+[->+++>+++>+++>+++<<<<]>.>.>.>.

Fibonacci in brainfuck. can your toy languages do this?

Name: Anonymous 2011-02-13 11:49

>>20
use brainfuck;
brainfuck($thread.getposts('>>20').body.lines[* -2].join);

Name: Anonymous 2011-02-13 12:00

>>21
.lines[* -2]
You've piqued my curiosity, what does that do?

Name: Anonymous 2011-02-13 12:09

>>22
It's a bug. It should be [^* -1], but that is not implemented in Rakudo. The way it is in >>21 will just grab the second last line, i.e. the last line of BF code.

Name: Anonymous 2011-02-13 17:52

mad easy in java, just saying.

public class fibonacci
{
    public static void main(String []args)
    {
        int a=1,b=1,x;
        System.out.println(a);
        System.out.println(b);
        do
        {
            a+=b;
            System.out.println(a);
            b+=a;
            System.out.println(b);
        }
        while (true);
    }
}

Name: Anonymous 2011-02-13 18:57

>>24
lol u mad

Name: Anonymous 2011-02-14 1:32

>>24
Now make it lazy. The real power isn't in ..., which just saves a little typing. It's in :=, which saves a lot of typing.

Name: Anonymous 2011-02-14 1:51

>>26
Now make it lazy.

public class TakeItEasy
{
   public static void main(String []args)
   {
       System.out.println("

   _,,....,,_  _人人人人人人人人人人人人人人人_
-":::::::::::::`>   ゆっくりしていってね!!!   <
ヽ::::::::::::::::::::: ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^ ̄
 |::::::;ノ´ ̄\:::::::::::\_,. -‐ァ     __   _____   ______
 |::::ノ   ヽ、ヽr-r'"´  (.__    ,´ _,, '-´ ̄ ̄`-ゝ 、_ イ、
_,.!イ_  _,.ヘーァ'二ハ二ヽ、へ,_7   'r ´          ヽ、ン、
::::::rー''7コ-‐'"´    ;  ', `ヽ/`7 ,'==─-      -─==', i
r-'ァ'"´/  /! ハ  ハ  !  iヾ_ノ i イ iゝ、イ人レ/_ルヽイ i |
!イ´ ,' | /__,.!/ V 、!__ハ  ,' ,ゝ レリイi (ヒ_]     ヒ_ン ).| .|、i .||
`!  !/レi' (ヒ_]     ヒ_ン レ'i ノ   !Y!""  ,___,   "" 「 !ノ i |
,'  ノ   !'"    ,___,  "' i .レ'    L.',.   ヽ _ン    L」 ノ| .|
 (  ,ハ    ヽ _ン   人!      | ||ヽ、       ,イ| ||イ| /
,.ヘ,)、  )>,、 _____, ,.イ  ハ    レ ル` ー--─ ´ルレ レ´
");
   }
}

Name: Anonymous 2011-02-15 4:39

>>12
Get the fuck back to your russian imageboards.

Name: Anonymous 2011-09-19 6:29

bampu

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List