Functional programming with monads is the right way to implement this.
How to programmatically find out if computer is on
101–110 of 197 posts
Re: How to programmatically find out if computer is on
#102Since the not-on result is 'undefined', a devilish implementer could return 1 for the off case, just to screw with people. (How could this work in theory? Maybe the computer has a separate watchdog controller board which allows the computer to be turned on and off remotely, and that controller acts as a proxy for the API request.)
Re: How to programmatically find out if computer is on
#103Re: How to programmatically find out if computer is on
#104Re: How to programmatically find out if computer is on
#105While it is clearly a joke, it has a legitimate use as a syscall that does nothing so can be used to test the syscall process itself [1]. (Its cousin `is_computer_on_fire` is not a syscall.) [1] https://github.com/haiku/haiku/commit/ccaac177f64038c160de6f...
Sure. Of course, one important trick here is that no matter how fast your system call is, not making a system call is just faster. io_uring is an example, as are futexes. So it's worth spending more effort on figuring out tricks to avoid doing the system call than exploiting tricks to shave a cycle or two off the time taken to execute one.
Re: How to programmatically find out if computer is on
#106While this is a joke, there are some contexts in which it does make sense to ask whether the computer is on. For instance, most laptops have an embedded controller which runs all the time, even when the laptop is powered off, and manages things like battery charging and the power state. Within that embedded controller, an is_computer_on() function could legitimately return "false".
Re: How to programmatically find out if computer is on
#107Re: How to programmatically find out if computer is on
#108I like how it also has support for the ENIAC platform. I kicked my family out of the house so I had room to install the ENIAC. Happy to hear there's an OS I can run on it to get real work done, like posting unfunny jokes for strangers on Hacker News.
It upsets me that this function's interface allows it to describe silly things like "an ENIAC running on a 68000" or "an Apple II running on SPARC". Wouldn't be an issue if C++ supported GADTs.
Re: How to programmatically find out if computer is on
#109Re: How to programmatically find out if computer is on
#110Returns TRUE.