pdco.icn: Procedures for programmer-defined control operations

procedure AddTabbyPDCO:    PDCO to add tabby to treadling
procedure AllparAER:       PDAE for parallel evaluation with repeats
procedure AltPDCO:         PDCO to model alternation
procedure BinopPDCO:       PDCO to apply binary operation to sequences
procedure CFapproxPDCO:    PDCO for continued-fraction approximations
procedure ComparePDCO:     PDCO to compare sequences
procedure ComplintPDCO:    PDCO to generate integers not in sequence
procedure CondPDCO:        PDCO for generalized Lisp conditional
procedure CumsumPDCO:      PDCO to produce cumulative sum
procedure CycleparAER:     PDAE for parallel evaluation with cycling
procedure DecimatePDCO:    PDCO to decimate sequence
procedure DecimationPDCO:  PDCO to create decimation sequence
procedure DecollatePDCO:   PDCO to decollate sequence
procedure DeltaPDCO:       PDCO to generate difference sequence
procedure ElevatePDCO:     PDCO to elevate sequence
procedure EveryPDCO:       PDCO to model iteration
procedure ExtendSeqPDCO:   PDCO to extend sequence
procedure ExtractAER:      PDAE to extract values
procedure FifoAER:         PDAE for reversal of lifo evaluation
procedure GaltPDCO:        PDCO to concatenate sequences
procedure GconjPDCO:       PDCO for generalized conjunction
procedure HistoPDCO:       histogram
procedure IncreasingPDCO:  PDCO to filter out non-increasing values
procedure IndexPDCO:       PDCO to select terms by position
procedure InterPDCO:       PDCO to interleave sequences
procedure LcondPDCO:       PDCO for Lisp conditional
procedure LengthPDCO:      PDCO to produce length of sequence
procedure LifoAER:         PDAE for standard lifo evaluation
procedure LimitPDCO:       PDCO to model limitation
procedure ListPDCO:        list from sequence
procedure LowerTrimPDCO:   lower trimming
procedure MapPDCO:         PDCO to map values
procedure OddEvenPDCO:     PDCO to force odd/even sequence
procedure PalinPDCO:       PDCO to produce palindromic sequence
procedure ParallelPDCO:    synonym for Inter
procedure ParallelAER:     PDAE for parallel evaluation
procedure PatternPalinPDCO PDCO to produce pattern palindrome
procedure PeriodPDCO:      PDCO for periodic part of sequence
procedure PermutePDCO:     PDCO for permutations
procedure PivotPDCO:       PDCO to generate pivot points
procedure RandomPDCO:      PDCO to generate from sequences at random
procedure RepaltPDCO:      PDCO to model repeated alternation
procedure ReducePDCO:      PDCO to reduce sequence using binary operation
procedure RepeatPDCO:      PDCO to repeat sequence
procedure RemoveDuplPDCO:  PDCO for remove duplicate values in a sequence
procedure ReplPDCO:        PDCO to replicate values in a sequence
procedure ResumePDCO:      PDCO to model limited iteration
procedure ReversePDCO:     PDCO to reverse sequence
procedure RotatePDCO:      PDCO to rotate sequence
procedure SelfreplPDCO:    PDCO to produce multiple of values in sequence
procedure SeqlistPDCO:     PDCO to return list of values
procedure SimpleAER:       PDAE for simple evaluation
procedure SkipPDCO:        PDCO to skip terms
procedure SmodPDCO:        generalized modular reduction
procedure SpanPDCO:        fill in gaps in integer sequences
procedure SumlimitPDCO:    PDCO to sum sequence to a limit
procedure TrinopPDCO:      PDCO to apply trinary operator to sequences
procedure UndulantPDCO:    PDCO to produce undulant
procedure UniquePDCO:      PDCO to filter out duplication values
procedure UnopPDCO:        PDCO to apply unary operation to sequence
procedure UpperTrimPDCO:   upper sequence trimming
procedure ValrptPDCO:      synonym for Repl
procedure WobblePDCO:      PDCO to produce sequence values alternately

link pdco
March 4, 2003; Ralph E. Griswold and Robert J. Alexander
Requires: co-expressions
This file is in the public domain.

