What's reliable way of finding declared but undefined functions/symbols in several interrelated packages?

6

1

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?

qazwsx

Posted 2012-10-26T15:21:50.430

Reputation: 8 134

You mean, to filter all the names in a given context leaving only those without any values defined on them? – Rojo – 2012-10-26T15:42:46.743

1

My PackageManipulations` package, available here, has the functionality to track escaping symbols.

– Leonid Shifrin – 2012-10-27T21:13:55.633

Answers

4

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

Kuba

Posted 2012-10-26T15:21:50.430

Reputation: 129 207

1Should messages count as definitions? i.e. does x::foo = "123" make x a defined Symbol? – Mr.Wizard – 2016-07-28T07:38:55.427

@Mr.Wizard good question, probably not for a sake of consistency but I would count it from a practical point of view. – Kuba – 2016-07-28T07:52:41.873

@Mr.Wizard answer upgraded :) – Kuba – 2016-07-28T19:47:05.157

Noted. You already had my vote however. :-) – Mr.Wizard – 2016-07-29T05:36:16.563