MyDef is a meta-programming preprocessor that adds a macro and code-factoring
layer on top of any programming language. You write .def files using
indentation-based syntax with reusable code blocks (subcodes) and compile-time
macros, and MyDef generates output in your target language.
# greet.def
page: greet.py
$map greet, Alice, Bob, Carol
subcode: greet(name)
print("Hello, $(name)!")
Compile it with mydef_page, then run the output:
$ mydef_page greet.def
PAGE: greet.py
--> [./greet.py]
$ python greet.py
Hello, Alice!
Hello, Bob!
Hello, Carol!
The generated greet.py:
print("Hello, Alice!")
print("Hello, Bob!")
print("Hello, Carol!")
Or use mydef_run to compile and run in one step:
$ mydef_run greet.def
Hello, Alice!
Hello, Bob!
Hello, Carol!
subcode) and inline them with
$call, eliminating boilerplate and repetition&call wraps open/close patterns (file I/O, loops, tags)
around arbitrary content via BLOCK substitution; nesting allows scoped
refactoring without side effects$(name) substitution with scoping, conditionals
($(if:...)), iteration ($(for:...)), and arithmeticPrerequisites: perl, make, git
git clone https://github.com/hzhou/MyDef.git
cd MyDef
sh bootstrap.sh
Set these environment variables (add to ~/.bashrc):
export PATH=$HOME/bin:$PATH
export PERL5LIB=$HOME/lib/perl5
export MYDEFLIB=$HOME/lib/MyDef
export MYDEFSRC=/path/to/MyDef # needed for installing output modules
If these variables are set before running bootstrap.sh, it will install to
those locations. Otherwise it defaults to $HOME/bin, $HOME/lib/perl5, and
$HOME/lib/MyDef.
To update after git pull:
make
make install
Create a file t.def:
page: t.py
print("Hello, World!")
Run it:
$ mydef_run t.def
PAGE: t.py
--> [./t.py]
python ./t.py
Hello, World!
mydef_run compiles the .def file and executes the result. For projects with
multiple files, use mydef_make to generate a Makefile, then use make.
The output file extension determines the language. Try naming the page t.c,
t.java, t.go, t.rs, t.f90, or t.sh (assuming the language toolchain
is installed). Specialized output modules (e.g. module: c, module: perl)
add language-specific features like auto-semicolons and function signatures.
| Command | Purpose |
|---|---|
mydef_page | Compile .def files into output files |
mydef_run | Compile and execute a single .def file |
mydef_make | Generate a Makefile from .def files in the current directory |
mydef_test | Run tests listed in a TESTS file |
mydef_install | Install outputs to $PERL5LIB, $MYDEFLIB, or $PATH |
This repository includes output_general (plain text, default) and
output_perl. Additional modules are available as separate repositories:
output_c, output_python, output_java, output_www, output_go, output_rust, output_fortran, output_win32, output_xs, output_pascal, output_tcl, output_glsl
To install an output module:
git clone https://github.com/hzhou/output_c.git
cd output_c
mydef_make && make && make install
ai_skills/ has skills that teach an AI coding assistant, such
as Claude Code, to write and build MyDef
code:
| Skill | For |
|---|---|
| mydef | General MyDef syntax, directives, and tools |
| mydef-perl | Perl with module: perl (built in) |
| mydef-c | C with module: c (output_c) |
| mydef-html | HTML, PHP, and JavaScript with output_www |
| mydef-python | Python with module: python (output_python) |
| mydef-sh | Shell scripts with module: sh (output_sh) |
| mydef-modules | Installing or rebuilding an output module |
To use them with Claude Code, copy the folders into ~/.claude/skills/:
cp -r ai_skills/* ~/.claude/skills/
They assume the environment from Installation (PERL5LIB,
MYDEFLIB, MYDEFSRC) and module repositories cloned under
$HOME/projects/; edit them to match your own setup.
" ~/.vim/filetype.vim
augroup filetypedetect
au BufNewFile,BufRead *.def setf mydef
augroup END
ln -s /path/to/MyDef/docs/mydef.vim ~/.vim/syntax/
Recommended .vimrc settings:
set shiftwidth=4
set expandtab
nmap <F5> :!mydef_run %<CR>
HTML
99.3%
MyDef is a meta-programming preprocessor that adds a macro and code-factoring
layer on top of any programming language. You write .def files using
indentation-based syntax with reusable code blocks (subcodes) and compile-time
macros, and MyDef generates output in your target language.
# greet.def
page: greet.py
$map greet, Alice, Bob, Carol
subcode: greet(name)
print("Hello, $(name)!")
Compile it with mydef_page, then run the output:
$ mydef_page greet.def
PAGE: greet.py
--> [./greet.py]
$ python greet.py
Hello, Alice!
Hello, Bob!
Hello, Carol!
The generated greet.py:
print("Hello, Alice!")
print("Hello, Bob!")
print("Hello, Carol!")
Or use mydef_run to compile and run in one step:
$ mydef_run greet.def
Hello, Alice!
Hello, Bob!
Hello, Carol!
subcode) and inline them with
$call, eliminating boilerplate and repetition&call wraps open/close patterns (file I/O, loops, tags)
around arbitrary content via BLOCK substitution; nesting allows scoped
refactoring without side effects$(name) substitution with scoping, conditionals
($(if:...)), iteration ($(for:...)), and arithmeticPrerequisites: perl, make, git
git clone https://github.com/hzhou/MyDef.git
cd MyDef
sh bootstrap.sh
Set these environment variables (add to ~/.bashrc):
export PATH=$HOME/bin:$PATH
export PERL5LIB=$HOME/lib/perl5
export MYDEFLIB=$HOME/lib/MyDef
export MYDEFSRC=/path/to/MyDef # needed for installing output modules
If these variables are set before running bootstrap.sh, it will install to
those locations. Otherwise it defaults to $HOME/bin, $HOME/lib/perl5, and
$HOME/lib/MyDef.
To update after git pull:
make
make install
Create a file t.def:
page: t.py
print("Hello, World!")
Run it:
$ mydef_run t.def
PAGE: t.py
--> [./t.py]
python ./t.py
Hello, World!
mydef_run compiles the .def file and executes the result. For projects with
multiple files, use mydef_make to generate a Makefile, then use make.
The output file extension determines the language. Try naming the page t.c,
t.java, t.go, t.rs, t.f90, or t.sh (assuming the language toolchain
is installed). Specialized output modules (e.g. module: c, module: perl)
add language-specific features like auto-semicolons and function signatures.
| Command | Purpose |
|---|---|
mydef_page | Compile .def files into output files |
mydef_run | Compile and execute a single .def file |
mydef_make | Generate a Makefile from .def files in the current directory |
mydef_test | Run tests listed in a TESTS file |
mydef_install | Install outputs to $PERL5LIB, $MYDEFLIB, or $PATH |
This repository includes output_general (plain text, default) and
output_perl. Additional modules are available as separate repositories:
output_c, output_python, output_java, output_www, output_go, output_rust, output_fortran, output_win32, output_xs, output_pascal, output_tcl, output_glsl
To install an output module:
git clone https://github.com/hzhou/output_c.git
cd output_c
mydef_make && make && make install
ai_skills/ has skills that teach an AI coding assistant, such
as Claude Code, to write and build MyDef
code:
| Skill | For |
|---|---|
| mydef | General MyDef syntax, directives, and tools |
| mydef-perl | Perl with module: perl (built in) |
| mydef-c | C with module: c (output_c) |
| mydef-html | HTML, PHP, and JavaScript with output_www |
| mydef-python | Python with module: python (output_python) |
| mydef-sh | Shell scripts with module: sh (output_sh) |
| mydef-modules | Installing or rebuilding an output module |
To use them with Claude Code, copy the folders into ~/.claude/skills/:
cp -r ai_skills/* ~/.claude/skills/
They assume the environment from Installation (PERL5LIB,
MYDEFLIB, MYDEFSRC) and module repositories cloned under
$HOME/projects/; edit them to match your own setup.
" ~/.vim/filetype.vim
augroup filetypedetect
au BufNewFile,BufRead *.def setf mydef
augroup END
ln -s /path/to/MyDef/docs/mydef.vim ~/.vim/syntax/
Recommended .vimrc settings:
set shiftwidth=4
set expandtab
nmap <F5> :!mydef_run %<CR>
HTML
99.3%