Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Data List
- {
- List = c_nil ++ double * List .c_cons;
- }
- Data SearchTree
- {
- SearchTree = c_tnil ++ double * SearchTree * SearchTree .c_branch;
- }
- Scheme ToTree
- {
- Fun Construct
- {
- Fun Split
- {
- current = [2].~c_cons.[1];
- rest = [2].~c_cons.[2];
- next = ([1] * rest) .Split;
- Split =
- [1].~c_nil ->
- (c_nil * c_nil),
- [2].~c_nil ->
- (c_nil * c_nil),
- (current * [1]) .equal ->
- next,
- (current * [1]) .less ->
- (current * next.[1]) .c_cons * next.[2] ,
- next.[1] * (current * next.[2]) .c_cons;
- }
- pivot = [1].~c_cons.[1];
- rest = [1].~c_cons.[2];
- res = (pivot * rest) .Split;
- @ = [1].~c_nil ->
- c_tnil,
- (res.[1].~c_nil ->
- (res.[2].~c_nil ->
- (pivot * c_tnil * c_tnil) .c_branch,
- (pivot * c_tnil * (res.[2]).Construct) .c_branch)
- ,(res.[2].~c_nil ->
- (pivot * (res.[1]).Construct * c_tnil) .c_branch,
- (pivot * (res.[1]).Construct * (res.[2]).Construct) .c_branch));
- }
- Fun Contains
- {
- Fun or
- {
- or = [1] ->
- true,
- [2] ->
- true,
- false;
- }
- Contains = [1].~c_tnil ->
- false,
- (([1].~c_branch.[1]) * [2]) .equal ->
- true,
- ((([1].~c_branch.[2] * [2]).Contains) * (([1].~c_branch.[3] * [2]).Contains)) .or;
- }
- Fun RandomList
- {
- @ = ([2] * 0).equal -> c_nil,
- (([1] * (rand * ([2] * [1]).sub).mul).add * ([1] * ([2] * 1).sub).RandomList).c_cons;
- }
- // @ = ((
- // ((3.0 *
- // ((4.0 *
- // ((5.0 * (c_nil))
- // .c_cons))
- // .c_cons))
- // .c_cons)
- // .Construct)
- // * 4.0).Contains.print;
- @ = ((1*20).RandomList).Construct;
- }
- Application
- % ToTree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement