<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def define_macro(out_f, (name, args, body), undefine=False, check=True):
 """Generate a macro definition or undefinition"""

    if undefine:
        out_f.write(
            '#undef {0}\n'
            .format(macro_name(name))
        )
    else:
        if args:
            arg_list = '({0})'.format(', '.join(args))
        else:
            arg_list = ''

        if check:
            out_f.write(
                '#ifdef {0}\n'
                '#  error {0} already defined.\n'
                '#endif\n'
                .format(macro_name(name))
            )

        out_f.write(
            '#define {0}{1} {2}\n'.format(macro_name(name), arg_list, body)
        )