Git Product home page Git Product logo

Comments (8)

dinfuehr avatar dinfuehr commented on May 5, 2024 1

I think removing nil became recently feasible in Dora. Thanks to @soc, we now have the Option class and the arrayDefault-function (although it's called arrayNew but feel free to change it). I don't think we need the lambda-version right now since we have the Vec class as well.

I guess what is left is to simply require initializers for fields and to make Array[T](length: Int) private to stdlib. The latter one could be "solved" for now by simply treating the array constructor as internal. Later when functions can be private to a module it is straight-forward to rectify this.

Apart from that I suppose we only need to remove nil from tests and test/benchmark programs - and then removing nil-support completely from the language.

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

Sounds good!

from dora.

soc avatar soc commented on May 5, 2024

Very exciting progress!

I updated the description above to the new syntax and the rough semantics of the existing code for Default; also added arrayZero as a more limited, but more lightweight alternative for types where no custom initialization code needs to be run (which I forgot when I first wrote the issue).

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

Not sure we need arrayZero for avoiding initialising twice. I think the optimizing compiler or runtime should be able to detect this and optimize it away. We need that anyways since classes like Vec[T] can't use arrayZero since they operate on all possible types.

from dora.

soc avatar soc commented on May 5, 2024

From my perspective it's not about initializing twice, it's avoiding initialization altogether:

Allocating zeroed memory for those types implementing Zero means that the type is properly initialized, but not every type can implement Zero.

Default is different in that every type could implement it.

For example, String could support Default with a default value of ""; arrayDefault[String](10) would mean that the defaultValue would be computed 10 times.

Assuming that String is a reference type, it wouldn't be able to support Zero though; the closest thing would be an Option[String]; in the case of arrayZero[Option[String]](10) no initialization code would need to be run at all, as zeroValue of Option would be None, which in turn is represented as a null pointer.

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

The array constructor Array[T](len) always initializes (zeros) the allocated memory. So we always initialize memory at least once. I think this is the step where we count differently.

With arrayFill or arrayDefault we then initialize the array with some value a second time. arrayZero would guarantee a single initialization, but I think this is something we might also be able to achieve with the compiler/runtime without providing a special function.

My argument is that many potential users can't use arrayZero anyways since e.g. T might not implement the Zero trait (e.g. Vec). That's why we should try to avoid the second initialization for arrayFill and arrayDefault if possible as well. As soon as we have that, there would be no use for arrayZero anymore.

from dora.

soc avatar soc commented on May 5, 2024

Is this done for good, @dinfuehr with your recent commits? :-)

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

I think it's mostly done, there might be some cleanup needed but I guess we can close this already.

from dora.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.