Question on "The Erlang Way"

Chris Pressey cpressey@REDACTED
Sat May 18 22:11:16 CEST 2002


On Fri, 17 May 2002 18:03:53 -0700
"Alex Peake" <apeake@REDACTED> wrote:

> I am new to Erlang. Can someone help me to "think the Erlang way" on the
> following (I am from the Lisp world):
> 
> 1) I want to create a "global" to the application dict. Is this best
> done by spawning a process that manages the dict (like the number
> analyser sample in the Book)? It seems that because of the "assign once"
> strategy, regular variables do not work (dict:store returns a new Dict).

Regular variables are also local to a single process.  But process names
aren't, so a named process (like the number analyser example) is probably
the way to go.

Actually, if I had my druthers, there'd be an application:set_env()
function; then you wouldn't need to roll your own 'application dict'.

> 2) How do you build functions to have optional arguments, like "key"
> arguments in Lisp (there are too many permutations to use a
> pattern/guard for each)? (Lisp example: (create-attr "First_Name"
> varchar :dom-len 20:nullable t) -- the first two arguments (name and
> domain) are required, but others dom-len, nullable and many others are
> optional (and have default values).

I would pass a list.  Probably a list of {key, value} tuples, much like
that used by the functions in GS.  So your function call would look
something like:

  create_attr("First_Name", varchar, [{dom_len, 20}, {nullable, t}])

(please excuse the fact that I don't know lisp :-)

-Chris



More information about the erlang-questions mailing list