This is scrapbook of things That I would like to consider for QDL that are not fully formed
but should be captured someplace.

9/27/2021

Classes vs. delegation.
The problem with classes is managing the inheritance hierarchy. Allowing multiple inheritance
is apt to be problematic at times. A better way is to only have interfaces and implementations.
Therefore the relationships are all Has-a vs. Is-a.
Typically, the implementations are embedded modules.

A stem is a set of variables. An interface is a set of function signatures. So

interface[uri][f(x); f(x,y); g(x);];

 Looks like another module...

Z := delegate[uri][
  module_import(A,B);
  module_import(P,Q);
    f(x)->B#f2(x);
  f(x,y)->B#f2(x)*Q#h(y-3);
    g(x)->Q#g(x^2-1)/Q#h(x^2+1);
];
Access elements with
  Z#f(2);
or maybe
  Z::f(2)


Might also have default resolution  mechanism in delegate, so if has a function f and g that are
unique (like in the workspace) then

Z := delegate[uri][
  module_import(A,B);
  module_import(P,Q);
  f(x,y)->B#f(x)*Q#h(y-3);
];

f and g are delegated to B automatically. Alternately, import order determines resolution order.
so if there is no defintion of f explicit, then first wins?

Does this implies some sort of typing? Do want to be able to pass these around? the question then
is if this is a convenience for the author or for code re-use. Passing it around implies
more re-usability.

Types?
------

If we do the above, we would need to be able to query modules like

   is_delegate(Z, uri)

(or why have them implement interfaces?)
So we are heading towards modules being first class objects. Pass them around?
This seems wrong, like we are overloading this concept. We need a large unit
like modules to organize larger units of work and smaller units within those.
Having a single thing for large/small scale is going to make things very clunky
and we want a nice, sleek notation for creating these.
Then these should be called types and be treated that way, which is different from
a module which can remain a larger syntactical unit.

So
  type[type_name][body]
  interface[uri0][...]
  type[type_name2]delegates[uri0][...]
  z := new(type_name); // some form of factory. Constructor?
  is_type(z, uri0)
  f(z,x)->z#g(x)/x^2; // e.g.
OR have a different notation for accessing types. This makes parsing way easier.
  f(z,x)->z::g(x)/x^2; // e.g.

Constructor can be something like a convention to call init(args):
  z:= new(type_name)::init(arg0, arg1,...)
or maybe any other function?

E.g.
type[complex_number][
  __x=0;__y=0;
  init(x,y)->[__x:=x;__y:=y;];
  // need some way to pass these in and check type???
  // creating new types means type checking and type safety(?)
  // Make type checking dyadic?

  add(complex_number & a, complex_number & b)->...
  // Or rather than in the signature, have in invocation?

  // Quick parser test -- & works great as a dyadic operation.
  // This means that type_name & var returns the variable value if true
  // or throws a TypeError if not.
  // Have basic types of number, boolean, stem?
  // Strict type checking will change QDL since the seamless
  // passing of scalars and stems would change.

  // optional type checking with &. Does this mean we add it
  // for scalars and stems?
  ];
z := new(complex_number)::init(2.3, pi()/4);
w := new(complex_number)::init(-1.4, pi()/5);
arg. := [z,w]
z::times(arg., arg.) // returns a stem of complex numbers with the induced operation
// problem with this is typing the :: to an instance.
// Better?
arg2.:=complex_number::times(arg., arg.)
// so both type and type def can be used.

z::add(w);
u := z::divide(z,w); // creates a new one.

And what about displaying
 [z, w, u]
as a stem? Some form of to_string??

** Alternately, define a type of complex number inside a module and the module
has all of the operations in it. So
module['qdl:/complex'][
  type[complex][init(x,y)->;...];
  add(complex & z, complex &w)->...;
  ];
import('qdl:/complex', 'c')
z := new(complex)#init(2,-3);
c#add(z,z)

---------
9/28/21: Coordinates for stems
---------
We have absolute addressing for stems by index, [a,b,...]. Propose relative addressing
of the form

{origin., dim.}

so
  copy(arg., origin., target.)
//copies target. to arg. starting at origin. anmd preserving the shape of target.
  get(arg., origin., dim.)
// returns a stem of shape dim. starting at origin. in arg.

Question: How do a fill up a 3x5 array using a single element, a.4.4?
get(a., [4,4], [3,5]) would just start at the index [4,4] May have to
restrict the source? Last arg is resulting shape?
  get(a., [4,4], [1], [3,5])

Table of operations for absolute (A) and relative (R) addressing
δ. is a dimension vector
ω. is the origin of the operation.
Greek names of functions are because I have to figure out the right ones later.

╔═════════════╦═══════════════════════════════════════════╦════════════════════╗
║             ║          A                                ║     R              ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ get         ║ a.i.j                                     ║ γ(a.,ω.,δ.)        ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ set         ║ a.i.j := x                                ║ σ(a.,ω., b.)       ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ copy        ║ copy(b., start, leng, a., ndx)            ║     "              ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ insert      ║ insert(b., start, leng, a., ndx)          ║ ι(a.,ω., b.)       ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ excise      ║ remove(a.i.j)                             ║ ε(a.,ω.,δ.)        ║
╠═════════════╬═══════════════════════════════════════════╬════════════════════╣
║ create      ║ n(i,j,..., values.)                       ║      --            ║
╚═════════════╩═══════════════════════════════════════════╩════════════════════╝
    γ - result always has dimension δ.
    σ - all of b. is used.
 copy - no need since all of b. is used. copy adds in parameters for shape
    ι - can add axes
    ε - remove only operates on individual elements

