Skip to content

Commit

Permalink
use fancy syntax highlighting for code samples using github-flavored …
Browse files Browse the repository at this point in the history
…markdown
  • Loading branch information
bakkdoor committed Nov 22, 2011
1 parent 2d05204 commit 7daf26b
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 186 deletions.
105 changes: 62 additions & 43 deletions Chapter01.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ Let's have a look at how this looks syntactically.


**No arguments:** **No arguments:**


object message_name ```fancy
object message_name
```


**Single argument:** **Single argument:**


object message_name: arg ```fancy
object message_name: arg
```


Is a message send to `object` with a message called `message_name:` Is a message send to `object` with a message called `message_name:`
and an argument `arg`. As in Smalltalk (or Objective-C, which is and an argument `arg`. As in Smalltalk (or Objective-C, which is
Expand All @@ -69,7 +73,9 @@ argument is preceeded by a keyword (usually describing the argument).


**Multiple arguments:** **Multiple arguments:**


object foo: arg1 bar: arg2 baz: arg3 ```fancy
object foo: arg1 bar: arg2 baz: arg3
```


The above shows a message send with three arguments for the The above shows a message send with three arguments for the
`foo:bar:baz:` message. If `object`, its class or any superclass `foo:bar:baz:` message. If `object`, its class or any superclass
Expand All @@ -80,9 +86,11 @@ Ruby's `method_missing`).


Lets look at a more real-world example: Lets look at a more real-world example:


[1,2,3] each: |x| { ```fancy
x println [1,2,3] each: |x| {
} x println
}
```


This peace of code shows a message send to a literal Array consisting This peace of code shows a message send to a literal Array consisting
of the three number values **1**, **2** and **3**. The `each:` method of the three number values **1**, **2** and **3**. The `each:` method
Expand All @@ -109,9 +117,11 @@ like any other though.
The `println` send to `x` causes it to be displayed on The `println` send to `x` causes it to be displayed on
`STDOUT`. Here's the implementation of `println`: `STDOUT`. Here's the implementation of `println`:


def println { ```fancy
Console println: (self to_s) def println {
} Console println: (self to_s)
}
```


You can find the code in *lib/object.fy* within Fancy's root source You can find the code in *lib/object.fy* within Fancy's root source
directory or just directory or just
Expand All @@ -134,62 +144,71 @@ programming languages.


**If/Else:** **If/Else:**


x < y if_true: { ```fancy
"x is smaller than y" println x < y if_true: {
} else: { "x is smaller than y" println
"x is NOT smaller than y" println } else: {
} "x is NOT smaller than y" println
}
```


The `else:` part can be ommited, as there's also a method `if_true:` The `else:` part can be ommited, as there's also a method `if_true:`
defined apart from `if_true:else:`. You can also write it the defined apart from `if_true:else:`. You can also write it the
following (although longer) way: following (although longer) way:


if: (x < y) then: { ```fancy
"x is smaller than y" println if: (x < y) then: {
} else: { "x is smaller than y" println
"x is NOT smaller than y" println } else: {
} "x is NOT smaller than y" println
}
# there's also this additional way of doing something conditionally: # there's also this additional way of doing something conditionally:
{ "x is smaller than y" println } if: (x < y) { "x is smaller than y" println } if: (x < y)
```




**While:** **While:**


x = 0 ```fancy
{ x < 10 } while_true: { x = 0
x println { x < 10 } while_true: {
x = x + 1 x println
} x = x + 1
}
# or: # or:
x = 0 x = 0
while: { x < 10 } do: { while: { x < 10 } do: {
x println x println
x = x + 1 x = x + 1
} }
```




**Endless loop:** **Endless loop:**


loop: { ```fancy
# do something here and possibly return when done loop: {
} # do something here and possibly return when done

}
```


**For-loop:** **For-loop:**


10 times: |i| { ```fancy
i println # will print 0 - 9 10 times: |i| {
} i println # will print 0 - 9
}
# or: # or:
0 upto: 9 do_each: |i| { 0 upto: 9 do_each: |i| {
i println # same here. i println # same here.
} }
```




#### In [Chapter 2][], we'll have a look how class & method definitions work in Fancy. #### #### In [Chapter 2][], we'll have a look how class & method definitions work in Fancy. ####
Expand Down
Loading

0 comments on commit 7daf26b

Please sign in to comment.