Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

How can I use the Input as a string, without checking by the kernel

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43830] How can I use the Input as a string, without checking by the kernel
  • From: Sirko Straube <straube at biologie.uni-freiburg.de>
  • Date: Wed, 8 Oct 2003 04:47:43 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have a problem with mathematica (I am using 4.2) and the technical 
support could not help me (after months of mailing), although I want to 
do something, that should be rather simple. Maybe someone of you knows a 
solution to this problem. An example notebook is attached.

I have a function (called SLI), that needs a string as Input. In the 
example notebook you have not the original function SLI. Everything one 
has to know is that the original function SLI is fixed. To make it clear 
it calls a function outside of mathematica and it needs the given 
command as a string !!

To explain a bit more what I'am trying to do:
Usually you would type in SLI["1+2-4"] in a notebook and the command 
"1+2-4" would be executed in SLI. This works so far.
What I try now is, that I create a cell type "SLI Input" and whenever 
this cell type is evaluated, the system (specified by my functions) 
should evaluate SLI["<command>"] .
Therefore I need the given command as the exact string.

Together with the Mathematica-Support we managed to make this work, 
except of the error that you get, if you try to evaluate symbols like 
==. The kernel looks at the Input and gives an error. The assumption for 
integrating SLI is in my opinion, that the kernel does not look at the 
input and judges wether it is correct. At the moment the only thing to 
deal with that, is to write

SLI["=="]

to a usual input cell...

Before you try to evaluate the notebook you have to  create a cell type 
named SLI Input in your Style Sheet and set

DefaultFormatType->InputForm


Can someone help me ??


Sincerely,

Sirko Straube

 filename="example_mathgroup.nb"

(************** Content-type: application/mathematica **************
                     CreatedBy='Mathematica 4.2'

                    Mathematica-Compatible Notebook

This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do
one of the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the
  application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info at wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
*******************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      5094,        188]*)
(*NotebookOutlinePosition[      5753,        211]*)
(*  CellTagsIndexPosition[      5709,        207]*)
(*WindowFrame->Normal*)



