• 0 Posts
  • 23 Comments
Joined 1 year ago
cake
Cake day: July 27th, 2023

help-circle
  • Well they said .NET Framework, and I also wouldn’t be surprised if they more or less wrapped that up - .NET Framework specifically means the old implementation of the CLR, and it’s been pretty much superseded by an implementation just called .NET, formerly known as .NET Core (definitely not confusing at all, thanks Microsoft). .NET Framework was only written for Windows, hence the need for Mono/Xamarin on other platforms. In contrast, .NET is cross-platform by default.



  • I was very intrigued by a follow-up to the recent numberphile video about divergent series. It was a return to the idea that the sum of the integers greater than zero can be assigned the value -1/12. There were some places this could be used, but as far as I know it was viewed as shaky math by a lot of experts.

    As far as I recall the story goes something like this: now, using a new technique Terrence Tao found, a team was seemingly able to “fix” previous infinities in quantum field theory - there’s a certain way to make at least some divergent series work out to being a real number, and the presenter proposed that this can be explained as the universe “protecting us” from the infinities inherent in the math.

    It made me think about other places infinities show up in modern physics (namely, singularities in general relativity) and whether a technique something like this could “solve” them without a whole new framework like string theory is.


  • The issue is that, in the function passed to reduce, you’re adding each object directly to the accumulator rather than to its intended parent. These are the problem lines:

    if (index == array.length - 1) {
    	accumulator[val] = value;
    } else if (!accumulator.hasOwnProperty(val)) {
    	accumulator[val] = {}; // update the accumulator object
    }
    

    There’s no pretty way (that I can think of at least) to do what you want using methods like reduce in vanilla JS, so I’d suggest using a for loop instead - especially if you’re new to programming. Something along these lines (not written to be actual code, just to give you an idea):

    let curr = settings;
    const split = url.split("/");
    for (let i = 0; i < split.length: i++) {
        const val = split[i];
        if (i != split.length-1) {
            //add a check to see if curr[val] exists
            let next = {};
            curr[val] = next;
            curr = next;
        }
        //add else branch
    }
    

    It’s missing some things, but the important part is there - every time we move one level deeper in the URL, we update curr so that we keep our place instead of always adding to the top level.










  • Currying is converting a function with n parameters to n functions that each have one parameter. This is done automatically in most primarily functional languages. Then, partial application is when you supply less than n arguments to a curried function. In short, currying happens at the function definition and partial application happens at the function call.

    Currently the type of test_increment is (int, int) -> unit -> unit. What we want is int -> int -> unit -> unit. The more idiomatic way would have this function definition:

    let test_increment new_value original_value () =
    

    Which would require this change in the callers:

    test_case "blah" `Quick (test_increment 1 0);
    

    See, in most primarily functional languages you don’t put parentheses around function parameters/arguments, nor commas between them - in this case, only around and between members of tuples.


  • sleep_deprived@lemmy.worldtoProgramming@programming.dev***
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    11 months ago

    I’m not an OCaml person but I do know other functional languages. I looked into Alcotest and it looks like the function after “`Quick” has to be unit -> unit. Because OCaml has currying, and I think test_increment already returns unit, all you should have to do is add an extra parameter of type unit. I believe that would be done like this:

    let test_increment (new_value, original_value) () =
    

    Now the expression test_increment (1, 0) returns a function that must be passed a unit to run its body. That means you can change the lambdas to e.g. this:

    test_case "blah" `Quick (test_increment (1, 0))
    

    I don’t know OCaml precedence rules so the enclosing parentheses here may not be necessary.

    I’d also note that taking new_value and original_value as a tuple would probably be considered not idiomatic unless it makes sense for the structure of the rest of your code, especially because it limits currying like we did with the unit being able to be passed later. Partial application/currying is a big part of the flexibility of functional languages.

    Edit: if you’re getting into functional programming you may also consider calling increment_by_one “succ” or “successor” which is the typical terminology in functional land.



  • The China thing is stupid but the review after the failure of the pad and the FTS isn’t really what this is about. I’m sure SpaceX would be happy if they could talk congress into relaxing that type of thing too, the reality is that by all accounts both parties are happy with the way the safety review has gone, and with this type of thing the FAA works very closely with SpaceX (though I suspect Elon will be upset if the Fish and Wildlife Service consult takes long given his impressive record of stupidity). In fact, given the wording the SpaceX rep used, I’d bet his mentioning Starship and the Moon is because Artemis is very important to a lot of people in Congress for several reasons - if this were about Elon’s ego and disregard for safety, I expect they’d instead mention Mars and China’s growing economic, not scientific, rivalry with the US. But that’s besides the point.

    The real issue at hand for the FAA, and the reason for this hearing, lies in the fact that starting with the Falcon 9, commercial space launches are becoming more and more routine, and they’re only going to keep picking up the pace as Starship, Vulcan, Proton and others enter service. And while at the moment the FAA is managing to keep most things running, they’re critically understaffed for the workload to begin with before you even take into account the pace at which the space scene is changing. And most of what was said in the article lines up with what the FAA says, which is basically “sorry guys, we’re doing the best we can, but we don’t have enough people”. I think this quote from SpaceX does a much better job than the crap they have to tell senators:

    “Our concern is even today Falcon and Dragon are sometimes competing for FAA resources with Starship, and the FAA can’t handle those three activities together. So let alone what’s coming next year, or maybe even later this year, we just don’t think the FAA is staffed ready to support that.”

    They also recommend that the FAA be allowed to use NASA’s and the Space Force’s resources, which sounds like a great idea worth exploring to me. It should also be mentioned that these complaints are almost exclusively targeted at unmanned space flight, and that manned space flight is a different story entirely and not really relevant to this hearing.

    So really a better non-sensational title would be “FAA understaffed for space boom even with doubling of staff, says space companies” or something along those lines.



  • Box is (basically) just the way to have memory on the heap. Here’s a direct comparison of how to do heap memory in C/++ and in rust:

    int* intOnHeap = (int*)malloc(sizeof(int));
    *intOnHeap = 0;
    MyClass* classOnHeap = new MyClass();
    
    let intOnHeap: Box = Box::new(0);
    let structOnHeap: Box = Box::new(MyStruct::default());
    

    There can be a bit more to it with custom allocators etc. but that’s the only way most people will use boxes. So Box basically just means “a T is allocated somewhere and we need to free that memory when this value is dropped”.