lib/contracts.fy in fancy-0.6.0 vs lib/contracts.fy in fancy-0.7.0
- old
+ new
@@ -1,60 +1,57 @@
-class Object {
- def require: require_block ensure: ensure_block body: body_block {
- requirement = Contract Requirement new: require_block
- ensurance = Contract Requirement new: ensure_block
- retval = nil
- requirement if_fullfilled: {
- retval = body_block call
- }
- ensure_block if_fullfilled: {
- retval
- }
- }
+# class Class {
+# class Contracts {
+# class ConditionBuilder : Proxy {
+# def initialize: block for: @method class: @class {
+# @conditions = <[]>
+# block call: [self]
+# insert_validations
+# }
- def require: require_block body: body_block {
- requirement = Contract Requirement new: require_block
- requirement if_fullfilled: {
- body_block call
- }
- }
+# def unknown_message: m with_params: p {
+# if: (p size > 0 ) then: {
+# @conditions[m to_s[[0,-2]]]: $ p first
+# }
+# }
- def ensure: ensure_block body: body_block {
- require: ensure_block body: body_block
- }
-}
+# def insert_validations {
+# name = @method name()
+# alias_name = "__#{name}__orig__"
+# conditions = @conditions
-class Contract {
- class RequirementError : RuntimeError
- class Requirement {
- def initialize: @block
- def if_fullfilled: block {
- @block call: [self]
- block call
- }
- def true: expr {
- { RequirementError new: "#{expr} not true" . raise! } unless: expr
- }
- def false: expr {
- { RequirementError new: "#{expr} not false" . raise! } if: expr
- }
- }
-}
-
-# # usage:
-# class Fixnum {
-# def / other {
-# require: @{
-# true: $ other is_a?: Fixnum
-# true: $ other > 0
-# # better:
-# other class is: Fixnum
-# other is > 0
-#
-# } body: {
-# "foo" println
+# @class alias_method: alias_name for: name
+# @class define_method: name with: |p| {
+# conditions each: |attr block| {
+# # TODO
+# }
+# receive_message: alias_name with_params: p
+# }
+# }
# }
# }
+
+# def preconditions: block for: method {
+# Contracts ConditionBuilder new: block for: method class: self
+# }
+
+# def postconditions: block for: method {
+# Contracts ConditionBuilder new: block for: method class: self
+# }
# }
-# f = 10 / 2
-# g = 10 / 0 # requirement error
+# # example
+
+# class Person {
+# read_slots: ('name, 'age)
+
+# preconditions: @{
+# name: @{ blank? not }
+# age: @{ > 0 }
+# } for: $ def initialize: @name age: @age
+# }
+
+
+# p = Person new: "chris" age: 25
+# p inspect println
+
+
+nil
\ No newline at end of file