Convert: Data Convertions

      $func  ToLower  e.Char = e.Char;
      $func  ToUpper  e.Char = e.Char;
      $func  CharsToBytes  e.Char = e.Int;
      $func  BytesToChars  e.Int = e.Char;
      $func  ToChars  e.Exp  = e.Char;
      $func  ToWord   e.Exp  = s.Word;
      $func? ToInt    e.Exp  = s.Int;

ToLower converts a sequence of character symbols to a character sequence in which all capital letters are replaced with the correspondent small letters.

ToUpper converts a sequence of character symbols to a character sequence in which all small letters are replaced with the corresponding capital letters.

CharsToBytes converts a sequence of character symbols to a sequence of numbers, each number being the ASCII code of the corresponding character.

If one of the above functions is given an argument that is not a sequence of character symbols, the value returned is $error(Fname "Invalid argument"), where Fname is the function's name.

For example:

      <ToLower 'AbCd+'>  =>   'abcd+'
      <ToLower 25>       => $error(ToLower "Invalid argument")
      <ToUpper 'AbCd+'>  =>   'ABCD+'
      <ToUpper 25>       => $error(ToUpper "Invalid argument")
      <CharsToBytes 'ABC'>   =>   65 66 67

BytesToChars takes as argument a sequence of numbers, each number ranging between 0 and 255, and converts it to a sequence of character symbols, each character having the ASCII code equal to the corresponding number.

For example:

      <BytesToChars 65 66 67>     =>   'ABC'

ToChars, ToWord, and ToInt take an arbitrary ground expression as argument, and, first of all, convert it to a character sequence. The conversion is performed as follows. Character symbols are replaced with the corresponding characters, the parentheses are replaced with the characters '(' and ')', word symbols are replaced with the corresponding character sequences, numeric symbols are replaced with their character representations, references to strings are replaced with the contents of the strings, all other references are replaced with their character representations, which depend on the Refal Plus implementation.

If the character sequence thus obtained exceeds the size limit imposed by the Refal Plus implementation, the value returned by the functions is $error(Fname "Argument too large for conversion"), where Fname is the function's name.

Then the functions ToChars, ToWord, and ToInt proceed in the following way.

ToChars just returns the character sequence thus obtained as its result.

      <ToChars "John">   =>   'John'
      <ToChars 'John'>   =>   'John'
      <ToChars 326>      =>   '326'
      <ToChars -326>     =>   '-326'
      <ToChars (-326) "John">   =>   '(-326)John'

ToWord converts the character sequence thus obtained to the corresponding word.

      <ToWord "John">    =>   "John"
      <ToWord 'John'>    =>   "John"
      <ToWord 326>       =>   "326"
      <ToWord -326>      =>   "-326"
      <ToWord (-326) "John">   =>   "(-326)John"

ToInt considers the character sequence thus obtained as the character representation of an integer, and converts it to the corresponding numeric symbol. If the character string is not a correct representation of an integer, the value returned is $fail(0).

For example:

      <ToInt '326'>      =>   326
      <ToInt '+326'>     =>   326
      <ToInt "-3" '26'>  =>   -326
      <ToInt -32 006>    =>   -326
      <ToInt 'John'>     =>   $fail(0)