6
$\begingroup$

I have many packages some of which use some of others. I have many symbols defined in them. Is there a reliable way of finding declared/exported but undefined functions/symbols in several interrelated packages?

$\endgroup$
2
  • $\begingroup$ You mean, to filter all the names in a given context leaving only those without any values defined on them? $\endgroup$
    – Rojo
    Oct 26, 2012 at 15:42
  • 1
    $\begingroup$ My PackageManipulations` package, available here, has the functionality to track escaping symbols. $\endgroup$ Oct 27, 2012 at 21:13

1 Answer 1

4
$\begingroup$

So here is an answer to Rojo's interpretation (which I agree with) of that question:

Select[Names["Global`*"], (First[ToBoxes@Definition[#]] === "Null") &]

Replace "Global`" with context of interest.

Maybe doesn't look neat but works well so far. It is based on an assumption that Definition of a symbol without any values will return Interpretation[Null,Definition[...]]


Another method not based on boxes:

With[{
  info = {Attributes, DefaultValues, DownValues, FormatValues, 
    Messages, OwnValues, SubValues, UpValues, NValues}
  },
  Select[
     Names["Global`*"],
     {} === Flatten @ Through[
        info[ToExpression[#, StandardForm, Unevaluated]]
     ] &
  ]
]

or something less documented

Select[
  Names["Global`*"],
  {} === ToExpression[ #, StandardForm, 
     Echo @* Flatten @* Values @* Values @* First @* 
     Language`ExtendedFullDefinition 
  ] &
]

Both ideas stolen from Triggering actions when a variable is set

$\endgroup$
4
  • 1
    $\begingroup$ Should messages count as definitions? i.e. does x::foo = "123" make x a defined Symbol? $\endgroup$
    – Mr.Wizard
    Jul 28, 2016 at 7:38
  • $\begingroup$ @Mr.Wizard good question, probably not for a sake of consistency but I would count it from a practical point of view. $\endgroup$
    – Kuba
    Jul 28, 2016 at 7:52
  • $\begingroup$ @Mr.Wizard answer upgraded :) $\endgroup$
    – Kuba
    Jul 28, 2016 at 19:47
  • $\begingroup$ Noted. You already had my vote however. :-) $\endgroup$
    – Mr.Wizard
    Jul 29, 2016 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.