2
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ "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. $\endgroup$
    – Szabolcs
    Aug 12, 2015 at 13:45
  • $\begingroup$ You might want to try UsingFrontEnd. $\endgroup$
    – Silvia
    Aug 14, 2015 at 7:46

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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