MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: RE: Strange use of FrontEnd`FileName

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71753] Re: [mg71721] RE: [mg71664] Strange use of FrontEnd`FileName
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Tue, 28 Nov 2006 06:04:08 -0500 (EST)
  • Reply-to: jfultz at wolfram.com

They would not give the same results if, for example, the FE was running on 
a Windows machine and the kernel was running on a Linux machine because the 
pathname separators would be different.

Things like $BaseDirectory and $UserBaseDirectory could be different even 
if the FE and kernel were running on different machines of identical 
architecture.

When ToFileName[] sees FrontEnd`FileName[], it passes off the job of 
filename resolution to the FE instead of doing the job itself.  Literally, 
ToFileName[] sends a MathLink request to the FE and the FE responds.

And yes, FrontEnd`FileName[] is either nominally documented or completely 
undocumented (not sure which).  This is a bit of an under-the-hood detail, 
and sometimes we document such things, but sometimes we don't.  This can 
happen due to oversight, lack of interest, or because there's an 
expectation that the design might change in the future.

But we're not going to let a lack of documentation get in the way of 
producing useful FAQs.  I wrote the original code used for the FAQ, and I 
used the FrontEnd`FileName[] output of NotebookInformation[] because it is 
the only 100% correct way to get the information you need (not to mention 
the fact that it's convenient).  Removing the FrontEnd`FileName[] wrapper 
would work in most cases, but I would rather use a nominally or 
undocumented, completely correct code snippet rather than a fully 
documented code snippet that works 97% of the time.

Incidentally, the next major release of Mathematica will have a new 
function that conveniently gets a notebook's directory, so the FAQ will 
have a much simpler answer in the future.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Mon, 27 Nov 2006 04:04:57 -0500 (EST), Philipp wrote:
> Dear Li,
>
> I never questioned that the FrontEnd`FileName wrapper (Head) worked in
> the original statement, i.e., ToFileName accepted input wrapped in
> FrontEnd`FileName. My question was, why it was necessary to wrap the
> result of Extract in the FrontEnd`FileName Head, and why ToFileName
> accepted input with FrontEnd`FileName. Even the error message caused by
> your In[16], where you wrap the directory list in test, states that
> "ToFileName::strse: String or list of strings expected at position 1
> ...".
>
> Following your logic
>
> In[1]:=  fn = "FileName" /. NotebookInformation[EvaluationNotebook[]]
> Out[1]=  FrontEnd`FileName[{$RootDirectory, E:, Common, Desktop},
> Untitled-1.nb, CharacterEncoding -> WindowsANSI]
>
> In[2]:=  ex0 = Extract[fn, {1}]
> ex1 = Extract[fn, {1}, FrontEnd`FileName]
>
> Out[2]=  {, E:, Common, Desktop}
> FrontEnd`FileName[{$RootDirectory, E:, Common, Desktop}]
>
> In[4]:=  ToFileName[ex0]
> ToFileName[ex1]
>
> Out[4]=  E:\Common\Desktop\
> E:\Common\Desktop\
>
> The last two statements still give the same answer, although ex1 has
> FrontEnd`FileName wrapper,
>
> In[6]:=  Head[ex0]
> Head[ex1]
>
> Out[6]=  List
> FrontEnd`FileName
>
> Cheers,
>
> Philipp.
>
> -----Original Message-----
> From: À÷Õý¼ª [mailto:zhengji.li at gmail.com]
> Sent: Monday, November 27, 2006 9:16 AM
> To: Philipp
> Cc: mathgroup at smc.vnet.net
> Subject: [mg71721] Re: [mg71664] Strange use of FrontEnd`FileName
>
> Philipp,
>
> Firstly, see what's happened with the use of extract.
>
> In[8]:=
> "FileName" /. NotebookInformation[EvaluationNotebook[]]
> Out[8]=
> FrontEnd`FileName[{$RootDirectory, "C:", Documents and Settings", ...,
> "Desktop"}, Untitled-2.nb, CharacterEncoding -> WindowsANSI]
> In[9]:=
> Extract["FileName" /. NotebookInformation[
> EvaluationNotebook[]], {1}, FrontEnd`FileName]
> Out[9]=
> FrontEnd`FileName[{$RootDirectory, "C:", Documents and Settings", ...,
> "Desktop"}]
>
> Secondly, ToFileName really works with
> FrontEnd`FileName[{$RootDirectory, "C:", Documents and Settings", ...,
> "Desktop"}]. Let's check it out:
>
> In[16]:=
> FrontEnd`FileName[{$RootDirectory, "C:", "Desktop"}] // ToFileName (*
> This is OK*)
> Remove[test];
> test[{$RootDirectory, "C:", "Desktop"}] // ToFileName (* This is bad *)
> {$RootDirectory, "C:", "Desktop"} // ToFileName (* OK, too *)
> Out[16]=
> C:\Desktop\


  • Prev by Date: Re: Not accepting function as parameter
  • Next by Date: Re: sum of integrals over patial intervals != integral over whole interval
  • Previous by thread: RE: Strange use of FrontEnd`FileName
  • Next by thread: Re: Plotting a function -