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

Perl6 thread

Name: Anonymous 2011-01-09 22:35

There are too many ways to do it.

The completely backwards way:

> sub foo(&f) { f() }
{ "hi".say }.&foo();
hi


On the other hand, closures are much nicer now (JavaScript needs this):
> say (1,2,3,4,5).reduce: { $^a + $^b };
15

Note about .reduce: it only supports binary functions.

A note on operators:
Hyperops, eg: (1,2,3,4) «+» (5,6,7,8)
These are permitted to auto-parallelize (implementation dependent.)
Lazy meta-ops, eg: 1,2,3,4 Z+ 5,6,7,8
These support lazy evaluation. The result is generated as needed.
Reduction meta-ops, eg: [+] 1,2,3,4,5
Triangular reduction: [code][\+] 1,2,3,4,5 # result is (1,3,6,10,15)[code]
These are basically .reduce(*[b][i]op[/i][/b]*) with the binary operator provided.

Name: Anonymous 2011-01-18 18:06

damn, perl6 is so cool.... we use a lot the Mod 11 Check Digit algorithm in my country for calculating the rut (the unique identifier for people in Chile)... now here is on one line!!!!!


my $rut = "1234567"; my $checksum = (0 .. 9,'K', 0)[ 11 - ( [+] $rut.split('').reverse <<*>> (2..7) ) % 11 ]; say $rut~'-'~$checksum;


Sauce:
http://en.wikipedia.org/wiki/MSI_Barcode#Mod_11_Check_Digit

Wanna test with other numbers?
http://joaquinnunez.cl/jQueryRutPlugin/generador-de-ruts-chilenos-validos.html

It has a bug, though. Does not work with, for example, "1", which should return "1-9". For real life applications is not important (such small rut numbers does not exists those days), but it's still a shortcoming.

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