Hacker Newsnew | past | comments | ask | show | jobs | submit | alain94040's commentslogin

That example is too simple for me to grasp it. How would you code a function that iterates over an array to compute its sum. No cheating with a built-in sum function. If you had to code each addition, how would that work? Curious to learn (I probably could google this or ask Claude to write me the code).

Carmack gives updating in a loop as the one exception:

> You should strive to never reassign or update a variable outside of true iterative calculations in loops.

If you want a completely immutable setup for this, you'd likely have to use a recursive function. This pattern is well supported and optimized in immutable languages like the ML family, but is not super practical in a standard imperative language. Something like

  def sum(l):
    if not l: return 0
    return l[0] + sum(l[1:])
Of course this is also mostly insensitive to ordering guarantees (the compiler would be fine with the last line being `return l[-1] + sum(l[:-1])`), but immutability can remain useful in cases like this to ensure no concurrent mutation of a given object, for instance.

You don't have to use recursion, that is, you don't need language support for it. Having first class (named) functions is enough.

For example you can modify sum such that it doesn't depend on itself, but it depends on a function, which it will receive as argument (and it will be itself).

Something like:

  def sum_(f, l):
    if not l: return 0
    return l[0] + f(f, l[1:])

  def runreq(f, *args):
    return f(f, *args)

  print(runreq(sum_, [1,2,3]))

> You don't have to use recursion

You're using recursion. `runreq()` calls `sum_()` which calls `sum()` in `return l[0] + f(f, l[1:])`, where `f` is `sum()`


> You're using recursion.

No, see GP.

> `runreq()` calls `sum_()` which calls `sum()` in `return l[0] + f(f, l[1:])`, where `f` is `sum()`

Also no, see GP.


I am too stupid to understand this. This:

    def sum_(f, l):
      if not l: return 0
      return l[0] + f(f, l[1:])

    def runreq(f, *args):
      return f(f, *args)

    print(995,runreq(sum_, range(1,995)))
    print(1000,runreq(sum_, range(1,1000)))
