🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #40

Re: Rust (was: Optimization by programmers)

#40
From: Michael S
Date: Sun, 11 Oct 2026 19:43
78 lines
4002 bytes
On Sun, 11 Oct 2026 09:27:04 GMT
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

> Michael S <already5chosen@yahoo.com> writes:
> >On Tue, 06 Oct 2026 08:29:19 GMT
> >anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:  
> >> My goal was to implement search tree insertion as efficiently and
> >> compactly as in Pascal,   
> >
> >I suppose, you mean some extended Pascal dialect here, because I can
> >not imagine how you code an example below in Standard Pascal. 
> >Then again, I learned Pascal ~40 years ago and didn't use it in
> >practice since 1989 or 1990, so can easily miss something.  
> 
> Page 75 and 76 of my copy of "Programming in Modula-2" (Second
> Edition) contain this:
> 
> TreePtr = POINTER TO TreeNode;
> TreeNode =
>   Record
>     key: CARDINAL;
>     data: ...
>     left, right: TreePtr;
>   END;
> 
> PROCEDURE search(VAR p: TreePtr; x: CARDINAL): TreePtr;
> BEGIN
>   IF p # NIL THEN
>     IF p^.key < x THEN
>       RETURN search(p^.right,x)
>     ELSIF p^.key > x THEN
>       RETURN search(p^.left, x)
>     ELSE
>       RETURN p
>     END
>   ELSE (* not found, hence insert *)
>     NEW(p);
>     WITH p^ DO
>       key := x;
>       left := NIL;
>       right := NIL;
>     END;
>     RETURN p
>   END
> END search
> 
> You would invoke this with
> 
> search(root,needle)^.data := ...;
> 
> in order to actually change the field "data", performing the insert
> functionality.
> 
> One would not want to use this procedure for lookup, given that it
> inserts a node with an uninitialized data field when the key is not
> found.  Wirth gives a loop implementation of lookup before the
> PROCEDURE search.
> 
> Note that the "VAR" in front of the p makes p a reference parameter
> rather than a value parameter (like x), which is key to making this
> work for insertion.  This language feature is also present in Pascal;
> the Pascal syntax is different, but I don't think that prevents
> implementing this approach.
> 
> Using recursion is necessary here because Modula-2 and Pascal support
> references to variables or fields only for parameters.  But the
> recursive calls are tail-recursive (I don't think that Wirth's
> Modula-2 or Parcal compilers optimized tail recursion, though).
> 
> - anton


Thank you. I forgot about call by reference feature of Pascal.
But even if I was not forgetting about it, using recursive function
call to emulate & operator of C probably would not cross my mind.


Technical Details
Message-ID: <20261011224357.0000479d@yahoo.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <1177fdi$26ea4$1@dont-email.me> <119otm8$2c89q$2@dont-email.me> <86ik3jo1js.fsf@linuxsc.com> <2026Oct3.131214@mips.complang.tuwien.ac.at> <11a0662$gic$1@reader2.panix.com> <2026Oct6.102919@mips.complang.tuwien.ac.at> <20261010222854.0000591c@yahoo.com> <2026Oct11.112704@mips.complang.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.arch
Subject: Re: Rust (was: Optimization by programmers)
Date: Sun, 11 Oct 2026 22:43:57 +0300
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <20261011224357.0000479d@yahoo.com>
References: <1177fdi$26ea4$1@dont-email.me>
	<119otm8$2c89q$2@dont-email.me>
	<86ik3jo1js.fsf@linuxsc.com>
	<2026Oct3.131214@mips.complang.tuwien.ac.at>
	<11a0662$gic$1@reader2.panix.com>
	<2026Oct6.102919@mips.complang.tuwien.ac.at>
	<20261010222854.0000591c@yahoo.com>
	<2026Oct11.112704@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Oct 2026 19:44:07 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1971962"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19BSkY1ylbeOHX/UjL6cZFeBp/LxCAfPyE="; posting-host="418de5f1fdcec6be73a5b91e21b5ce1e"
Cancel-Lock: sha1:HJarMuy+tsHmllHP3cZNTh+0wdw= sha256:WI3tsWKJjnPbPbnXr7Q0nT7reyBZFzednLVaiZ2P9cc=
	sha1:aMOjplW9d75oGrz9MP/dTE5hJwQ= sha256:PkgleDTvmLalgAJXeE8uWrGIQerGeoQaQykA2+8nsGw=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)