reddit / emacs

Any experts with literal programming: how to gradually add code to a function?

arthurno1 · 2022-07-23 07:16
AQuietMan · 2022-07-23 12:27
(whispers) *literate*, not *literal*
arthurno1 · 2022-07-23 15:57
Ah indeed, thank :)
Unlucky_Business1099 · 2022-07-25 03:29
there's some way to create a dynamic block which includes all other blocks with a certain identifiers. I think somethings like \[this\](https://emacs.stackexchange.com/questions/46479/how-to-set-a-tangled-parent-directory-for-each-subtree-in-org-mode) So I think you'd need to dynamically collect all source blocks with function body cody, and then "interpolate" (forget emac term). so it would look something like \`\`\` void InitGlobals() { <<init-globals-components>> } \`\`\` hope that helps point you in the right direction (?) \- definitely not an expert
arthurno1 · 2022-07-25 04:01
Yes, that is noweb as pointed by others. However, it can't do what I was asking for. Noweb in org-mode does basically what C preprocessor does, just replaces tokens. So << foo >> will be replaced with a code from a named block foo. Which is good for many uses. But it does not have semantic knowledge of lisp code, so you can't use something like << foo >>+= (some-lisp-expression) to add that (some-lisp-expression) to the body of already defined sexps like say a function foo. For the illustration, I would like to be able to say: (defun foo () "Function foo" (message "foo")) Somewhere later in the text, in some other source code block I would like to write: <<foo>> += (message "bar") And the tangled result would be: (defun foo () "Function foo" (message "foo") (message "bar")) You can also check the C code in the original post.