E.g.
   a.
 0   1   2    3   4
 5   6   7    8   9
 10  11  12   13  14

   b.
p  q
r  s

   γ(a.,[1,1],[2,2]); // get 2x2 array at [1,1]
6  7
11 12

    σ(a.,[0,2], b.)
 0   1   p    q   4
 5   6   r    s   9
 10  11  12   13  14

    σ(a.,[2,4], b.)
 0   1   2    3   4
 5   6   7    8   9
 10  11  12   13  p  q
                  r  s

    ι(a.,[0,2], b.)
 0   1   p    q   2    3   4
 5   6   r    s   7    8   9
 10  11  12   13  14

   ι(a.,[0,0,0], b.); // laminates along new axis?
 0   1   2    3   4
 5   6   7    8   9
 10  11  12   13  14

 p  q
 r  s

    ι([;5],[0,0], 10+[;5]);
 0  1  2  3  4
 10 11 12 13 14

    ι([;5],[0,0], n(2,5,10 + [;10]);
 0  1  2  3  4
 10 11 12 13 14
 15 16 17 18 19

    ε(a.,[1,1],[2,2])
 0   1   2    3   4
 5   6            9
 10  11           14


 Compare  σ(a.,[0,2], b.) with
    a.[0,2] := b.
 0   1   b.   3   4
 5   6   7    8   9
 10  11  12   13  14

 ??? behavior for generic stems?
 z. := {'a':'p';'b':'q'}
 w. := {'a':'s','c':'t'}

   x. := ι(z., ['a'], w.)
{'a':[p,s]~{'b':'q'},'c':'t'}



4/8/2021
 ┌──┬──┐  ╔══╦══╗ ╒══╤══╕ ╓──╥──╖
 │  │  │  ║  ║  ║ │  │  │ ║  ║  ║
 ├──┼──┤  ╠══╬══╣ ╞══╪══╡ ╟──╫──╢
 │  │  │  ║  ║  ║ │  │  │ ║  ║  ║
 └──┴──┘  ╚══╩══╝ ╘══╧══╛ ╙──╨──╜
╔═══════╦══════════════╦══════════════════════════╦══════╦══════════════════════════════════════════════════════════════╗
║ NS    ║    name      ║          args            ║ conf ║  description                                                 ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║ list  ║ append       ║ arg., scalar             ║      ║  append a scalar to a list                                   ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ insert_at    ║ src.,start, len,         ║      ║  insert at the point, moving elements                        ║
║       ║              ║ target.,target_index     ║      ║                                                              ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ copy         ║   "     "                ║      ║  copy at the point, i.e., overwrite                          ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ reverse      ║ list.                    ║      ║  reverse elements                                            ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ subset       ║ arg,index[,len]          ║      ║  subset of a list starting at index to end or with len       ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║ stem  ║ box          ║ arg0,arg1,...            ║      ║  returns stem {'arg0':arg0,...} remove from symbols          ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ common_keys  ║ left., right.            ║      ║  common keys in stems                                        ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ dim          ║ arg.                     ║      ║  list of lengths of axes                                     ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ exclude_keys ║ arg., list.              ║      ║  exclude the keys in list.                                   ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ has_keys     ║ arg., list.              ║   R  ║  boolean list                                                ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ has_value    ║ left, right              ║   L  ║  Checks left arg values (keys ignored) in right arg.         ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ include_keys ║ arg., list.              ║  -   ║ returns only elements of arg. with keys in list.             ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ indices      ║ arg0,arg1,...            ║      ║  returns stem list with given shape                          ║
║       ║              ║  [,[values]]             ║      ║                                                              ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ is_list      ║ arg.                     ║  -   ║ boolean if arg. is exactly a list                            ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ join         ║ left., right.[, axis]    ║  -   ║ catenate the elements of left. and right. along the axis.    ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ keys         ║ arg.[,filter]            ║      ║ returns stem {key0:key0,key1:key1,...}                       ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ list_keys    ║ arg.[,filter]            ║      ║ returns list [key0,key1,...]                                 ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ mask         ║ left., right.            ║  L   ║                                                              ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ rank         ║ arg.                     ║      ║                                                              ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ remove       ║ var_name                 ║      ║ deletes var_name from symbol table                           ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║   "   ║ rename_keys  ║ arg., stem.              ║  L   ║ renames the keys in arg. as per stem.                        ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ set_default  ║ arg., scalar             ║   -  ║ returns arg.~{*:scalar}                                      ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ shuffle      ║ int | arg.[,list.]       ║      ║ randomly shuffles elements of arg. or reorders them          ║
║       ║              ║                          ║      ║ as per list.                                                 ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ size         ║   arg.                   ║      ║ number of elements                                           ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ to_list      ║  arg0,arg1,...           ║   -  ║ returns [arg0,arg1,...]                                      ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ trim         ║   arg.                   ║      ║ trims a stem of strings on 0th axis                          ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ unbox        ║   arg.                   ║      ║ turns stem into a set of variables.                          ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ union        ║  arg0.,arg1.,...         ║      ║ returns single stem of all keys. Overwrite possible          ║
╠═══════╬══════════════╬══════════════════════════╬══════╬══════════════════════════════════════════════════════════════╣
║  "    ║ unique       ║  list.                   ║      ║ returns the unique elements in a list.                       ║
╚═══════╩══════════════╩══════════════════════════╩══════╩══════════════════════════════════════════════════════════════╝
 This is the master list of things to do with stems and lists (aside from to/from JSON).

 * Deprecation list
 append
 set_default
 to_list
 union
 Maybe vencode encode_b64, to_hex, to_json  replace with
 encode(type, arg)
 decode(type, arg)
 Support: hex, base 64, base 32 (new), json, variable
 Could get rid of 10 functions and make it more extensible.





