%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Copyright (c) 2014 Scott Laufer % % % % Permission is hereby granted, free of charge, to any person obtaining a copy % % of this software and associated documentation files (the "Software"), to % % deal in the Software without restriction, including without limitation the % % rights to use, copy, modify, merge, publish, distribute, sublicense, and/or % % sell copies of the Software, and to permit persons to whom the Software is % % furnished to do so, subject to the following conditions: % % % % The above copyright notice and this permission notice shall be included in % % all copies or substantial portions of the Software. % % % % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR % % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, % % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE % % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER % % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING % % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS % % IN THE SOFTWARE % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (list.ps) run % load list library /k list:create def % create a list /ki list:it:create def % create an iterator /kj list:it:create def % create another iterator % put some values into the list k 42 list:push_front % 42 k 29 list:push_back % 42 29 k /x list:push_back % 42 29 /x k /$ list:push_back % 42 29 /x /$ k /v list:push_front % /v 42 29 /x /$ k 87 list:push_front % 87 /v 42 29 /x /$ % remove some values k list:pop_front % /v 42 29 /x /$ k list:pop_back % /v 42 29 /x % do some stuff with an iterator (* denotes iterator ki position) k ki list:first % */v 42 29 /x ki list:it:next % /v *42 29 /x ki list:it:next % /v 42 *29 /x ki 77 list:it:insert % /v 42 *29 77 /x ki list:it:delete % /v *42 77 /x ki 82 list:it:set % /v *82 77 /x % do some more stuff with multiple iterators (^ denotes iterator kj position) k ki list:first % */v 42 29 /x k kj list:last % */v 42 29 /x^ % print whether or not iterators point to the same member (false) ki kj list:it:same == ki list:it:next % /v *42 29 /x^ ki list:it:next % /v 42 *29 /x^ ki list:it:next % /v 42 29 */x^ % print whether or not iterators point to the same member (true) ki kj list:it:same == % print list length (4) k list:getcount == % print the list in forward order (========================================) == k ki list:first % move iterator to first member { ki list:it:is_end { exit } if % if we hit the end of the list, break out ki list:it:get == % get data under iterator and print it ki list:it:next % move iterator to next member } loop % print the list in reverse order (========================================) == k ki list:last % move iterator to last member { ki list:it:is_begin { exit } if % if we hit the start of the list, break out ki list:it:get == % get data under iterator and print it ki list:it:prev % move iterator to previous member } loop