Files
wren/doc/site/getting-started.markdown
T
Bob Nystrom d791dd0d7c docs: add Getting Started page with setup instructions and interactive mode examples
Add a comprehensive Getting Started guide covering Unix/Mac installation via git clone and make, interactive mode usage with code examples, and script execution with a Mandelbrot fractal demo. Also update the site navigation template to link the new page, add placeholder pages for Embedding, Error Handling, and Getting Involved, fix the index page link from "usage.html" to "embedding.html", and reorder the types section in the nav to list Fibers before Functions.
2014-04-09 14:53:30 +00:00

2.5 KiB

^title Getting Started

Getting Wren up and running on your machine should be pretty straightforward. Tiny C programs with no dependencies are nice that way. If you're on a Unix or Mac and you can rock a command line, it's just:

:::bash
$ git clone https://github.com/munificent/wren.git
$ cd wren
$ make
$ ./wren

For Mac users, there is also an XCode project in the repo that you can use to hack on Wren. That's what I develop in. It builds fine from there but may not have the exact same build settings. The Makefile is the canonical way to compile it.

For our Windows bretheren, there's still a little work to be done. Ideally, the repo would include a Visual Studio solution for building Wren. I don't have a Windows machine, but if someone does, I would be delighted to take a patch for this.

Interactive mode

The above instructions will drop you into Wren's standalone interpreter in interactive mode. In that mode, you can type a line of code in, and it will immediately execute it. Here's something to try:

:::dart
IO.print("Hello, world!")

Or a little more exciting:

for (i in 1..10) IO.print("Counting up ", i)

You can exit the interpreter using good old Ctrl-C or Ctrl-D, or just throw your computer to the ground and storm off.

Running scripts

The standalone interpreter can also load scripts from files and run them. Just pass the name of the script to wren. Copy and paste this into a file named my_first_script.wren:

:::dart
for (yPixel in 0...24) {
  var y = yPixel / 12 - 1
  for (xPixel in 0...80) {
    var x = xPixel / 30 - 2
    var x0 = x
    var y0 = y
    var iter = 0
    while (iter < 11 && x0 * x0 + y0 * y0 <= 4) {
      var x1 = (x0 * x0) - (y0 * y0) + x
      var y1 = 2 * x0 * y0 + y
      x0 = x1
      y0 = y1
      iter = iter + 1
    }
    IO.write(" .-:;+=xX$& "[iter])
  }

  IO.print("")
}

Now run:

:::bash
$ ./wren my_first_script.wren

Neat, right? You're a Wren programmer now! The next step is to read more docs here and learn your way around the language. If you run into bugs, or have ideas or questions, any and all of the following work: