Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Python and Java

2 views
Skip to first unread message

Farshad Nayeri

unread,
Jul 1, 1996, 3:00:00 AM7/1/96
to

> How did they come [Java and Python are] so similar?

Designs of Python and Jave were influenced by features in Modula-3
(and its predecessor, Modula-2+).

As far as I know, Modula-3 was the first language that made a
big point of combining exceptions, threads and garbage collection,
among other things. Modula-3 language and an implementation
incorporating these features has been available since 1989!

--
Farshad Nayeri
Critical Mass, Inc.
http://www.cmass.com/

Daniel Larsson

unread,
Jul 1, 1996, 3:00:00 AM7/1/96
to

And Simula was the first language that made a big point of
combining coroutines, inheritance and garbage collection, and
has been around since the sixties!

Coroutines are still rare in newer languages. I'm sure there
are more, but I know only of Modula-2 and BETA.
--
Daniel Larsson, ABB Industrial Systems AB

Scott Schwartz

unread,
Jul 1, 1996, 3:00:00 AM7/1/96
to Daniel Larsson

Daniel Larsson <dlar...@sw.seisy.abb.se> writes:
| Coroutines are still rare in newer languages. I'm sure there
| are more, but I know only of Modula-2 and BETA.

Alef, used for systems programming in Plan 9.


Farshad Nayeri

unread,
Jul 2, 1996, 3:00:00 AM7/2/96
to

> > > How did they come [Java and Python are] so similar?
> >
> > Designs of Python and Jave were influenced by features in Modula-3
> >
> > Modula-3 was the first language that made a
> > big point of combining exceptions, threads and garbage collection,
> >
> And Simula was the first language that made a big point of
> combining coroutines, inheritance and garbage collection, and

Right. Modula-3 designers clearly give credit to the Simula
design--see the Modula-3 specification--so their relationship
is well-known. I was trying to highlight the relationship of
Java and Python with Modula-3 which is not as well-known.

James C. Phillips

unread,
Jul 2, 1996, 3:00:00 AM7/2/96
to

Daniel Larsson wrote:
> Coroutines are still rare in newer languages. I'm sure there
> are more, but I know only of Modula-2 and BETA.

For us non-computer-science-types, what is a coroutine?
I've never heard this term before.

-Jim

Aaron Watters

unread,
Jul 3, 1996, 3:00:00 AM7/3/96
to

I've never really used them, but as I recall they are like
subroutines, except that more than one coroutine can be
active at once and one coroutine can explicitly give control
to another or something... I personally don't understand why
you need programming language features to emulate this kind of
behaviour, but I'm probably ill informed and wrong.

Maybe some expert can tell me: is there anything you can do
with coroutines that can't be emulated directly with instances
of classes in Python or M3? Please educate... -- Aaron Watters
===
What the heck does that do?
Dunno. try commenting it out and see if it matters...
--overheard years ago in a Symbolics lab.

Daniel Larsson

unread,
Jul 3, 1996, 3:00:00 AM7/3/96
to

Aaron Watters wrote:
>
> James C. Phillips wrote:
> >
> > Daniel Larsson wrote:
> > > Coroutines are still rare in newer languages. I'm sure there
> > > are more, but I know only of Modula-2 and BETA.
> >
> > For us non-computer-science-types, what is a coroutine?
> > I've never heard this term before.
> >
> > -Jim
>
> I've never really used them, but as I recall they are like
> subroutines, except that more than one coroutine can be
> active at once and one coroutine can explicitly give control
> to another or something... I personally don't understand why
> you need programming language features to emulate this kind of
> behaviour, but I'm probably ill informed and wrong.
>
> Maybe some expert can tell me: is there anything you can do
> with coroutines that can't be emulated directly with instances
> of classes in Python or M3? Please educate... -- Aaron Watters

I would hardly describe myself as an expert in coroutines, but
anyway...

Suppose you have a binary tree class:

class Node:
def __init__(self, elem, left=None, right=None):
self.elem = elem
self.left, self.right = left, right


class BinTree:
def __init__(self):
self.root = None

def scan(self, node):
if node:
self.scan(node.left)
suspend node.elem # Suspend coroutine and return value
self.scan(node.right)

coroutine traverse(self):
self.scan(self.root)
return None # Terminate coroutine

A coroutine has its own stack. When a coroutine is called, the
caller's stack is saved, and the execution is moved to the callee's
stack. When a coroutine suspends, stacks are reversed again.

In the above case, each call to traverse will do one inorder step
in the tree and return the value at that node. Here's how to use
it to print the contents of a binary trees:

tree = BinTree()
... # init tree
while 1:
elem = tree.traverse()
if elem == None: break
print elem

This could certainly be implemented in Python without coroutines,
and I don't even know if this is even a good example of the
benefits of coroutines. Anyway, some problems where you would like
to use threads, might be easier to solve with coroutines, since
you don't have any synchronization problems (you have explicit
control of when switching between threads).

Hope I didn't confuse too many people out there...

Andreas Buschmann KS/EF4A 60/1/29 #40409

unread,
Jul 9, 1996, 3:00:00 AM7/9/96
to

Farshad Nayeri (far...@cmass.com) wrote:
: > How did they come [Java and Python are] so similar?

: Designs of Python and Jave were influenced by features in Modula-3

: (and its predecessor, Modula-2+).

: As far as I know, Modula-3 was the first language that made a


: big point of combining exceptions, threads and garbage collection,

: among other things. Modula-3 language and an implementation

: incorporating these features has been available since 1989!

No.

Algol68 had exceptions, threads (they were called differently) and
garbage collection, two decades earlier. Compilation unit were
missing, and objects. Simula67 had objects at the same time, but
coroutines instead of threads.


Tschuess
Andreas


--

/|) Andreas Buschmann
/-|) SEL Stuttgart KS/EIC5

work: busc...@lts.sel.alcatel.de
home: busc...@kalahari.s.bawue.de


0 new messages