Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7420 > unrolled thread
| Started by | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| First post | 2011-12-24 12:09 +0000 |
| Last post | 2012-01-01 07:30 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Retrieving pasteable function definition without contexts preprended Szabolcs Horvát <szhorvat@gmail.com> - 2011-12-24 12:09 +0000
Re: Retrieving pasteable function definition without contexts preprended A Retey <awnl@gmx-topmail.de> - 2011-12-29 07:58 +0000
Re: Retrieving pasteable function definition without contexts preprended Szabolcs Horvát <szhorvat@gmail.com> - 2012-01-01 07:30 +0000
| From | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| Date | 2011-12-24 12:09 +0000 |
| Subject | Retrieving pasteable function definition without contexts preprended |
| Message-ID | <jd4fdh$da8$1@smc.vnet.net> |
Dear MathGroup,
I'm essentially asking the same question that E. Martin-Serrano has
asked this February (message quoted at the end):
http://forums.wolfram.com/mathgroup/archive/2011/Feb/msg00515.html
What is the best way to print the definition of a package symbols
without contexts, so it's more readable?
To his question (what is a substitute to Developer`ContextFreeForm), we
can use Block[{$ContextPath = Append[$ContextPath =
"contextIdontWantPrinted`", FullDefinition[symbol]]
This method still has a problem though. The definition that's printed
cannot be copied directly because quotation marks are missing. I would
like to copy it to Workbench for formatting.
Take for example the definition of RunThrough which contains
WriteString[tmpfile, "\n"]. The "\n" part won't show at all.
Are there any other solutions? Do you have any other suggestion about
making it easy to read the code of already defined function (when we
don't have access to the source file)?
Note: I also asked about this here
<http://stackoverflow.com/questions/8607813> and got an alternative
answer to pasting to Workbench for formatting.
> Hi,
>
>
>
> On 2003, I sent to MathGroup the question whose answer is in the link below.
>
>
>
> http://forums.wolfram.com/mathgroup/archive/2003/Jun/msg00146.html
>
>
>
> The idea was to remove the description of the context of local variables in
> packages (the syntactical sugar, I said in that post), as to make clearer
> the definitions inside the private context of packages, which really makes
> obscure these definitions.
>
>
>
> With the answer given in the link to me question, I wrote a trivial function
> which made the trick as follows,
>
>
>
> FullSymbolInfo[s_Symbol]:=Module[{d=FullDefinition[s]//Developer`ContextFree
> Form},If[d==Null,Print["Symbol '"<>ToString[s]<>"' not defined"],d]]
>
>
>
> The idea was *Developer`ContextFreeForm* applied to the (full) definition of
> the symbols in the private context, but now without the
> Developer`ContextFreeForm* facility available, the function does not work
> any more (I think it worked up to the version 6).
>
>
>
> I have unsuccessfully tried to find a substitution for it, (for the
> *Developer`ContextFreeForm* command) might someone in the group come up with
> an alternative? The function *FullSymbolInfo[s_Symbol]* used to be very
> useful.
>
>
>
> Cheers.
>
>
>
> E. Martin-Serrano
--
Szabolcs Horvát
Mma QA site proposal: http://area51.stackexchange.com/proposals/37304
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2011-12-29 07:58 +0000 |
| Message-ID | <jdh6j4$kmd$1@smc.vnet.net> |
| In reply to | #7420 |
Hi,
> I'm essentially asking the same question that E. Martin-Serrano has
> asked this February (message quoted at the end):
>
> http://forums.wolfram.com/mathgroup/archive/2011/Feb/msg00515.html
>
> What is the best way to print the definition of a package symbols
> without contexts, so it's more readable?
>
> To his question (what is a substitute to Developer`ContextFreeForm), we
> can use Block[{$ContextPath = Append[$ContextPath =
> "contextIdontWantPrinted`", FullDefinition[symbol]]
>
> This method still has a problem though. The definition that's printed
> cannot be copied directly because quotation marks are missing. I would
> like to copy it to Workbench for formatting.
>
> Take for example the definition of RunThrough which contains
> WriteString[tmpfile, "\n"]. The "\n" part won't show at all.
>
> Are there any other solutions? Do you have any other suggestion about
> making it easy to read the code of already defined function (when we
> don't have access to the source file)?
>
> Note: I also asked about this here
> <http://stackoverflow.com/questions/8607813> and got an alternative
> answer to pasting to Workbench for formatting.
I'm not sure whether this is really what you need, but from your
description you are only missing an InputForm in the
stackoverlfow-suggestion. The following gives code that can be copied
and pasted to workbench:
Unprotect[RunThrough];
ClearAttributes[RunThrough, ReadProtected]
Block[{$ContextPath = Append[$ContextPath, "System`Dump`"]},
Print[InputForm[FullDefinition[RunThrough]]]]
hth,
albert
[toc] | [prev] | [next] | [standalone]
| From | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| Date | 2012-01-01 07:30 +0000 |
| Message-ID | <jdp239$rq7$1@smc.vnet.net> |
| In reply to | #7470 |
On 2011.12.29. 8:58, A Retey wrote:
> Hi,
>
>> I'm essentially asking the same question that E. Martin-Serrano has
>> asked this February (message quoted at the end):
>>
>> http://forums.wolfram.com/mathgroup/archive/2011/Feb/msg00515.html
>>
>> What is the best way to print the definition of a package symbols
>> without contexts, so it's more readable?
>>
>> To his question (what is a substitute to Developer`ContextFreeForm), we
>> can use Block[{$ContextPath = Append[$ContextPath =
>> "contextIdontWantPrinted`", FullDefinition[symbol]]
>>
>> This method still has a problem though. The definition that's printed
>> cannot be copied directly because quotation marks are missing. I would
>> like to copy it to Workbench for formatting.
>>
>> Take for example the definition of RunThrough which contains
>> WriteString[tmpfile, "\n"]. The "\n" part won't show at all.
>>
>> Are there any other solutions? Do you have any other suggestion about
>> making it easy to read the code of already defined function (when we
>> don't have access to the source file)?
>>
>> Note: I also asked about this here
>> <http://stackoverflow.com/questions/8607813> and got an alternative
>> answer to pasting to Workbench for formatting.
>
> I'm not sure whether this is really what you need, but from your
> description you are only missing an InputForm in the
> stackoverlfow-suggestion. The following gives code that can be copied
> and pasted to workbench:
>
> Unprotect[RunThrough];
>
> ClearAttributes[RunThrough, ReadProtected]
>
> Block[{$ContextPath = Append[$ContextPath, "System`Dump`"]},
> Print[InputForm[FullDefinition[RunThrough]]]]
>
Thank you, this indeed solves the problem! I am not sure why I thought
that InputForm doesn't affect FullDefinition ...
It's also important to note that Print[] is essential here. Without it
the context names are not removed.
Based on this, here's a function to print definitions with the commonest
context removed:
commonestContext[sym_Symbol] :=
Commonest[
Cases[
Level[DownValues[sym], {-1}, HoldComplete],
s_Symbol /; FreeQ[$ContextPath, Context[s]] :> Context[s]
], 1]
contextFreeDefinition[sym_Symbol] :=
Internal`InheritedBlock[{sym},
ClearAttributes[sym, ReadProtected];
Block[ {$ContextPath =
Join[$ContextPath, commonestContext[sym]]},
Print@InputForm[FullDefinition[sym]]
]
]
Example use:
contextFreeDefinition[RunThrough]
--
Szabolcs Horvát
Mma QA site proposal: http://area51.stackexchange.com/proposals/37304
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web