11

Is require idempotent? i.e. do

(require 'helm)

and

(require 'helm)
(require 'helm)

end with the same result?

PythonNut
  • 10,363
  • 2
  • 30
  • 76

2 Answers2

14

Yes. From Named Features (emphasis mine):

A feature name is a symbol that stands for a collection of functions, variables, etc. The file that defines them should provide the feature. Another program that uses them may ensure they are defined by requiring the feature. This loads the file of definitions if it hasn't been loaded already.

To require the presence of a feature, call require with the feature name as argument. require looks in the global variable features to see whether the desired feature has been provided already. If not, it loads the feature from the appropriate file. This file should call provide at the top level to add the feature to features; if it fails to do so, require signals an error.

13

Yes, provided that the code in helm.el or helm.elc respects the rule that it must call (provide 'helm). The call (provide 'helm) marks the symbol helm as a loaded feature, and this causes the second call to (require 'helm) to do nothing.

If the loaded package does not call provide then require signals an error, and the feature is not marked as loaded, so a second call to (require 'helm) would attempt the loading again (and typically fail again for the same reason).