News for hackers. Stuff that matters.
Re:Lisp-Stick on a Python by jxy on Monday November 14, 2022 @11:25PM (#33605263)
Just in case people don't know about C. This is a short piece of code where an array is returned from a function.

    typedef struct {int v[4];} Vec;
    Vec get_vec(void){return Vec {3,2,1,0};}
Edit: alas, I've been writing too much C++. The following is correct C.

    typedef struct {int v[4];} Vec;
    Vec get_vec(void){Vec v={{3,2,1,0}}; return v;}
Re:Lisp-Stick on a Python by merlincorey on Tuesday November 15, 2022 @02:22AM (#33606260)
Yeah, there is nothing complicated about returning a static array in C.

C is a much simpler language than many people assume -- of course, it can get really hairy and complicated especially when you need to do dynamic memory management, but that's not what the GP was asking for in this case.

Re:Lisp-Stick on a Python by chronial on Tuesday November 15, 2022 @05:36AM (#33607549)
> that's not what the GP was asking for in this case.

You really think that when they mentioned the dynamically allocated `Vec` in Rust (which has fixed-sized arrays) and "manual memory management" in C, what they were actually talking about was a static array?

Re:Lisp-Stick on a Python by jnxx on Tuesday November 15, 2022 @02:06PM (#33613477)
But you need dynamic memory management for side-effect-free functional programming.
Re:Lisp-Stick on a Python by xigoi on Tuesday November 15, 2022 @05:59AM (#33607718)
Now do an array whose size is not known at compile time.
Re:Lisp-Stick on a Python by flohofwoe on Tuesday November 15, 2022 @07:38AM (#33608377)
In C99 or later you can also write it as:

    Vec get_vec(void) {
        return (Vec){ { 3, 2, 1, 0 } };
    }
...or I would probably prefer designated init for readability:

    Vec get_vec(void) {
        return (Vec){ .v = { 3, 2, 1, 0 } };
    }