2

I can't get any function defined in $UserBaseDirectory/Kernel/init.m to work. For example:

SinDeg[d_] := Sin[d * Degree]; (* Only line in init.m *)

Output:

SinDeg[90]
(* => SinDeg[90] *)

However when copying the code and executing it inside a Mathematica notebook, it works fine:

SinDeg[d_] := Sin[d * Degree];
SinDeg[90]
(* => 1 *)

The Mathematica front-end can definitely see the function definitions as it displays SinDeg as an autocompletion suggestion, when typing SinD.

I'm using Mathematica 9 Home Edition on OS X.

Mark Adler
  • 4,949
  • 1
  • 22
  • 37
Tyilo
  • 1,545
  • 13
  • 25

1 Answers1

6

This has to do with the Notebook's default context setting in the evaluation menu. If it isn't set to Global`, the definitions made in init.m are not seen.

As rm-rf says, a good way to put custom definitions in the init.m would be to use Begin and End to create an Init` context and append that context to the context path so that the definitions are available regardless of the notebook's context. (better still, use packages)

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323