Metaprogramming
Writing programs that generate, analyze, or transform other programs — or even themselves.
| Use Case | Example |
|---|---|
| Code generation | Generating boilerplate code in web frameworks |
| Compilers / transpilers | A C program that outputs machine code |
| Interpreters | Python interpreter written in C |
| DSLs (Domain-Specific Languages) | A templating language generating SQL or HTML |
| AI-generated code | LLMs (like ChatGPT) generating C++ from specs |
with open("hello.c", "w") as f:
f.write('#include <stdio.h>\nint main() {\n printf("Hello from C!\\n");\n return 0;\n}')
#include <stdio.h>
int main() {
FILE *fp = fopen("gen.py", "w");
fprintf(fp, "print('Hello from generated Python')\n");
fclose(fp);
return 0;
}
(defmacro make-printer (msg)
`(lambda () (print ,msg)))
(setq f (make-printer "Hello from macro"))
(funcall f)
// #[derive(Debug)] is a procedural macro
#[derive(Debug)]
struct Point { x: i32, y: i32 }
Used to generate HTML, SQL, config files, etc., programmatically.
Bootstrapping: A compiler written in the language it compiles (e.g., C compiler written in C).
Quines: Programs that output their own source code.
AI tools: GPT-4 writing JavaScript from natural language.
| Concept | Description |
|---|---|
| Reflection | A program examining its own structure |
| Code synthesis | Automatic generation of correct-by-construction code |
| Transpilation | Translating code from one language to another (e.g., TypeScript → JavaScript) |
A bottom-line question, to me, seems to be: Why use one computer coding language over another??
Knud seems to focus on TSE to achieve some amazing things.
Python appears to be terrific for accomplishing quite a bit.
I remember hearing a computer “expert” say that virtually all computer languages are capable of producing the same results.
--
---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/semware/119563405.715526.1752846261419%40mail.yahoo.com.