hzhou/MyDef

Programming in the next paradigm -- your way

HTML

51

986 commits

updated Sep 30, 2026

See the code

See what people are saying

SourceMessageScoreDate

Reasons to Use MyDef

1

Sep 30, 2026

README

MyDef

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!

Documentation

  • Why MyDef (clean code, design-first development, AI-assisted development)
  • Manual (Getting Started, syntax reference, output module guides)
  • Design (architecture and internals)

Features

  • Code factoring -- define reusable blocks (subcode) and inline them with $call, eliminating boilerplate and repetition
  • Block calls -- &call wraps open/close patterns (file I/O, loops, tags) around arbitrary content via BLOCK substitution; nesting allows scoped refactoring without side effects
  • Compile-time macros -- $(name) substitution with scoping, conditionals ($(if:...)), iteration ($(for:...)), and arithmetic
  • Pluggable output modules -- language-specific backends that add syntax sugar (auto-semicolons, indentation-based control flow, function signatures)
  • Works with any language -- the general module passes text through; specialized modules exist for Perl, C/C++, Python, Java, Go, Rust, Fortran, and more

Installation

Prerequisites: 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

Quick Start

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.

Tools

CommandPurpose
mydef_pageCompile .def files into output files
mydef_runCompile and execute a single .def file
mydef_makeGenerate a Makefile from .def files in the current directory
mydef_testRun tests listed in a TESTS file
mydef_installInstall outputs to $PERL5LIB, $MYDEFLIB, or $PATH

Output Modules

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 Assistant Skills

ai_skills/ has skills that teach an AI coding assistant, such as Claude Code, to write and build MyDef code:

SkillFor
mydefGeneral MyDef syntax, directives, and tools
mydef-perlPerl with module: perl (built in)
mydef-cC with module: c (output_c)
mydef-htmlHTML, PHP, and JavaScript with output_www
mydef-pythonPython with module: python (output_python)
mydef-shShell scripts with module: sh (output_sh)
mydef-modulesInstalling 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 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>

License

MIT

metaprogramming
mydef
paradigm
perl
programming-language
refactor

hzhou/MyDef

Programming in the next paradigm -- your way

HTML

51

986 commits

updated Sep 30, 2026

See the code

See what people are saying

SourceMessageScoreDate

Reasons to Use MyDef

1

Sep 30, 2026

README

MyDef

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!

Documentation

  • Why MyDef (clean code, design-first development, AI-assisted development)
  • Manual (Getting Started, syntax reference, output module guides)
  • Design (architecture and internals)

Features

  • Code factoring -- define reusable blocks (subcode) and inline them with $call, eliminating boilerplate and repetition
  • Block calls -- &call wraps open/close patterns (file I/O, loops, tags) around arbitrary content via BLOCK substitution; nesting allows scoped refactoring without side effects
  • Compile-time macros -- $(name) substitution with scoping, conditionals ($(if:...)), iteration ($(for:...)), and arithmetic
  • Pluggable output modules -- language-specific backends that add syntax sugar (auto-semicolons, indentation-based control flow, function signatures)
  • Works with any language -- the general module passes text through; specialized modules exist for Perl, C/C++, Python, Java, Go, Rust, Fortran, and more

Installation

Prerequisites: 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

Quick Start

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.

Tools

CommandPurpose
mydef_pageCompile .def files into output files
mydef_runCompile and execute a single .def file
mydef_makeGenerate a Makefile from .def files in the current directory
mydef_testRun tests listed in a TESTS file
mydef_installInstall outputs to $PERL5LIB, $MYDEFLIB, or $PATH

Output Modules

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 Assistant Skills

ai_skills/ has skills that teach an AI coding assistant, such as Claude Code, to write and build MyDef code:

SkillFor
mydefGeneral MyDef syntax, directives, and tools
mydef-perlPerl with module: perl (built in)
mydef-cC with module: c (output_c)
mydef-htmlHTML, PHP, and JavaScript with output_www
mydef-pythonPython with module: python (output_python)
mydef-shShell scripts with module: sh (output_sh)
mydef-modulesInstalling 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 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>

License

MIT

metaprogramming
mydef
paradigm
perl
programming-language
refactor

Languages

HTML

99.3%