Introduction
Once, at one of the computer forums, participants shared their thoughts on what they lack in languages, so to speak, in their daily activities. One said that he was sorely missing an operator like put data . For those who have not heard of this, I will explain that the PL / 1 language provided an operator for outputting (or entering) the values of variables along with their names, i.e. along with identifiers.
, put list(X,Y); - :
1280 1024
put data(X,Y); :
X= 1280 Y= 1024
:
put list(’X=’,X,’Y=’,Y);
, . , put data, «» get data .
, «» ( ) put data .
, , () . put data . « », (.. ) . , exe- . «» . , , , put data, , . , «» . , .
-
, , put data . . , , . :
1. , -. , , . (.. ) , , , , .., .
2. , . , , . , , .
, . - .
put data , ( ) , « ».
. - «», . «» , .. , , -.
, , :
put data(x(i+1,j-1));
:
put list(’x(i+1,j-1)=’,x(i+1,j-1));
, -, . . , , .
-
« » . put data, – - . - , .
, put data , :
put data(x);
« » - :
do i=lbound(x) to hbound(x); put data(x(i)); end;
. , x – (, 33), put data(x); , - :
X(1,1)= 1 X(1,2)= 2 X(1,3)= 3 X(2,1)= 4 X(2,2)= 5 X(2,3)= 6 X(3,1)= 7 X(3,2)= 8 X(3,3)= 9
put data(x(2)); :
X(2,1)= 4 X(2,2)= 5 X(2,3)= 6
x – ( PL/1 ), , :
declare
1 a,
2 a1 fixed,
2 a2 fixed,
2 b,
3 b1 fixed,
3 b2 float;
put data(a);
A.A1= 0 A.A2= 0 A.B.B1= 0 A.B.B2= 0.000000E+00
, , (.. ), :
declare
1 a(1:2),
2 a1 fixed,
2 a2 fixed,
2 b,
3 b1 (-5:3) fixed,
3 b2 float;
put data(b);
B(1).B1(-5)= 0 B(1).B1(-4)= 0 B(1).B1(-3)= 0 B(1).B1(-2)= 0 B(1).B1(-1)= 0 B(1).B1(0)= 0 B(1).B1(1)= 0 B(1).B1(2)= 0 B(1).B1(3)= 0 B(1).B2= 0.000000E+00 B(2).B1(-5)= 0 B(2).B1(-4)= 0 B(2).B1(-3)= 0 B(2).B1(-2)= 0 B(2).B1(-1)= 0 B(2).B1(0)= 0 B(2).B1(1)= 0 B(2).B1(2)= 0 B(2).B1(3)= 0 B(2).B2= 0.000000E+00
PL/1 -. . - :
put list((x(i) do i=lbound(x) to hbound(x)));
:
do i=lbound(x) to hbound(x); put list(x(i)); end;
- . , PL/1 , , , . , :
put list(1e0*(x1+x2)/2e0));
, , - , . – , . .
, (put data) – . , . , , . . . – , , , -.
, -, « », . .
, put data, , . .. , , . - , , , , , , - .
, , . , , x(1:10,1:10,1:10) :
put list(x); 1000
put list(x(5)); 100
put list(x(5,6)); 10 .
put list(x(5,6,8)); - .
, put data , . ?A, ?B, ?,…?O ( 15 15) :
X(?A,?B)= 1 X(?A,?B)= 2 X(?A,?B)= 3 X(?A,?B)= 4 X(?A,?B)= 5 X(?A,?B)= 6 X(?A,?B)= 7 X(?A,?B)= 8 X(?A,?B)= 9
. put data – ?A, ?B, ?,…?O, 07FH.
, , , , , . . , , .
, put data - get data, , . , , PL/1 . , . , , put data(x);, :
X(1,2)= 2 X(1,1)= 1 X(2,3)= 6 X(2,1)= 4 X(2,2)= 5 X(3,1)= 7 X(1,3)= 3 X(3,2)= 8 X(3,3)= 9
get data(x); , . , , , , - . , , exe-, get data. , . – put data get data «» put get .
, - . , , - , . - , , , .
, , , , . , , , , -.
, , :
1. .
2. .
« » , , , « ».
, , . , , , , .. , put data.
, , , PL/1:
using System.Console;
using PL1.Macro;
module Program
{
Main() : void
{
def x = 1280;
def y = 1024;
put data(x, y);
put data(x, y, x + y, x.ToString() + "asd");
_ = ReadLine();
}
}
using Nemerle;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using System.Collections.Generic;
using System.Linq;
namespace PL1.Macro
{
public macro PutData(args)
syntax ("put", "data", args)
{
PutDataImpl.Impl(args)
}
module PutDataImpl
{
public Impl(args : PExpr) : PExpr
{
match (args)
{
| PExpr.Tuple as args =>
def code = List();
foreach (arg in args.args)
{
code.Add(<[ $(arg.ToString()) ]>);
code.Add(<[ "=" ]>);
code.Add(arg);
code.Add(<[ " " ]>);
}
code.RemoveAt(code.Count - 1);
def code = code.Aggregate((a1, a2) => <[ $a1 + $a2 ]>);
<[ System.Console.WriteLine($(code)) ]>
| _ => PExpr.Error(args.Location, "Tuple expected.")
}
}
}
}
However, when I was asked to modify the library so that it would allow displaying non-scalar objects with printing of all indices (and then it would really repeat the capabilities of PL / 1), I was asked to do it myself as a "homework". I rejected this honor, under the pretext that, in fact, I have all this and have been using it for a long time. Apparently, the author of the library simply did not immediately figure out how to do this. And for some reason I remembered a scene from the movie "Formula of Love", where Cagliostro, having surprised everyone by eating a fork, still refused to eat a plate at the same time.