Permalink
Browse files

cleanup examples/ dir

  • Loading branch information...
1 parent b83f7dc commit ed8e66f738bb56b125612b4a79850d7eec46286c @bakkdoor committed Aug 7, 2012
View
@@ -1,7 +0,0 @@
-# arithmetic.fy
-# Example of some basic arithmetic operations in fancy
-
-23 + 32432.32 println
-324432.432 - 32432.4324 println
-32432 * 432.32 println
-432 / 12319 println
@@ -5,8 +5,10 @@
class Fixnum {
def decimals {
- """Returns all decimals of a Number as an Array.
- E.g. 123 decimals # => [1,2,3]"""
+ """
+ Returns all decimals of a Number as an Array.
+ E.g. 123 decimals # => [1,2,3]
+ """
decimals = []
tmp = self
@@ -19,7 +21,9 @@ class Fixnum {
}
def armstrong? {
- "Indicates, if a Number is a Armstrong Number."
+ """
+ Indicates, if a Number is a Armstrong Number.
+ """
decimals = self decimals
n_decimals = decimals size
View
@@ -1,50 +0,0 @@
-# array.fy
-# Examples of fancy Arrays
-
-# create an array
-arr = [1,2,3,4,5,6]
-
-# print each element squared
-arr each: @{ squared println }
-
-# display each element with its index in the array
-arr each_with_index: |x i| {
- "Index " ++ i ++ " -> " ++ x println
-}
-
-# print the array of squared elements
-arr map: 'squared . inspect println
-
-# print the array of doubled elements
-arr map: 'doubled . inspect println
-
-# print array of all elements smaller than 4
-arr select: @{ < 4 } . inspect println
-
-# print array of all elements that are not smaller than 4
-arr reject: @{ < 4 } . inspect println
-
-# prints: [5, 6]
-arr take_while: @{ < 5 } . inspect println
-
-"testing reduce:init_val: " print
-arr reduce: |acc x| { acc * x } init_val: 1 . println # same as: 1*1*2*3*4*5*6
-
-"testing any?: " print
-arr any?: @{ > 3 } . println # prints: true
-
-"testing all?: " print
-arr all?: @{ < 7 } . println # prints: true
-
-"testing from:to: " print
-arr [[3,5]] . inspect println # prints: [4, 5, 6]
-
-# some other handy methods
-"testing size: " print
-arr size println # prints: 6
-
-"testing to_s: " print
-arr to_s println # prints: 123456
-
-"testing inspect: " print
-arr inspect println # prints: [1, 2, 3, 4, 5, 6]
View
@@ -1,15 +1,15 @@
# blocks.fy
# Examples of fancy code blocks
-x = { Console println: "Println from within block!" }
+x = { "Println from within block!" println }
x call # calls x and prints: "Println from within block!"
-y = |x y| { Console println: $ x + y }
+y = |x y| { x + y println }
y call: [2, 3] # calls y and prints: 5
# prints numbers 0 to 20
num = 0
while: { num <= 20 } do: {
- Console println: num
+ num println
num = num + 1
}
View
@@ -1,24 +0,0 @@
-# boolean.fy
-# Example of boolean expressions and logical operations in fancy
-
-true and: true . println # true
-true and: nil . println # nil
-nil and: nil . println # nil
-
-true or: true . println # true
-true or: nil . println # true
-nil or: nil . println # nil
-
-
-"--------------" println
-
-# won't print string
-nil if_true: {
- "this should _not_ be displayed" println
-}
-
-# will print string
-nil if_false: {
- "this _should_ be displayed" println
-}
-
View
@@ -1,68 +0,0 @@
-# class.fy
-# Example of fancy's classes mechanism
-
-class Bar {
- def initialize {
- Console println: "In Bar constructor!"
- }
-
- def say_hello: name {
- Console print: "Hello, "
- Console println: name
- }
-}
-
-class Foo : Bar {
- def initialize: name {
- Console println: "gonna set @name"
- @name = name
- }
- def say_hello {
- Console print: "Hello, "
- Console println: @name
- { @block call } if: @block
- }
- def on_hello_do: block {
- @block = block
- }
-}
-
-bar = Bar new
-bar say_hello: "Chris"
-
-foo = Foo new: "Chris from Constructor"
-foo say_hello
-foo on_hello_do: {
- Console println: "Call me when calling on_hello! :)"
-}
-foo say_hello
-
-foo class println # print the class of foo
-
-# define a singleton method on foo object
-foo define_singleton_method: "foo!" with: {
- "In foo method :D" println
-}
-
-foo foo!
-
-# define a 'normal' method on Foo class
-# (instance method for all instances of Foo)
-foo class define_method: "foo_for_all:" with: |x| {
- "In foo_for_all method (defined for all instances of Foo class)" println
- "Got argument: " ++ x println
-}
-
-foo2 = Foo new
-foo2 foo_for_all: "hello, test! :)"
-foo foo_for_all: "hello, test (again)! :)"
-
-# define a class method on Foo class
-# it's the same as calling 'define_singleton_method:with:' on class
-foo class define_class_method: "cool_class_method:" with: |arg| {
- "In class method for Foo! Argument given: " ++ arg println
-}
-
-# the following is the same as:
-# foo class cool_class_method: "Some argument string"
-Foo cool_class_method: "Some argument string"
@@ -1,15 +0,0 @@
-class Foo {
- class Bar {
- def self name { 'bar }
- }
-}
-
-Foo Bar name println
-
-class Foo Baz
-
-Foo Baz == Foo::Baz println
-
-def Foo Baz name { 'baz }
-
-Foo Baz name println
View
@@ -1,20 +0,0 @@
-# default_args.fy
-# Example of fancy's default arguments
-
-def arg1: arg1 ("default_arg1") arg2: arg2 ("default_arg2") arg3: arg3 ("default_arg3") {
- "arguments are: " println
- arg1 println
- arg2 println
- arg3 println
-}
-
-arg1: "hello" arg2: "world" arg3: "how are you?"
-
-Console newline
-arg1: "hello" arg2: "world"
-
-Console newline
-arg1: "hello"
-
-Console newline
-arg1
View
@@ -1,15 +0,0 @@
-arr = [1,2,3]
-arr define_singleton_method: "foo" with: {
- "in foo!" println
- self inspect println
-}
-
-arr receive_message: 'foo
-
-arr undefine_singleton_method: "foo"
-
-try {
- arr receive_message: 'foo
-} catch NoMethodError => e {
- e println
-}
View
@@ -1,15 +0,0 @@
-# *stdout* refers to STDOUT
-File open: "/tmp/foo.txt" modes: ['write] with: |f| {
- let: '*stdout* be: f in: {
- # *stdout* refers to f
- # "foo" will be written to /tmp/foo.txt
- # and not STDOUT
- "foo" println
- }
-}
-File open: "/tmp/foo.txt" modes: ['read] with: |f| {
- let: '*stdin* be: f in: {
- *stdin* readln println # => prints "foo" to *stdout*
- }
-}
-# *stdout* refers to STDOUT
View
@@ -1,4 +0,0 @@
-try {
- "Empty catch" println
-} catch StdError => e {
-}
View
@@ -1,9 +0,0 @@
-try {
- "Hola" println
- StdError new: "Hello" . raise!
- "Hi" println
-} catch StdError => e {
- e println
-} finally {
- "Adios" println
-}
View
@@ -1,23 +0,0 @@
-# files.fy
-# File handling examples
-
-{
- Directory create: "tmp/"
-} unless: $ Directory exists?: "tmp/"
-
-File open: "tmp/Hello-World.txt" modes: ['write] with: |f| {
- f writeln: "Hello, world"
-}
-
-File delete: "tmp/Hello-World.txt"
-
-arr = [1,2,3,4]
-File open: "tmp/Array-Test.txt" modes: ['write] with: |f| {
- arr each: |x| {
- f writeln: x
- }
-}
-
-File delete: "tmp/Array-Test.txt"
-
-Directory delete: "tmp/"
View
@@ -1,5 +0,0 @@
-try {
- "Hello" println
-} finally {
- "World" println
-}
View
@@ -1,30 +0,0 @@
-def foo {
- Thread sleep: 3
- "FOO"
-}
-
-def + other {
- Thread sleep: 1.5
- "PLUS"
-}
-
-def baz: num {
- Thread sleep: (num * 0.5)
- "BAZ"
-}
-
-"Start" println
-
-f = self @ foo
-f println # print future object
-?f println # access and print the future's value
-
-f = self @ + 10
-f println
-?f println
-
-f = self @ baz: 10
-f println
-?f println
-
-"End" println
@@ -1,20 +0,0 @@
-# example of composing futures:
-
-def do_large_computation: x {
- x upto: (x ** x)
-}
-
-# FutureSend#&& takes a Block (or a Callable - something that implements 'call:)
-# and creates a new FutureSend that executes the given Block with the value of the first FutureSend
-# when it has finished its computation. This makes pipelining tasks easy.
-
-f = self @ do_large_computation: 5 && @{select: 'even?} && @{inspect println}
-"computing .. " println
-f value
-
-#the above is the same as:
-# f = self @ do_large_computation: 5
-# f = f when_done: @{select: 'even?}
-# f = f when_done: @{inspect println}
-# "computing .. " println
-# f value
View
@@ -1,9 +0,0 @@
-fs = []
-100 times: |i| {
- f = { Thread sleep: 0.5; i println } @ call
- fs << f
-}
-
-"Waiting" println
-fs each: 'value
-"Done" println
Oops, something went wrong.

0 comments on commit ed8e66f

Please sign in to comment.