Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile

(Extracted from Practicing Ruby Issue 7.1)

Exploratory programming as a first-class paradigm?

Even though we've managed to pack a lot of interesting behavior into a small amount of code, the examples I've shown here barely scratch the surface of StarLogo and capabilities. While my Terrarium engine is nothing more than a poor man's implementation of a few of StarLogo's features, the full StarLogo language is elegantly designed and carefully thought out.

But the goal of this article was not to introduce you to a shiny piece of technological infrastucture, it was meant to get you thinking about a different kind of workflow than what we tend to use day to day. Even through the smudged window I've had you look through, it should be clear to see that the style of programming used in StarLogo has several powerful benefits:

  • Thoughts can be expressed directly
  • Feedback is given continuously
wumpus_room = rand(2..10)
current_room = 1
loop do
puts
if current_room == 0
puts "You escaped the cave unharmed,"
puts "but the wumpus still lurks in the shadows. GAME OVER!"
exit

"What in the world is a Wumpus?", Ruth asked.

"It's a terrible cave-dwelling beast", said Grandpa Joe, "and by golly, we're going to hunt it!"

Ruth looked at the old man and sighed deeply. It would seem that she had got her hopes up for nothing, and that today would be the usual mix of boring and crazy she had come to expect from her grandfather.

bats = Hazard.new(:bats)
bats.sensed("You hear a rustling sound.")
bats.encountered do |narrator|
narrator.say("Giant bats whisk you away to a new cavern!")
new_room = random_room
move(:bats, from: current_room, to: new_room)
@practicingruby
practicingruby / x.rb
Last active December 30, 2015 01:08
Tests for a game object in "Hunt The Wumpus". Please help improve its clarity.
require_relative "../helper"
describe "A room" do
let(:room) { Wumpus::Room.new(12) }
it "has a number" do
room.number.must_equal(12)
end
it "may contain hazards" do
def ellipse(point, r1, r2 = r1)
x, y = point
l1 = r1 * KAPPA
l2 = r2 * KAPPA
create_path do |path|
path.move(x + r1, y)
.curve(x, y + r2, x + r1, y + l2, x + l1, y + r2)
.curve(x - r1, y, x - l1, y + r2, x - r1, y + l2)
.curve(x, y - r2, x - r1, y - l2, x - l1, y - r2)
require "prawn"
class CustomReport
def initialize(document)
@document = document
end
def header(message)
draw { text(message, :size => 32) }
end
test() ->
12 = area({rectangle, 3, 4}),
144 = area({square, 12}),
tests_worked.
my_tuple_to_list({}) -> [];
my_tuple_to_list(T) ->
[erlang:element(1, T) | my_tuple_to_list(erlang:delete_element(1, T))].
my_time_func(F) ->
{MegaS@T1, S@T1, MicroS@T1 } = erlang:now(),
F(),
{MegaS@T2, S@T2, MicroS@T2 } = erlang:now(),
(MegaS@T2 - MegaS@T1)*1000000 + (S@T2 - S@T1) + (MicroS@T2 - MicroS@T1)/1000000.