Previous Page Next Page Contents

expr2text -- convert objects into character strings

Introduction

expr2text(object) converts object into a character string.

Call(s)

expr2text(object)

Parameters

object - any MuPAD object

Returns

a string.

Overloadable:

object

Related Functions

coerce, fprint, int2text, tbl2text, text2expr, text2int, text2list, text2tbl, print

Details

Example 1

Expressions are converted into character strings:

>> expr2text(a + b)
                                  "a + b"

expr2text quotes strings. Note that the quotation marks are preceded by a backslash when they are printed on the screen:

>> expr2text(["text", 2])
                              "[\"text\", 2]"

Example 2

If more than one argument is given, the arguments are treated as a single expression sequence:

>> expr2text(a, b, c)
                                 "a, b, c"

If no argument is given, an empty string is generated:

>> expr2text()
                                    ""

Example 3

expr2text evaluates its arguments:

>> a := b: c := d: expr2text(a, c)
                                  "b, d"

Use hold to prevent evaluation:

>> expr2text(hold(a, c));
   delete a, c:
                                  "a, c"

Here is another example:

>> expr2text((a := b; c := d));
   delete a, c:
                                    "d"
>> e := expr2text(hold((a := b; c := d)))
                           "(a := b; \nc := d)"

The last string contains a newline character '\n'. Use print with option Unquoted to expand this into a new line:

>> print(Unquoted, e):
                                 (a := b;
                                 c := d)

Example 4

expr2text is overloadable. It uses a default output for elements of a domain if the domain has neither a "print" slot nor an "expr2text" slot:

>> T := newDomain("T"): e := new(T, 1):
   e;
   print(e):
   expr2text(e)
                                 new(T, 1)
      
                                 new(T, 1)
      
                                "new(T, 1)"

If a "print" slot exists, it will be called by expr2text to generate the output:

>> T::print := proc(x) begin
     _concat("foo: ", expr2text(extop(x)))
   end_proc:
   e;
   print(e):
   expr2text(e)
                                  foo: 1
      
                                  foo: 1
      
                                 "foo: 1"

If you want expr2text to generate an output differing from the usual output generated by print, you can supply an "expr2text" method:

>> T::expr2text := proc(x) begin
     _concat("bar: ", expr2text(extop(x)))
   end_proc:
   e;
   print(e):
   expr2text(e)
                                  foo: 1
      
                                  foo: 1
      
                                 "bar: 1"

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000