Article View: comp.arch
Article #31Re: Rust (was: Optimization by programmers)
From: Michael S
Date: Sat, 10 Oct 2026 19:28
Date: Sat, 10 Oct 2026 19:28
74 lines
3972 bytes
3972 bytes
On Tue, 06 Oct 2026 08:29:19 GMT
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
> >In article <2026Oct3.131214@mips.complang.tuwien.ac.at>,
> >Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> >>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> >>>That's good to know but what is a good resource to learn the Rust
> >>>language? I've looked at the Rust book several times and each
> >>>time come away rather frustrated.
> >>
> >>If you mean "The Rust Programming Language", I came away from it
> >>disillusioned.
> >>
> >>The reason was that I could not get a search-tree insertion
> >>technique to work that can be implemented in e.g., Pascal, C, and
> >>Forth, but not in Java (because in Java I cannot produce references
> >>to a field inside an object).
> >
> >I think what you mean to say is that you couldn't find a way to
> >implement that in the manner you were accustomed to thinking
> >about the problem, given your prior experience.
>
> 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.
I would think that it is possible to code your example in Standard
Ada83, but not in "checked" subset of it.
> C or Forth (and in contrast to Java), ideally
> in safe Rust. Here it is in C (untested):
>
> struct tree {
> int key; /* or some other key type */
> int val; /* or some other value type */
> struct tree *left;
> struct tree *right;
> };
>
> struct tree **search(struct tree **rootp, int key)
> {
> while ((root=*rootp)!=NULL && key != root->key) {
> if (key < root->key)
> rootp = &(root->left);
> else
> rootp = &(root->right);
> }
> return rootp;
> }
>
> void insert(struct tree **rootp, int key, int val)
> {
> struct tree **nodep = **search(rootp, key);
> struct tree *node = *nodep;
> if (node == NULL) {
> node = malloc(sizeof(tree));
> node->key = key;
> node->left = NULL;
> node->right = NULL;
> *nodep = node;
> }
> node->val = val;
> }
>
> Passing a reference to a mutable field is what is done in these
> languages, and I don't know an efficient and similarly compact
> technique that does not pass a reference to a mutable field.
>
Technical Details
Message-ID:
<20261010222854.0000591c@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-mailReferences:
<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>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: Sat, 10 Oct 2026 22:28:54 +0300 Organization: A noiseless patient Spider Lines: 74 Message-ID: <20261010222854.0000591c@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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sat, 10 Oct 2026 19:29:02 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1971962"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Na3l9NcEtYD/0jd5Grw3Oi5XxQVrHhlw="; posting-host="49690832da79aa746ce4261de989d20e" Cancel-Lock: sha1:OTFlKKIiQHgLUIupU9D0mt4rMzE= sha256:brmXHO0VHfGUrjYmXcIJmwz7Df3AQR2Ow0O2uX6BKu8= sha1:9JrKkvWdvlZpKyVt0kntCvkcmCk= sha256:m4purVnhdZkDFpRc0lvWwjV7bbgtBT/fJl4bPX8NguE= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)