Live data from Hacker News

Subroutine calls in the ancient world, before computers had stacks or heaps

devblogs.microsoft.com

221–230 of 241 posts

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#221

Earlier quoted context omitted.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... https://www.geeksforgeeks.org/python-map-function/ The whole point of map is that it does the iteration for you and you pass it a function. Iteration is literally the reason it exists.

map predates javascript and python by decades

What does that have to do with the fact that map iterates over a data structure?

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#222

Earlier quoted context omitted.

map predates javascript and python by decades

What does that have to do with the fact that map iterates over a data structure?

You can't rely on how these languages describe mapping.

Map doesn't simply iterate (that would be forEach), it creates another piece of information containing f(a) for all a in the input sequence.

What would iterating over a tree yields ? what would mapping over a tree yields ? how do you define the latter ?

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#223

Earlier quoted context omitted.

What does that have to do with the fact that map iterates over a data structure?

You can't rely on how these languages describe mapping. Map doesn't simply iterate (that would be forEach), it creates another piece of information containing f(a) for all a in the input sequence. What would iterating over a tree yields ? what would mapping over a tree yields ? how do you define the latter ?

You can't rely on how these languages describe mapping.

Says who? You didn't back this claim up with anything.

Map doesn't simply iterate

No one has ever said it 'only' iterates, you hallucinated this claim. The whole point that I've made is that just because a language like haskell uses recursion for iteration, it doesn't mean iteration and recursion are the same thing or that things that iterate have anything to do with recursion.

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#224

Earlier quoted context omitted.

You can't rely on how these languages describe mapping. Map doesn't simply iterate (that would be forEach), it creates another piece of information containing f(a) for all a in the input sequence. What would iterating over a tree yields ? what would mapping over a tree yields ? how do you define the latter ?

You can't rely on how these languages describe mapping. Says who? You didn't back this claim up with anything. Map doesn't simply iterate No one has ever said it 'only' iterates, you hallucinated this claim. The whole point that I've made is that just because a language like haskell uses recursion for iteration, it doesn't mean iteration and recursion are the same thing or that things that iterate have anything to do…

> Says who? You didn't back this claim up with anything.

Why would I need to back that up ?

> No one has ever said it 'only' iterates, you hallucinated this claim. The whole point that I've made is that just because a language like haskell uses recursion for iteration, it doesn't mean iteration and recursion are the same thing or that things that iterate have anything to do with recursion.

Why the mention of haskell all the time ? I'm not even talking about statically typed languages here.

The original conversation was about the intellectual benefits of recursion, not iteration == recursion. Recursion is a way to think about problems that I find more general, precise, creative and economical I tried to convey why, I'm not the most precise but this is getting nowhere. Feel free to enjoy your life.

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#225

Earlier quoted context omitted.

Yeah, but that is error prone and more complex. A compiler can make those same transformations. I'd argue that the properly lazy programmer is the one using recursion. To get even lazier, one should move into relational algebra.

Meh, or just choose a documented data structure that supports your problem scope. If it takes longer than 1 coffee, than someone is usually approaching things the wrong way... Have to think "minimum effort" here... ;-)

I have seen 150 lines of SQL replaced with 12k lines of Java.

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#226

Earlier quoted context omitted.

You can't rely on how these languages describe mapping. Says who? You didn't back this claim up with anything. Map doesn't simply iterate No one has ever said it 'only' iterates, you hallucinated this claim. The whole point that I've made is that just because a language like haskell uses recursion for iteration, it doesn't mean iteration and recursion are the same thing or that things that iterate have anything to do…

> Says who? You didn't back this claim up with anything. Why would I need to back that up ? > No one has ever said it 'only' iterates, you hallucinated this claim. The whole point that I've made is that just because a language like haskell uses recursion for iteration, it doesn't mean iteration and recursion are the same thing or that things that iterate have anything to do with recursion. Why the mention of haskell…

Why would I need to back that up ?

Why do you need to back up the things you say? Because if someone believes anything without an explanation then they don't know what's true.

Why the mention of haskell all the time ?

Because you wrote haskell -> foldl f z (x:xs) = foldl f (f z x) xs

The original conversation was about the intellectual benefits of recursion

No, you made very abstract and bizarre claims like recursion is compressing the domain so small it eats itself, it's creating self sustaining computing blocks, and use tiny function that will thread themselves as see fit.

Statements like this that aren't even really coherent sentences, let alone explainable, are the types of things that happen when no one asks anyone to back up what they say. Evangelism starts to bleed into religion and anyone questioning the grandiose hyperbole is dismissed as an adversary.

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#227

Earlier quoted context omitted.

>but at that point you might as well use Malloc and Realloc. IIRC, the first edition of the classic K&R C book, The C Programming Language, had an example of creating a memory allocator and using it.

It's not difficult to write a memory allocator, but there are some assumptions there which don't always hold true. For instance SmartCards (e.g. SIMs) use a language alleged to be Java, but without a garbage collector and with only one data type. Applications never terminate, so while you can allocate heap memory, you cannot free it and memory exhaustion is one way to brick the device. Since it is "Java" you don't ha…

Interesting. What data type?

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#228

> How did you call a function if you didn’t have a stack for the return address or local variables? Here’s how it worked. First, the compiler defined a secret global variable for each inbound function parameter, plus another secret global variable for each function to hold the return address. It also defined a secret global variable for each of the function’s local variables. I always assumed that functions did somet…

Yes they do. Depending on the architecture, there's either a stack pointer register and CALL/PUSH/POP instructions, or a general purpose auto-increment/decrement addressing mode.

Local variables are placed on the stack as well, this is necessary if you want recursion, and it also typically results in faster/shorter code, because the instruction set and microarchitecture are optimized for this type of memory access.

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#229

Earlier quoted context omitted.

Meh, or just choose a documented data structure that supports your problem scope. If it takes longer than 1 coffee, than someone is usually approaching things the wrong way... Have to think "minimum effort" here... ;-)

I have seen 150 lines of SQL replaced with 12k lines of Java.

Only 12k lines?

That is efficient for most Java programmers. =)

Re: Subroutine calls in the ancient world, before computers had stacks or heaps

#230

Earlier quoted context omitted.

That sounds awfully complicated modifying a recursive algorithm to control the recursion depth. By that, I mean, if sometimes the data happens to be a very deep unbalanced tree that would cause a stack overflow with a naive recursive algorithm, you detect that situation and make it work. Isn't that much harder than just using your own stack (from a library/framework)?

> That sounds awfully complicated modifying a recursive algorithm to control the recursion depth. An easy way to do it is to just pass a separate "depth" integer parameter into the recursive function. It then passes that +1 when it makes a recursive call. At the top of the function, if the depth is above your chosen limit, you bail out in some way instead of continuing to recurse. > you detect that situation and make…

OK, controlling the recursion depth just means failing more gracefully than a stack overflow. The GP's statement that nobody's likely to encounter a bigger problem is silly. It can happen walking a mesh of a 3D model where perfectly valid geometry or ordering might lead to a million-deep branch.
Post reply on HN