2

This is in continuation to the question in Infix form of PutAppend ( >>> ) does not work with variable.

I was trying to use

MakeExpression[RowBox[{lhs_, ">>>", rhs_String}], form_] :=
MakeExpression[
RowBox[{"PutAppend", "[", RowBox[{lhs, ",", rhs}], "]"}],
form
] /; ! StringMatchQ[rhs, "\"*\""]

In terminal, so that

out= "new"<>"file";
{5,5^2}>>>out

would send the expression into "newfile". However the suggested solution failed.

How do I use MakeExpression in a terminal session? Or otherwise use >>> in terminal for a filename stored in an expression?

Itay
  • 31
  • 4
  • "How do I use MakeExpression in a terminal session?" <-- Things typed into a notebook are stored as boxes. The conversion rules from boxes to expressions can be hacked (MakeExpression). Things typed into a terminal are just text. They're interpreted by the kernel's built-in parser, which cannot be changed or hacked. Generally, stuff relying on boxes will only work in notebooks and requires a front end. An example is the Notations package, which is not usable from the terminal. – Szabolcs Aug 12 '15 at 13:45
  • You might want to try UsingFrontEnd. – Silvia Aug 14 '15 at 07:46

1 Answers1

1

To use Put or PutAppend with a filename saved in a string in terminal, one can use it in input form rather then >> or >>>, that is:

filename="newfile.txt"
Put[expression,filename]

or

PutAppend[expression,filename]

I found the answer in https://stackoverflow.com/questions/8853676 by Brett Champion.

While this solves my problem, I would still like to be enlightened as to how to use MakeExpression in a terminal.

Cheers.

Itay
  • 31
  • 4