Module: internal Author: Jonathan Bachrach Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND // BOOTED: define ... class ... end; //////////// // INTERFACE //////////// define constant = type-union(subclass(), ); // Functions on define open generic element-setter (new-value, collection :: , key) => new-value; define open generic replace-elements! (collection :: , predicate :: , new-value-fn :: , #key count :: false-or() = #f) => (mutable-collection :: ); define open generic fill! (collection :: , value, #key start :: = 0, end: last :: ) => (mutable-collection :: ); ///////////////// // IMPLEMENTATION ///////////////// // // REPLACE-ELEMENTS! // define method replace-elements! (collection :: , predicate? :: , new-value-function :: , #key count :: false-or() = #f) => (collection :: ) with-fip-of collection /* Use with-setter? */ if (count) let count :: = count; for (state = initial-state then next-state(collection, state), until: count = 0 | finished-state?(collection, state, limit)) let element = current-element(collection, state); if (predicate?(element)) current-element(collection, state) := new-value-function(element); count := count - 1 end if; end for else for (state = initial-state then next-state(collection, state), until: finished-state?(collection, state, limit)) let element = current-element(collection, state); if (predicate?(element)) current-element(collection, state) := new-value-function(element); end if; end for; end; collection end with-fip-of end method replace-elements!; // // FILL! // define method fill! (collection :: , value, #key start, end: last) => (collection :: ) // Ignore start: and end: in the non-sequence case with-fip-of collection for (state = initial-state then next-state(collection, state), until: finished-state?(collection, state, limit)) current-element(collection, state) := value; end for; /* Use with-setter? */ end with-fip-of; collection end method fill!; // // Specialized inherited generic methods // // // TYPE-FOR-COPY // define method type-for-copy (collection :: ) => (class :: subclass()) collection.object-class end method type-for-copy; // // ELEMENT-NO-BOUNDS-CHECK-SETTER // define open generic element-no-bounds-check-setter (new-value, collection :: , key) => new-value; define inline method element-no-bounds-check-setter (new-value, collection :: , key) => new-value; element-setter(new-value, collection, key) end method element-no-bounds-check-setter;