These procedures use co-expressions to used to model the built-in
control structures of Icon and also provide new ones.

 AddTabbyPDCO{e, i}  adds tabby to treadling sequence

 AllparAER{e1,e2, ...}
                     parallel evaluation with last result
                     used for short sequences

 AltPDCO{e1,e2}      models e1 | e2

 BinopPDCO{op,e1,e2} produces the result of applying op to e1 and e2

 CFapproxPDCO{e}     produce sequence of approximations for the
                     continued-fraction sequence e

 ComparePDCO{e1,e2}  compares result sequences of e1 and e2

 ComplintPDCO{e}     produces the integers not in e

 CondPDCO{e1,e2, ...}
                     models the generalized Lisp conditional

 CumsumPDCO{e}       generates the cumulative sum of the terms of e

 CycleparAER{e1,e2, ...}
                     parallel evaluation with shorter sequences
                     re-evaluated

 DecimatePDCO{e1, e2}
                     "decimate" e1 by deleting e2-numbered terms
                     (e2 is assumed to be an increasing sequence).

 DecimationPDCO{e}   produce a decimation sequence from e1 by
                     deleting even-valued terms and replacing
                     odd-valued terms by their position.

 DecollatePDCO{e, i} decollate e according to parity of i

 DeltaPDCO{e1}       produces the difference of the values in e1

 ElevatePDCO{e1, m, n}
                     elevate e1 mod n to n values

 EveryPDCO{e1,e2}    models every e1 do e2

 ExtendSeqPDCO{e1,i} extends e1 to i results

 ExtractAER{e1,e2, ...}
                     extract results of even-numbered arguments
                     according to odd-numbered values

 FifoAER{e1,e2, ...} reversal of lifo evaluation

 FriendlyPDCO{m, k, e3}
                     friendly sequence starting at k shaft mod m

 GaltPDCO{e1,e2, ...}
                     produces the results of concatenating the
                     sequences for e1, e2, ...

 GconjPDCO{e1,e2,...}
                     models generalized conjunction: e1 & e2 & ...

 The programmer-defined control operation above shows an interesting
 technique for modeling conjunction via recursive generative
 procedures.

 HistoPDCO{e,i}      generates histogram for e limited to i terms;
                     default 100.

 IncreasingPDCO{e}   filters out non-increasing values in integer
                     sequence

 IndexPDCO{e1,e2}    produce e2-th terms from e1

 InterPDCO{e1,e2, ...}
                     produces results of e1, e2, ... alternately

 LcondPDCO{e1,e2, ...}
                     models the Lisp conditional

 LengthPDCO{e}       returns the length of e

 LifoAER{e1,e2, ...} models standard Icon "lifo" evaluation

 LimitPDCO{e1,e2}    models e1 \ e2

 ListPDCO{e,i}       produces a list of the first i results from e

 LowerTrimPDCO{e}    lower trim

 MapPDCO{e1,e2}      maps values of e1 in the order they first appear
                     to values of e2 (as needed)

 OddEven{e}          forces odd/even sequence

 PalinPDCO{e}        x produces results of concatenating the
                     sequences for e and then its reverse.

 ParallelPDCO{e1,e2, ...}
                     synonym for InterPDCO{e1, e2, ...}

 ParallelAER{e1,e2, ...}
                     parallel evaluation terminating on
                     shortest sequence

 PatternPalinPDCO{e, i}
                     produces pattern palindrome.  If i is given,
                     e is truncated to length i.

 PeriodPDCO{e, i}    generates the periodic part of e; i values are
                     used to find the period

 PermutePDCO{e1,e2}  permutes each n-subsequence of e1 by the
                     n positional values in lists from e2.  If a list does
                     not consist of all the integers in the range 1 to
                     n, "interesting" things happen (see the use
                     of map() for transpositions).

 PivotPDCO{e, m}     produces pivot points from e % m; m default 100

 PosDiffPDCO{e1,e2}  produces positions at which e1 and e2 differ

 PositionsPDCO{e, i} generates the positions at which i occurs in e.

 RandomPDCO{e1,e2, ...}
                     produces results of e1, e2, ... at random

 ReducePDCO{op, x, e}
                     "reduces" the sequence e by starting with the value x
                     and repetitively applying op to the current
                     value and values from e.

 RemoveDuplPDCO{e}   removes duplicate adjacent values.

 RepaltPDCO{e}       models |e

 RepeatPDCO{e1, e2}  repeats the sequence for e1 e2 times

 ReplPDCO{e1,e2}     replicates each value in e1 by the corresponding
                     integer value in e2.

 ResumePDCO{e1,e2,e3}
                     models every e1 \ e2 do e3

 ReversePDCO{e, i}   produces the results of e in reverse order. If i
                     is given, e is truncated to i values.

 RotatePDCO(e, i)    rotates the sequence for e left by i; negative
                     i rotates to the right

 SelfreplPDCO{e1,i}  produces e1 * i copies of e1

 SeqlistPDCO{e1, i}  produce list with first i values of e1; i
                     defaults to all values

 SimpleAER{e1,e2, ...}
                     simple evaluation with only success or
                     failure

 SkipPDCO{e1,e2}     generate e1 skipping each e2 terms

 SmodPDCO{e1,e2}     reduce terms in e1 (shaft) modulus e2

 SpanPDCO{e,m}       fill in between consecutive (integer) values in
                     e % m; m default 100

 SumlimitPDCO{e, i, j}
                     produces values of e until their sum exceeds
                     i.  Values less than j are discarded.

 TrinopPDCO{op,e2,e2,e3}
                     produces the result of applying op to e1, e2, and e3

 UndulantPDCO{e}     produces the undulant for e.

 UniquePDCO{e}       produces the unique results of e in the order
                     they first appear

 UnopPDCO{e1,e2}     produces the result of applying e1 to e2

 UpperTrimPDCO{e}    upper trim

 ValrptPDCO{e1,e2}   synonym for ReplPDCO

 WobblePDCO{e}       produces e(1), e(2), e(1), e(2), e(3), e(2), ...

 Comments:

 Because of the handling of the scope of local identifiers in
 co-expressions, expressions in programmer-defined control
 operations cannot communicate through local identifiers.  Some
 constructions, such as break and return, cannot be used in argu-
 ments to programmer-defined control operations.

Source code | Program Library Page | Icon Home Page