Programming Guidelines and Additional Notes

  1. Variable names starting with three underscores (___varname) are reserverd for Elfenben. You should not start a variable name with three underscores. Except in a special case which we will come to.
  2. Use macros with caution. In most cases a function would serve the purpose. In which case use a function.
  3. Write macros if you want to add new features to Elfenben or create a domain specific Language.

When you write macros be very careful when you create a variable inside your macro, either using var or as function argument names. Because if the arguments to your macro get dereferenced (eg. ~arg or ~rest...) in the same scope as the variables you created, there is chance for a variable capture situation. This happens when the user of your macro has a variable with the same name and has used it in the argument passed to the macro. You can get around this in the following ways.

  • Obviously if your macro does not create any variables you are fine. There are many macros like that.
  • If your macro is or has an immediately evaluated function, and the macro args get dereferenced as arguments to that function, you are fine again. Because the macro args get dereferenced outside the function. This is also a common situation in Elfenben. As far as possible try to get into this situation.
  • If the variable you create needs to be accessed by the dereferenced code you are fine again
  • If you still need to dereference the macro arg in the same scope as a variable created by you, then makes sure of two things. First that the variable you create is inside a function (usually the case), and second make sure the name starts with three underscores.

results matching ""

    No results matching ""