Try it! Reset!

# Print "Hello, world!"

p "Hello, world!"
# Compute a factorial

factorial = { x |
  true? x == 0 1 { x * factorial(x - 1)}
}

factorial 10
# Use a function as an argument to another function

add = { a, b | a + b }
 
doit = { f, a, b | f a, b }
 
doit ->add 1 2
# Reverse a string

"stop".reverse
# Count down from 10 to 1

10.to 1 { i | p i }
# Select only even numbers from an array

1.to(10).select { x | x % 2 == 0 }
# Simulate a deck of cards

#Card object
card = object.new

card.init = { pip, suit |
  my.pip = pip
  my.suit = suit
}

card.suits = [ :Clubs :Hearts :Spades :Diamonds ]
card.pips = 2.to(10) + [ :Jack :Queen :King :Ace ]

card.prototype.to_s = {
  "#{my.pip} of #{my.suit}"
}

# Deck object
deck = object.new

deck.init = {
  cards = []
  card.suits.each { suit |
    card.pips.each { pip |
      cards << card.new pip, suit
    }
  }

  my.cards = cards
}

deck.prototype [
  shuffle: 
  {
    my.cards.shuffle!
    my
  }

  deal: { num |
    my.cards.pop num
  }

  to_s: {
    my.cards.to_s
  }
]

d = deck.new.shuffle
p "Number of cards in deck: #{d.cards.length}"
p "Hand of five cards: #{d.deal(5)}"
p "Number of cards remaining: #{d.cards.length}"
#*

 Type Brat code into the this box and click "Try it!"

 Output from the program is shown above the dashed line. The return value of the evaluated code is shown below the line.

 Interactive programs are not possible at this time.

*#