From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4e39e3650a0d633 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Icon Co-Expressions in Ada Date: 1998/12/17 Message-ID: #1/1 X-Deja-AN: 423314153 References: Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1998-12-17T00:00:00+00:00 List-Id: Ehud Lamm writes: > A bit about goal directed evaluation in general. Co-Expressions are really > a special mechanism, and for some reason I slumped them together in my > post. > > I'll give an example of how Goal directed eval works: > Icon has a built in function find(s1,s2) which returns (potentially) all > the indexes in s2, where s1 start (find("e","ehud") should be 1). > suppose I say > if find("e","element")>1 then... > > What will happen is that find will be executed, it will return 1 which > doesn't satisfy the condition, it will then be resumed, and return the > value 3. Than the "then-clause" will be executed. I can see this is a general mechanism, difficult to implement in Ada. The "Ada way" to get this particular result is to pass a "terminate condition" function to an iterator : find ("e", "element", index_greater_1'access) It would be nice to have annonymous functions for this (like lisp lambda functions), but local functions aren't too bad (in GNAT anyway :). > For this to work from arbitrary procedures, the language provides the > suspend statement, which is like return but after which the procedure may > be resumed.(you can have a procedure say suspend 4; suspend 5; for > example). > > I was thinking about implimenting this statement. Note that you ahve to > remember exactly where the computation stopped. I think I understand "suspend"; it's what Knuth calls a "coroutine". I'm not clear what "suspend " means? You definitely need tasks to do this in Ada, since the task stack is where the procedure state is saved. At each "suspend", you could have an accept statement. The caller would still have to write a loop to get the goal-directed behavior. > Co-expression are another mechanism. The allow you a limited sort of > parallel execution, of two or more procedure that can be supended. This > allows you to take one value from one routine, another from the second > routine etc. Ok; Ada tasks are executed in parallel. You'll need a good naming convention! > > Hopes this clears things up, a bit. Getting there ... -- Stephe > > Ehud Lamm mslamm@pluto.mscc.huji.ac.il > P.S > If any one is interested let them browse to http://www.cs.arizona.edu/icon > > If anyone wants to read more, I have a litle memo called "Integrating User > Defined Procedures With Built-In Language Features: The Case of J, Icon > and C++". It deals with Icon generators (= routines that use suspend) and > other clever programming languages features.