• How does one make doubly linked lists in Rust

    From Johann 'Myrkraverk' Oskarsson@johann@myrkraverk.invalid to comp.lang.misc on Mon Sep 21 21:55:51 2026
    From Newsgroup: comp.lang.misc

    Dear comp.lang.misc,

    Posting here because comp.lang.rust is still being debated in news. groups.proposals.

    In /Rust by Example/, there is a chapter on linked lists,


    https://doc.rust-lang.org/rust-by-example/custom_types/enum/testcase_linked_list.html

    so I was wondering how one would create doubly linked lists, because
    it's not immediately obvious from the examples what the syntax should
    be like?

    Of course, if this is a solved problem, a chapter in a book, or post on
    Stack Overflow should be sufficient, but I thought to ask here first.


    Best wishes, and happy Rust!
    --
    Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
    I'm not from the Internet, I just work there. | via XS News https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.misc on Mon Sep 21 14:09:04 2026
    From Newsgroup: comp.lang.misc

    Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
    Of course, if this is a solved problem, a chapter in a book, or post on
    Stack Overflow should be sufficient, but I thought to ask here first.

    Since Rust already has std::collections::LinkedList, doubly-linked
    lists with owned nodes, there's little need to implement something
    like this, unless as an exercise.

    If one wants to use lists, one should also check if std::collections
    ::VecDeque can be used. It has O(1) push/pop at the front and back
    and is cache-friendly.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Johann 'Myrkraverk' Oskarsson@johann@myrkraverk.invalid to comp.lang.misc on Wed Sep 23 01:09:44 2026
    From Newsgroup: comp.lang.misc

    On 9/21/2026 10:09 PM, Stefan Ram wrote:
    Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
    Of course, if this is a solved problem, a chapter in a book, or post on
    Stack Overflow should be sufficient, but I thought to ask here first.

    Since Rust already has std::collections::LinkedList, doubly-linked
    lists with owned nodes, there's little need to implement something
    like this, unless as an exercise.

    If one wants to use lists, one should also check if std::collections
    ::VecDeque can be used. It has O(1) push/pop at the front and back
    and is cache-friendly.

    Dear Stefan,

    Thank you. As I'm just taking my first steps in Rust, I'm too focused
    on exercises, and tend to forget the wider world of the standard lib-
    rary.

    On a different subject, at

    https://doc.rust-lang.org/rust-by-example/variable_bindings/scope.html

    the book talks about shadowing variables, with a completely new type.

    This is of course done without a new scope. I thought that anti-pattern
    had been deemed confusing by the developers of C, Fortran 77, and other programming languages of yore [1].

    Even Standard M.L. of Edinburgh requires a new scope for shadowed varia-
    bles.

    So, erm, what were the Rustacians smoking when they made this a feature?


    Best wishes, and happy Rust!

    [1] So we have York, and New York, but where is yore?
    --
    Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
    I'm not from the Internet, I just work there. | via XS News https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.misc on Tue Sep 22 17:50:56 2026
    From Newsgroup: comp.lang.misc

    Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
    the book talks about shadowing variables, with a completely new type.

    The Rustafarians think that

    let input = input.trim();

    is clearer, because the name "input" always represents the same
    concept, and it becomes impossible to inadvertently use the un-
    trimmed input later. (One also might think of every "let" in a
    block opening a kind of "new scope".)


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.misc on Tue Sep 22 21:03:43 2026
    From Newsgroup: comp.lang.misc

    On 22 Sep 2026 17:50:56 GMT, Stefan Ram wrote:

    The Rustafarians think that

    let input = input.trim();

    is clearer, because the name "input" always represents the same
    concept, and it becomes impossible to inadvertently use the un-
    trimmed input later. (One also might think of every "let" in a block
    opening a kind of "new scope".)

    Why not follow Lisp, and denote this with rCLlet*rCY, as a hint to the
    reader ...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.misc on Thu Nov 12 18:25:31 2026
    From Newsgroup: comp.lang.misc

    On 21/09/2026 15:09, Stefan Ram wrote:
    Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
    Of course, if this is a solved problem, a chapter in a book, or post on
    Stack Overflow should be sufficient, but I thought to ask here first.

    Since [language] already has [special feature implementation name], [feature],
    there's little need to implement something
    like this, unless as an exercise.


    Surely there will be a point in the decades long history of discussion
    of language constructs where somebody remembers that every time somebody
    said that it was not true.

    If there was a movie about implementation this plot line would start "Of
    course it could go wrong in theory but it's a million to one against".
    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.misc on Thu Nov 12 18:32:34 2026
    From Newsgroup: comp.lang.misc

    On 22/09/2026 18:50, Stefan Ram wrote:
    Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
    the book talks about shadowing variables, with a completely new type.

    The Rustafarians think that

    let input = input.trim();

    is clearer, because the name "input" always represents the same
    concept, and it becomes impossible to inadvertently use the un-
    trimmed input later. (One also might think of every "let" in a
    block opening a kind of "new scope".)

    In fact it's the semi-colon doing that isn't it? Following the age-old
    form of so many languages in which (pseudo-grammar):


    implicit-scope : statement ';' implicit-scope
    | statement ';'


    'let' just takes advantage of the new implicit-scope to cons a
    dictionary overlay (or in this case an individual identifier definition)
    onto a definitions dictionary stack at compile time (if you view a
    compiler as an interpreter that compiles instead of executing).
    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.
    --- Synchronet 3.22a-Linux NewsLink 1.2