when run with python3.11 gives me this output:

    995 494515
    Traceback (most recent call last):
      File "/tmp/sum.py", line 9, in <module>
        print(1000,runreq(sum_, range(1,1000)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/tmp/sum.py", line 6, in runreq
        return f(f, *args)
               ^^^^^^^^^^^
      File "/tmp/sum.py", line 3, in sum_
        return l[0] + f(f, l[1:])
                      ^^^^^^^^^^^
      File "/tmp/sum.py", line 3, in sum_
        return l[0] + f(f, l[1:])
                      ^^^^^^^^^^^
      File "/tmp/sum.py", line 3, in sum_
        return l[0] + f(f, l[1:])
                      ^^^^^^^^^^^
      [Previous line repeated 995 more times]
    RecursionError: maximum recursion depth exceeded in comparison
A RecursionError seems to indicate there must have been recursion, no?

While your example of `sum` is a nice, pure function, it'll unfortunately blow up in python on even moderately sized inputs (we're talking thousands of elements, not millions) due to lack of tail calls in Python (currently) and the restrictions on recursion depth. The CPython interpreter as of 3.14 [0] is now capable of using tail calls in the interpreter itself, but it's not yet in Python, proper.

[0]: https://docs.python.org/3/whatsnew/3.14.html#a-new-type-of-i...


Yeah, to actually use tail-recursive patterns (except for known-to-be-sharply-constrained problems) in Python (or, at least, CPython), you need to use a library like `tco`, because of the implementation limits. Of course the many common recursive patterns can be cast as map, filter, or reduce operations, and all three of those are available as functions in Python's core (the first two) or stdlib (reduce).

Updating one or more variables in a loop naturally maps to reduce with the updated variable(s) being (in the case of more than one being fields of) the accumulator object.


> Does anyone really think we are close to AGI?

My definition of AGI is when AI doesn't need humans anymore to create new models (to be specific, models that continue the GPT3 -> GPT4 -> GPT5 trend).

By my definition, once that happens, I don't really see a role for Microsoft to play. So not sure what value their legal deal has.

I don't think we're there at all anyway.


> I don't really see a role for Microsoft to play.

They have money and infra, if AI can create better AI models, then isn't OpenAI with its researches going to be the redundant one?


Just tried: open TextEdit, new document (creates an empty document). Close it, no save dialog.


Yup, same. Save dialog only happens if I have added some text (but will still happen if I remove the text I added, which I expected anyways).


Interesting. Is there a picture that explains how the layers talk to each other? Is there a VM system? How does message passing work, what kinds of protections are between tasks?

I have had many ideas for such kernels over the years, but not the patience yet to implement any of them. I wonder if Claude could help me with generating a kernel in less than a day.


I should definitely make that picture. Yes, it as VM. Message passing all runs through the kernel. Task isolation is strictly memory based, whether a task acts on or responds to a message is something the tasks will have to negotiate between themselves. You could whitelist, use a token scheme or any other method for authentication that you wish to put in place, but out of the box there is none, if you know a tasks ID you can send it a message. Obviously there are ownership of resource constraints and the kernel will always ensure that the receiving task knows who the sending task is to ensure that parties are not stealing each others descriptors and such.


Pull the source and ask Claude to explain it to you...


Instead of just saying: rsync on my system is version 3.2, have you tried copy/pasting rsync --help? In my experience, that would be enough for the AI to figure out what it needs to do and which arguments to use. I don't treat AI like an oracle, I treat it like an eager CS grad. I must give it the right information for the task.


Yes, sounds to me like the user really wanted to sort by time created. And got used to sorting alphabetically as a poor proxy for that.


When copying files from a device and then between systems, too often the dates get lost (shouldn't, but still...)


That only happens for the datetime metadata of the files (modified, created, access etc). The EXIF metadata will still remain the same.


I don't particularly recommend this article, it's a little bit too simplistic and the reasons given are not quite right.


What would you recommend to learn this topic in detail with accuracy?


A must read would be "What Every Programmer Should Know About Memory"[1], Section 4 covers Virtual Memory.

[1] https://people.freebsd.org/~lstewart/articles/cpumemory.pdf


Background : Operating Systems: 3 easy pieces

ISA/OS level: Architectural and Operating System Support for Virtual Memory

(Both are books)


We can only hope the parent comment indeed knows a better source or even what he is talking about. Let give him the benefit of the doubt and assume that the shortness of his comment derives from a lack of time and not from a lack of knowledge.


don’t be shy :o), please do recommend alternatives !


Pssh, real developers read volumes 1, 3A, 3B, 3C, and 3D of the Intel® 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes, pages 3125 through 4200

And if you have a steady hand, a magnetized needle and a hard drive can be used for practice exercises.


do you have similar references for risc-v ?


The RISC-V privileged spec describes their paging implementation (under the Supervisor-level ISA), while the unprivileged spec has a chapter and two appendices describing their memory model (RVWMO), formal axiomatic and operational models included.

Finding the inevitable bugs in the formal model is left as an exercise to the reader (three bugs where the axiomatic/operational models disagree are already known).

If you want a more gentle introduction, the Computer Organization and Design book is pretty nice.


the book, I have gone through (yes, exercises too :o), fwiw) thanks for the risc-v reference.


There never was a problem generating documentation from code

That doesn't match my experience at all. Before AI, generating documentation from code was either getting some embedded comments for a function call, or just list a function's arguments.

AI reads the implementation, reads the callers and callees, and provides much smarter documentation, with context. Something sorely lacking from previous solutions. Is it sometimes not completely accurate? Probably. But still a giant step forward.


I think it depends on how good your documentation generator was before. Finding all the callers and callees is not a new idea to LLMs.


>This analysis would suggests a 2.7× speedup vs. hash tables: 128 bytes vs. 48 bytes of memory traffic per uint64

It's ok to waste bandwidth, it doesn't directly impact performance. However, the limitation you are hitting (which directly impacts performance) is the number of memory accesses you can do (per cycle for instance) and the latency of each memory access. With linear access, after some initial read, data is ready instantly for the CPU to consume. For scattered data (hash tables), you have to pay a penalty on every read.

So the bandwidth ratio is not the right factor to look at to estimate performance.


Could it be a TLB issue? Page size on Mac is 4x larger than on Intel.


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: