On Wed, 22 Nov 2000 09:45:08 -0700, Dave Gudeman wrote:
<snip>
>Second, consider
>
> p1 := create (write(tab(find("abc"))))
> s ? every @p1
>
>the intention of this is probably the same as
>
> s ? every write(tab(find("abc")))
>
>but it doesn't work since the @ operator only produces one result.
<snip>
The Icon book says use |@p1 to generate all results; this works if you
are not backtracking PAST the @:
every |@p1
p1:=^p1
but NOT
every tab(find(a))& |@p1
(see below)
for your example with 2 coexpressions, I could use
static digits
or
digits:=[&null]
p1 := create (digits[1] := tab(any(&digits)))
so the shared data is on the heap (or global area).
To fix it so we can use p1 and p2 anywhere, I did
# ---- USE CPP -C to preprocess!!! ----
# (GOD help you if you have // or /* anywhere)
#define redo(a) (|@a | (a := ^a, &fail))
#define recreate(a,b) (a := create b,redo(a))
#define restart(a) (a := ^a,redo(a))
static digits
p1 := create (digits := tab(any(&digits)))
p2 := create (=digits)
s ? (restart(p1) & tab(any(~&digits)) & restart(p2)
) # note parens around &'s (OW)
OR use L:= [p1,p2] and a procedure restart, s? (restart L[1]...)
(call by reference would help here of course - maybe we need procedure
restart(&a) a la C++?)
OR use a class. (probably better for this example - what do you think?)
Do you have an example where auto-refreshing would be the best
solution?
I think an operator that does a 'restart' would be nice -
refreshing the co-expression first, generating, and refreshing again if it
fails (then fail itself)
maybe @@ for redo and @@@ for restart?
(has anyone out there done a coexpr valued coexpr that this would break?)
Is this close enough to what you did?
(other than scoping - is that still a problem?)
or maybe we should make $define take args
(NQRTVY ;)
Is a c-expression just a co-expression that uses dynamic scoping (a la
Pascal) instead of a private copy of the environment, or is there more to
it? I have not read Ken Walker's paper in Computer Language
(1989) First Class Patterns for Icon.
-- Charles, [EMAIL PROTECTED] on 11/24/2000
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/mailman/listinfo/unicon-group