Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The biggest project is implementing the D compiler itself in 100% D. Don't have much time for other projects.

Nested functions are a little gem. I stole the idea from Pascal. I've since discovered that they can nicely clean up spaghetti code that C engenders, without losing efficiency.

Nested functions would fit into C seamlessly, I sometimes wonder why the C people don't adopt it. I can only assume they just don't realize how sweet they are, which is understandable because you just have to use them a bit to see it.



How do D’s nested procedures differ from the Obj-C block extension?

The original pascal based Mac toolbox APIs encouraged nested procedures in modal contexts - but Nested procedures couldn’t escape their outer frame.


I have no idea what Obj-C block extensions are.

D's nested functions (like Pascal's) have two frame pointers - a dynamic frame pointer (like C has), pointing to the caller's stack frame, and a static frame pointer pointing to the enclosing function's stack frame.

This allows the nested function to access the enclosing function's variables.

It's a bit tricky to set up, but works a treat.


GNU C has had nested functions for quite a long time. I would use them a lot if they were standardized. https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html


D's differs in that:

1. you cannot "goto" out of the nested function

2. you can declare them "static", which means they don't have a static link and cannot access the enclosing function's variables

3. if garbage collection is enabled, you can pass a pointer to the function out of the enclosing function's scope and still safely access its variables

4. they work in `extern (C++)` functions, too




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