Printing a call-stack

Related to my previous post, I’m trying to orient myself in a large code-base. I have a number of habits I’m bringing over from procedural programming when exploring a code-base. One of them is printing a call-stack, showing the order the functions were called in if the execution point is inside of a nested function, so I understand how a certain point of execution has been reached.

Is it possible to print a call-stack in Elm? Does the idea of call-stack apply to functional programming languages such as Elm?

Yep, the concept certainly applies!
From your other post it looks like you know Debug.log, and how to use it in a let expression. That should allow you to do this. I don’t think there’s any other way.

Although I’m not sure what your reference point is. What have you used elsewhere? Is there something in JavaScript you’re thinking of?

You could throw an exception with Debug.crash and it would show you a call stack! And you can set break points in Chrome dev tools. But both of these will only work on the generated JS, which is hard to read. Elm doesn’t have a “source map” that dev tools can use to map back to lines in the original Elm code.

Elm has a call stack, yes, and it can be useful to think about. You provide the Elm runtime some functions, most importantly update and view, and it calls them at the appropriate times with the correct arguments. When you call any other function from inside those functions, it goes onto the call stack just as you’d expect.

As for printing out the call stack for debugging purposes… I don’t think that’s currently possible. It sounds like a good idea. Well, it might get confusing if you have a lot of recursive functions.

If you’re trying to understand how a function behaves, maybe try unit testing it with elm-test?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.