comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Icon Co-Expressions in Ada
Date: 1998/12/17
Date: 1998-12-17T00:00:00+00:00	[thread overview]
Message-ID: <u1zlyznoc.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: Pine.A41.3.96-heb-2.07.981217080010.70860A-100000@pluto.mscc.huji.ac.il

Ehud Lamm <mslamm@mscc.huji.ac.il> 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 <integer>" 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. 




  reply	other threads:[~1998-12-17  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-16  0:00 Icon Co-Expressions in Ada Ehud Lamm
1998-12-16  0:00 ` dennison
1998-12-16  0:00 ` Stephen Leake
1998-12-16  0:00   ` Al Christians
1998-12-17  0:00   ` Ehud Lamm
1998-12-17  0:00     ` Stephen Leake [this message]
1998-12-17  0:00       ` Ehud Lamm
1998-12-17  0:00     ` Mats Weber
1998-12-17  0:00       ` Chris Morgan
1998-12-17  0:00       ` Ehud Lamm
1998-12-17  0:00   ` Mats Weber
1998-12-17  0:00     ` Ehud Lamm
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox