DIRECTORY Lists, Rope; ListsImpl: CEDAR PROGRAM IMPORTS Rope EXPORTS Lists = BEGIN ROPE: TYPE = Lists.ROPE; ReverseList: PUBLIC PROC [list: LIST OF ROPE] RETURNS [new: LIST OF ROPE] = {FOR list _ list, list.rest WHILE list#NIL DO new _ CONS[list.first, new] ENDLOOP}; ReverseLIST: PUBLIC PROC [list: LIST OF REF] RETURNS [new: LIST OF REF] = {FOR list _ list, list.rest WHILE list#NIL DO new _ CONS[list.first, new] ENDLOOP}; ListLength: PUBLIC PROC [list: LIST OF ROPE] RETURNS[size: INT] = {FOR size _ 0, size+1 WHILE list#NIL DO list_list.rest ENDLOOP}; LISTLength: PUBLIC PROC [list: LIST OF REF] RETURNS[size: INT] = {FOR size _ 0, size+1 WHILE list#NIL DO list_list.rest ENDLOOP}; ListIndexItem: PUBLIC PROC [list: LIST OF ROPE, index: INT] RETURNS[item: ROPE] = { FOR index _ index, index-1 WHILE index#0 AND list#NIL DO list_list.rest ENDLOOP; RETURN[IF list=NIL THEN NIL ELSE list.first]}; LISTIndexItem: PUBLIC PROC[list: LIST OF REF, index: INT] RETURNS[item: REF] = { FOR index _ index, index-1 WHILE index#0 AND list#NIL DO list_list.rest ENDLOOP; RETURN[IF list=NIL THEN NIL ELSE list.first]}; ListItemIndex: PUBLIC PROC [list: LIST OF ROPE, item: ROPE] RETURNS[index: INT] = { IF item=NIL THEN RETURN[-1]; FOR index _ 0, index+1 WHILE list#NIL DO IF Rope.Equal[list.first, item, FALSE] THEN RETURN[index]; list_list.rest ENDLOOP; RETURN[-1]}; ListItemIndexMax: PUBLIC PROC [list: LIST OF ROPE, item: ROPE] RETURNS[index: INT] = { count: INT _ -1; index _ -1; IF item=NIL THEN RETURN[-1]; FOR list _ list, list.rest WHILE list#NIL DO count _ count+1; IF Rope.Equal[list.first, item] THEN index _ count ENDLOOP}; ListItemIndexMin: PUBLIC PROC [list: LIST OF ROPE, item: ROPE] RETURNS[index: INT] = { IF item=NIL THEN RETURN[-1]; FOR index _ 0, index+1 WHILE list#NIL DO IF Rope.Equal[list.first, item] THEN RETURN[index]; list_list.rest ENDLOOP; RETURN[-1]}; ListNonNILIndexMin: PUBLIC PROC [list: LIST OF ROPE] RETURNS[index: INT] = { FOR index _ 0, index+1 WHILE list#NIL DO IF list.first#NIL THEN RETURN[index]; list_list.rest ENDLOOP; RETURN[-1]}; ListNonNILIndexMax: PUBLIC PROC [list: LIST OF ROPE] RETURNS[index: INT] = { count: INT _ -1; index _ -1; FOR list _ list, list.rest WHILE list#NIL DO count _ count+1; IF list.first#NIL THEN index _ count ENDLOOP}; ListAllNil: PUBLIC PROC [list: LIST OF ROPE] RETURNS[allNIL: BOOL] = {FOR list _ list, list.rest WHILE list#NIL DO IF list.first#NIL THEN RETURN[FALSE]; ENDLOOP; RETURN[TRUE]}; ListConcat: PUBLIC PROC [list1, list2: LIST OF ROPE] RETURNS[new: LIST OF ROPE] = { FOR i: INT DECREASING IN [0..ListLength[list2]) DO new _ CONS[ ListIndexItem[list2, i], new] ENDLOOP; FOR i: INT DECREASING IN [0..ListLength[list1]) DO new _ CONS[ ListIndexItem[list1, i], new] ENDLOOP}; END. ŠListsImpl.mesa, Copyright c 1986 by Xerox Corporation. All rights reserved. Last Edited by Curry, March 11, 1986 9:59:09 pm PST Ê’˜šœ™Jšœ<™