[erlang-questions] extending function clauses

Dave Smith dave.smith.to@REDACTED
Fri Dec 19 18:44:18 CET 2008


In Erlang, one might write a geometry server that allows you to register
another module with a callback to calculate area.
If you come from an OO background, it's sometimes helpful to consider how
objects map to Erlang processes instead of modules.

2008/12/19 Ittay Dror <ittay.dror@REDACTED>

>
> Hi,
>
> Is it possible to add clauses to a function that is defined in another
> module?
>
> More elaborately: say a 3rd party module 'geometry' defines a function
> 'area', for each shape (shapes are defined as tuples where the first
> element
> is an atom naming the shape) there is a clause (so there is a clause for
> 'circle', 'square' etc.). Now, I have a new shape. Can I extend
> 'geometry:area' so it can handle my new shape (by adding a new clause). I
> cannot change the original module's file. 'geometry:area' is used by other
> functions to do more sophisticated stuff (so defining my own area function
> is not effective). If not, what is the erlang way of handling this
> situation?
>
> Thank you,
> Ittay
> --
> View this message in context:
> http://www.nabble.com/extending-function-clauses-tp21091060p21091060.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081219/5019f166/attachment.htm>


More information about the erlang-questions mailing list