home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
PDAE.ICN
< prev
next >
Wrap
Text File
|
1991-07-13
|
4KB
|
158 lines
#
# Name: pdae.icn
#
# Title: Programmer-defined argument evaluation
#
# Author: Ralph E. Griswold
#
# Date: January 1, 1990
#
############################################################################
#
# These procedures use co-expressions to model the built-in argu-
# ment evaluation regime of Icon and also provide new ones.
#
# Allpar{e1,e2, ...} parallel evaluation with last result
# used for short sequences
#
# Extract{e1,e2, ...} extract results of even-numbered argu-
# ments according to odd-numbered values
#
# Lifo{e1,e2, ...} models standard Icon ``lifo'' evalua-
# tion
#
# Parallel{e1,e2, ...} parallel evaluation terminating on
# shortest sequence
#
# Reverse{e1,e2, ...} left-to-right reversal of lifo evalua-
# tion
#
# Rotate{e1,e2, ...} parallel evaluation with shorter
# sequences re-evaluated
#
# Simple{e1,e2, ...} simple evaluation with only success or
# failure
#
# In all cases, the first argument is "applied".
#
# Comments:
#
# Because of the handling of the scope of local identif-
# iers in co-expressions, expressions in programmer-defined argu-
# ment evaluation regimes cannot communicate through local identif-
# iers. Some constructions, such as break and return, cannot be
# used in arguments to programmer-defined argument evaluation
# regimes.
#
############################################################################
#
# Requires: co-expressions
#
############################################################################
procedure Allpar(a)
local i, x, done
x := list(*a)
done := list(*a,1)
every i := 1 to *a do x[i] := @a[i] | fail
repeat {
suspend x[1]!x[2:0]
every i := 1 to *a do
if done[i] = 1 then ((x[i] := @a[i]) | (done[i] := 0))
if not(!done = 1) then fail
}
end
procedure Extract(a)
local i, j, n, x
x := list(*a/2)
repeat {
i := 1
while i < *a do {
n := @a[i] | fail
every 1 to n do
x[(i + 1)/2] := @a[i + 1] | fail
a[i + 1] := ^a[i + 1]
i +:= 2
}
suspend x[1]!x[2:0]
}
end
procedure Lifo(a)
local i, x, ptr
x := list(*a)
ptr := 1
repeat {
repeat
if x[ptr] := @a[ptr]
then {
ptr +:= 1
(a[ptr] := ^a[ptr]) |
break
}
else if (ptr -:= 1) = 0
then fail
suspend x[1]!x[2:0]
ptr := *a
}
end
procedure Parallel(a)
local i, x
x := list(*a)
repeat {
every i := 1 to *a do
x[i] := @a[i] | fail
suspend x[1]!x[2:0]
}
end
procedure Reverse(a)
local i, x, ptr
x := list(*a)
ptr := *a
repeat {
repeat
if x[ptr] := @a[ptr]
then {
ptr -:= 1
(a[ptr] := ^a[ptr]) |
break
}
else if (ptr +:= 1) > *a
then fail
suspend x[1]!x[2:0]
ptr := 1
}
end
procedure Rotate(a)
local i, x, done
x := list(*a)
done := list(*a,1)
every i := 1 to *a do x[i] := @a[i] | fail
repeat {
suspend x[1]!x[2:0]
every i := 1 to *a do
if not(x[i] := @a[i]) then {
done[i] := 0
if !done = 1 then {
a[i] := ^a[i]
x[i] := @a[i] | fail
}
else fail
}
}
end
procedure Simple(a)
local i, x
x := list(*a)
every i := 1 to *a do
x[i] := @a[i] | fail
return x[1]!x[2:0]
end