Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

As the title states I would like to dynamically show ::usage on several functions.

Let's consider two functions here:

funlist={Plot,Plot3D};

Thus I do:

Input[
  Panel[
   PopupMenu[Dynamic@whichfun, funlist], "usage should be here"], 
  Dynamic@whichfun]

Instead of "usage should be here" I obviously tried (Dynamic@whichfun)::usage but it's complaining that the Head is not a Symbol, so I tried to convert it to a Symbol but it still fails.

Thus the question is:

How can I convert Dynamic@whichfun in order to be able to have its usage?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This is the problem with evaluation, since MessageName is HoldFirst. You can use e.g.

Dynamic[MessageName @@ {whichfun, "usage"}]

or

Dynamic @ MessageName[Evaluate[whichfun], "usage"]

in place of "usage should be here".

share|improve this answer
    
Thanks! It seems like I'll always do the same mistakes when I use Dynamic. Additional Question (might be to be edited): Do you know how to display the first line of the usage only? –  Öskå Oct 1 '13 at 13:35
    
@Öskå Not sure how robust this is, but I would use something like this: Dynamic[First@ StringSplit[MessageName[Evaluate[whichfun], "usage"], "\n"]]. –  Leonid Shifrin Oct 1 '13 at 14:02
    
It does the job, thanks! –  Öskå Oct 1 '13 at 14:05
add comment

Use With to inject expression:

funlist = {Plot, Plot3D};
Input[Panel[PopupMenu[Dynamic@whichfun, funlist], 
  Dynamic[With[{t = whichfun}, MessageName[t, "usage"]]]], 
  Dynamic@whichfun]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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