Article View: comp.lang.modula2
Article #4068Re: Recursively defined data types.
From: Kasper Osterbye
Date: Wed, 17 Feb 1988 18:06
Date: Wed, 17 Feb 1988 18:06
37 lines
1457 bytes
1457 bytes
Dear Mark,
Recursive datatypes are not pointers in disguise. If I am not wrong, they
will only represent trees - and here is why.
I will assume your definition of a list.
List = RECORD CASE Null:BOOLEAN OF
TRUE : |
FALSE: Key: ...;
Data: ....;
Next: List;
END
now assume that we have variables l1,l2 of type "List", and that l1 is (a,b,c).
the magic of the concept recursive datatypes is that it is not pointers so
when I do a
l2 := l1;
l2 gets assigned a COPY of l1, and if you change anything to l1, it will not
affect l2.
further more, an assignment of the form:
l1.next.next := l1
will not give you a cycle, but rather the list (a,b,a,b,c).
That is at least how I learned recursive types. As to your changed syntax
for pointers so they pretend they are recursive, I dislike it, it looks
different, but you will still have to learn the concept of pointers to
use it.
The why not use pointers afterall?
/Kasper
Technical Details
Message-ID:
<2420@csli.STANFORD.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mailrus!nrl-cmf!ames!amdcad!sun!decwrl!labrea!csli!kasperShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mailrus!nrl-cmf!ames!amdcad!sun!decwrl!labrea!csli!kasper From: kasper@csli.STANFORD.EDU (Kasper Osterbye) Newsgroups: comp.lang.modula2 Subject: Re: Recursively defined data types. Message-ID: <2420@csli.STANFORD.EDU> Date: 17 Feb 88 18:06:51 GMT Reply-To: kasper@csli.UUCP (Kasper Osterbye) Organization: Center for the Study of Language and Information, Stanford U. Lines: 37