Notebook[{
Cell["\<\
First of all the example function SLI, which does nothing else, then taking \
the String and printing it out. The original SLI function is much more \
complicated. Therefore this function is fixed. It cannot change its Input \
type.\
\>", "Text"],

Cell["\<\
SLI[x_String]:= Module[{},CellPrint[Cell[\"Executing SLI command: \
\"<>x,Background\[Rule]RGBColor[0,0,1]]];
];\
\>", "Input"],

Cell["\<\
The following functions take the evaluated Input and check if it is evaluated \
from a SLI Input cell (defined in your Style Sheet : you can copy/paste the \
normal Input cell type definition, change the name to \"SLI Input\" and set \
DefaultFormatType\[Rule]InputForm).\
\>", "Text"],

Cell["\<\

GetCellTypeOfThisCell[]:=
    Block[{cellExpr,nb=EvaluationNotebook[]},
      SelectionMove[nb,All,EvaluationCell];
      cellExpr=NotebookRead[nb];
      SelectionMove[nb,After,EvaluationCell];
      If[Length[cellExpr]>1,cellExpr[[2]],\"\"]];

ClearAll[CheckIfSLICommand]

Attributes[CheckIfSLICommand] = {HoldAllComplete};\
\>", "Input"],

Cell["\<\

CheckIfSLICommand[x_] :=   If[
(StringLength[x]\[NotEqual]0)&&(GetCellTypeOfThisCell[]\[Equal] \"SLI \
Input\"),
\"SLI[\"<>ToString[Unevaluated[x], FormatType -> InputForm]<>\"]\",
x
];
  \
\>", "Input"],

Cell["Finally this is written into $PreRead.", "Text"],

Cell[BoxData[
    \(\($PreRead = CheckIfSLICommand;\)\)], "Input"],

Cell["If you evaluate", "Text"],

Cell[BoxData[
    \(SLI["\<1+2\>"]\)], "Input"],

Cell["Executing SLI command: 1+2",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["\<\
the result should be a blue box with  << Executing SLI command:1+2>>. This is \
what SLI does.\
\>", "Text"],

Cell[CellGroupData[{

Cell["Tests", "Section"],

Cell["\<\
Now here are some tests. Every input cell should be of the type \"SLI \
Input\".\
\>", "Text"],

Cell["1 + 2", "SLI Input"],

Cell["Executing SLI command: 1 + 2",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["1/2+\"hello\" abc", "SLI Input"],

Cell["Executing SLI command: 1/2+\"hello\" abc",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["1+2 \"h\\\"el\\\"lo\"abc-4", "SLI Input"],

Cell["Executing SLI command: 1+2 \"h\\\"el\\\"lo\"abc-4",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["1+2-4", "SLI Input"],

Cell["Executing SLI command: 1+2-4",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["\<\
So far this should work. The following commands result in errors. This should \
not be, because we tried to prevent the kernel from looking at the Input.\
\>", "Text"],

Cell[CellGroupData[{

Cell["1 2 add ==", "SLI Input"],

Cell["Syntax::sntxpi: Incomplete expression in result of $PreRead.", "Message"]
}, Open  ]],

Cell[CellGroupData[{

Cell["==", "SLI Input"],

Cell["Syntax::sntxpi: Incomplete expression in result of $PreRead.", "Message"]
}, Open  ]],

Cell["\<\
At the moment the only thing to execute such a command is in the following \
way:\
\>", "Text"],

Cell[BoxData[
    \(SLI["\<==\>"]\)], "Input"],

Cell["Executing SLI command: ==",
  GeneratedCell->True,
  CellAutoOverwrite->True,
  Background->RGBColor[0, 0, 1]],

Cell["Can you help ??", "Text"]
}, Open  ]]
},
FrontEndVersion->"4.2 for X",
ScreenRectangle->{{0, 1280}, {0, 1024}},
WindowSize->{1049, 930},
WindowMargins->{{0, Automatic}, {Automatic, 6}},
StyleDefinitions -> "SLI.nb"
]

(*******************************************************************
Cached data follows.  If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of  the file.  The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1754, 51, 256, 5, 60, "Text"],
Cell[2013, 58, 137, 4, 54, "Input"],
Cell[2153, 64, 295, 5, 60, "Text"],
Cell[2451, 71, 351, 12, 243, "Input"],
Cell[2805, 85, 214, 9, 159, "Input"],
Cell[3022, 96, 54, 0, 37, "Text"],
Cell[3079, 98, 66, 1, 33, "Input"],
Cell[3148, 101, 31, 0, 37, "Text"],
Cell[3182, 103, 47, 1, 33, "Input"],
Cell[3232, 106, 117, 3, 45, InheritFromParent],
Cell[3352, 111, 118, 3, 37, "Text"],

Cell[CellGroupData[{
Cell[3495, 118, 24, 0, 60, "Section"],
Cell[3522, 120, 104, 3, 37, "Text"],
Cell[3629, 125, 26, 0, 49, "SLI Input"],
Cell[3658, 127, 119, 3, 45, InheritFromParent],
Cell[3780, 132, 38, 0, 49, "SLI Input"],
Cell[3821, 134, 131, 3, 45, InheritFromParent],
Cell[3955, 139, 47, 0, 49, "SLI Input"],
Cell[4005, 141, 140, 3, 45, InheritFromParent],
Cell[4148, 146, 26, 0, 49, "SLI Input"],
Cell[4177, 148, 119, 3, 45, InheritFromParent],
Cell[4299, 153, 177, 3, 60, "Text"],

Cell[CellGroupData[{
Cell[4501, 160, 31, 0, 49, "SLI Input"],
Cell[4535, 162, 79, 0, 23, "Message"]
}, Open  ]],

Cell[CellGroupData[{
Cell[4651, 167, 23, 0, 49, "SLI Input"],
Cell[4677, 169, 79, 0, 23, "Message"]
}, Open  ]],
Cell[4771, 172, 105, 3, 37, "Text"],
Cell[4879, 177, 46, 1, 33, "Input"],
Cell[4928, 180, 116, 3, 45, InheritFromParent],
Cell[5047, 185, 31, 0, 37, "Text"]
}, Open  ]]
}
]
*)



(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)




  • Prev by Date: Re: Re: Summation Problem w/ 5.0
  • Next by Date: 3D Plots
  • Previous by thread: Re: Graphics3D Edgeless Polygons
  • Next by thread: 3D Plots