News for hackers. Stuff that matters.
Re:Programming Algorithms in Lisp: Data Structures by pjmlp on Wednesday August 07, 2019 @10:36AM (#20635052)
Ok I might have to give in with the syntax sugar part, but safety?

Here is my example in C#. So now C# is unsafe?

    class Point
    {
        public int x, y;
    }


    static class CSharpIsUnsafe {
        static void ByPointer(Point p)
        {
            p = new Point();
            p.x = 12;
        }

        static void ByReference(ref Point p)
        {
            p = new Point();
            p.x = 12;
            p.y = 33;
        }
        
        public static void Main(string[] args)
        {
           p = new Point();
           p.x = 23;
           p.y = 28;
           Console.WriteLn($"The point is {p.x} {p.y}");
           

           ByPointer(p)
           Console.WriteLn($"The point is {p.x} {p.y}");

           p.x = 23;
           p.y = 28;
           Console.WriteLn($"The point is {p.x} {p.y}");

           ByReference(ref p);
           Console.WriteLn($"The point is {p.x} {p.y}");
        }
    }
Re:Programming Algorithms in Lisp: Data Structures by jstimpfle on Wednesday August 07, 2019 @03:48PM (#20638180)
I guess it might very well be safe. I don't know C# very well, but I'd assume that ref is sort of a proxy that

1) under the hood stores an (object) reference to the lowest structural ancestor that is GC'ed, as well as an offset from that object to the ref'ed property.

2) is itself GC'ed

Escape analysis might in some cases optimize out the GC'ing of the ref, but that of course doesn't work if the ref does escape.

Something like that, but in any case it's something very different than the Pascal/C++ examples we've talked about.

Re:Programming Algorithms in Lisp: Data Structures by pjmlp on Wednesday August 07, 2019 @05:11PM (#20639127)
The generated code is similar as how a C++ compiler would do it.

Easy to check with VS Assembly visualizer or WinDbg alongside SOS.dll.

D, Ada, CLU, Mesa, Mesa/Cedar, Algol, PL/I, PL/S, PL.8, Delphi, Dylan, .NET, Swift, Oberon, Oberon-2, Component Pascal, Active Oberon, QuickBasic, Turbo Basic are just a couple of examples of languages allowing for pass by value and pass by reference, some of them also quite safe.

And then there is also call by name introduced alongside Algol.