Let me tell you about Raku

@jjmerelo | git.io/raku-fosdem20

cc-by-sa

Previously known as

Perl 6

Long story short

It's a different language

But still

TIMTOWTDI

So

Let me tell you about Raku

But previously

What do many cool emerging languages do?

Unicode

is

important

It's all Greek to me

function isελληνικά(input) {
  const rελληνικά = /^\p{Script=Greek}$/u
  return rελληνικά.test(input)
}
console.log(isελληνικά('π'));
	    

λ FTW

+ Immutability

Warning: your loops are deprecated

(def elipsis (fn [n] (print "... ", n ) ))

(defn to-zero [n]
  (if (> n 0)
    (do
      (elipsis [n])
      (to-zero (dec n))
      )
    )
  )

(to-zero 3)

Postmodern assignment:

Destructuring arguments

Gradual typing

Kotlin and Derrida

data class Result (val result: Int, val treasure: Boolean)
fun main(args: Array<String>) {
        val search =  fun(attempt: Int): Result
        {
                val things = listOf( 3, 33, 333, 42, 1, 1, 111 )
                if ( attempt == 4  ) {
                        return Result( 42, true )
                } else {
                        return Result( things[attempt], false )
                }
        }
        val (value1, prize1) = search( 2 )
        println( "2 returns " + value1 + prize( prize1 )  )
        val (value2, prize2) = search( 4 )
        println( "4 returns " + value2 + prize( prize2 )  )
}              

Pattern matching for complex decisions

Avoiding if cascades

Scala-ing comparison

val points = (card: String) => {
  card match {
    case "Ace" => 11
    case "3"  => 10
    case "J"  => 2
    case "Q"  => 3
    case "K"  => 4
    case  _   => 0
  }
}

println("Ace ", points("Ace"))
println("7 ", points("7"))

Multiple dispatch

High performance implementation at your service

Suit up with Julia

@enum Suit ♣ ♦ ♥ ♠
@enum Palo Bastos Espadas Oros Copas

toString( n::Int, s::Suit ) = string( n, " ", s )
toString( n::Int, p::Palo ) = string( n, " de ", p )

println( toString( 3, ♦) )
println( toString( 7, Bastos ) ) 

Sloths will inherit the earth

Lazy evaluation FTW

Great for propagating: cascading

Lazy and cascaded in F#

let horadam =
    (0.0f, 1.0f) 
    |> Seq.unfold (fun (x, y) -> let z = 0.25f*x + 0.75f*y in Some(z, (y, z))) 
    |> Seq.append [0.0f; 1.0f]


let seq_15 = horadam |> Seq.take 15
printfn "First 15 %A" seq_15
              

Inheriting << composing

Traits, mixins and roles

Safe Rust-y traits

struct Card { value: String, suit: &'static str }

trait Lookup {
    fn lookup(self ) -> String;
}

impl Lookup for Card  {
    fn lookup(self ) -> String {
        self.value + " of " + self.suit
    }
}

fn main() {
    let ace_of_clubs = Card { value: "Ace".to_string(),
                               suit: "♣"
    };
    println!( "Card → {}", ace_of_clubs.lookup() );
}

              

Raku: Everything and the kitchen sink

Took me a while

Syntax is tricky

And there's a new Emacs mode to install

But I knew the concepts

Because I code in Raku

JJ Merelo

@jjmerelo github.com/JJ

multi sub collatz( 1 ) { return [1] }
multi sub collatz( Int $a where $a %% 2 ) { return collatz( ($a/2).Int ).prepend( $a )}
multi sub collatz( $a where not $a %% 2 ) { return collatz( $a*3 + 1 ).prepend($a)}

my @collatz = lazy gather for ١..١٠٠٠ { take collatz( $_ ); }

1..100 ==> map( { @collatz[ $_ ] }) ==> grep( *.elems > 15 ) ==> my @long-chains;

sub prefix:<⇈> ( $𝒾 ) {
    given @collatz[ $𝒾 ].elems {
        when $_ > 15 { return @collatz[ $𝒾 ] but "15-Collatz", @collatz[ $𝒾 ].elems }
        default  { @collatz[ $𝒾 ], @collatz[ $𝒾 ].elems }
    }
}

for ^10 -> $þ {
    my ($seq, $elems) = ⇈$þ;
    say "Sequence with $þ ", $seq.?Str eq "Collatz" ?? " is " !! " is not " , "15-Collatz";
}
          

Learn Raku to learn every single language

Or at least the cool ones.

Questions?

Comments?