Martin Fowler's Ruby examples (http://www.martinfowler.com/bliki/Closure.html), in my proposed Fan syntax:
///////////////////////////////////////////////////////////////////// // Ruby ///////////////////////////////////////////////////////////////////// def managers(emps) return emps.select {|e| e.isManager} end def highPaid(emps) threshold = 150 return emps.select {|e| e.salary > threshold} end def paidMore(amount) return Proc.new {|e| e.salary > amount} end highPaid = paidMore(150) john = Employee.new john.salary = 200 print highPaid.call(john) ///////////////////////////////////////////////////////////////////// // Fan ///////////////////////////////////////////////////////////////////// Employee[] managers(Employee[] emps) { return emps.findAll |Employee e->Bool| { return e.isManager } } Employee[] highPaid(Employee[] emps) { threshold := 150 return emps.findAll |Employee e->Bool| { return e.salary > threshold } } Method paidMore(Int amount) { return |Employee e->Bool| { return e.salary > amount } } highPaid := paidMore(150) john := Employee.make john.salary = 200 echo highPaid(john)
Login or Signup to reply.
brian Tue 17 Jan 2006
Martin Fowler's Ruby examples (http://www.martinfowler.com/bliki/Closure.html), in my proposed Fan syntax: