[erlang-questions] Why we need a -module() attribute?

Richard A. O'Keefe ok@REDACTED
Mon Feb 22 23:30:23 CET 2016


I do not recall ever seeing -module coming up here before.
I certainly don't recall a long thread like this one.

I believe I have pointed out how utterly trivial it is to
create the -module directive and how valuable I have found
it in detecting file-system-created snafus.

#!/bin/sh
#Usage: edit module
case "$1" in
  */*)  echo "Module name may not contain /"   >/dev/stderr; exit 1 ;;
  -*)   echo "Module name may not start with -">/dev/stderr; exit 1 ;;
  *\'*) echo "Module name may not contain '"   >/dev/stderr; exit 1 ;;
  *\\*) echo "Module name may not contain \\"  >/dev/stderr; exit 1 ;;
  *)    ;;
esac
file="$1.erl" # Beware: file system may mangle name!
if [ ! -e "$file" ]; then
    date=`date +%Y-%m-%d`
    case `expr "$1" : '^[a-z][a-zA-Z0-9_]*$'` in
     0) module="'$1'" ;;
     *) module="$1"   ;;
    esac
    echo "%%% File   : $file"     >"$file"
    echo "%%% Author : $LOGNAME" >>"$file"
    echo "%%% Created: $date"    >>"$file"
    echo "%%% Purpose: "         >>"$file"
    echo ""                      >>"$file"
    echo "-module($module)."     >>"$file"
    echo ""                      >>"$file"
    echo "-export(["             >>"$file"
    echo " ])."                  >>"$file"
    echo ""                      >>"$file"
fi
exec ${EDITOR:-emacs} "$file"

This isn't completely bullet-proof, but it's close enough
to be useful.  The program I actually use fills in the full
name from the pw_gecos field in the struct passwd entry for
$LOGNAME and adds a copyright notice if you want one.

So here's how much burden -module adds to this programmer:
instead of
  % emacs foobar.erl
I have to type
  % edit foobar

Hang on, that's LESS work.

Hmmm.




More information about the erlang-questions mailing list