On Mar 5, 2021, at 12:24 PM, John Cowan
<cowan(a)ccil.org> wrote:
On Fri, Mar 5, 2021 at 9:14 AM Steffen Nurpmeso <steffen(a)sdaoden.eu
<mailto:steffen@sdaoden.eu>> wrote:
But, not important. A real change to my coding style came when
i looked around Plan9 source code, the pragmatism to simply not
use spaces in language constructs aka statements at all, for
example "if(a){" instead of "if(a) {" or "if (a) {", and
let alone
"if (a)\nALIGN{\nALIGN" and whatever else.
That way lies APL madness. To exemplify, Kona is an open-source interpreter for Arthur
Whitney's K version 3 language, which is closely related to APL, but crams almost all
of the APL operators onto single ASCII characters with massive overloading. For example,
monadic ! is APL "iota", but dyadic ! is "modulo" if both arguments
are numbers and "rotate" if the right argument is a number and the left argument
is a vector. What any of these has to do with the rest is beyond me: I had to create a
set of flash cards to help me learn them all.
Not sure what this has to do with tabs but note that APL itself did a lot of punning in
that unary and binary functions of the same name were related. K does something similar
but perhaps not as consistently.
Well, here's a procedure definition from the Kona
source, in a file helpfully named kc.c (almost all of the source files have 1-2 character
names):
People should perhaps look at Whitney's original C code[1] that started all this (see
below).
I can no longer compile this but it is worth studying. This was the genesis of both K
& J languages. There is method to Whitney's madness but it takes a while to grok
his style. Given that he has produced 6 or so versions of K, a specialized C compiler, as
well as an OS prototype (kOS), clearly it has worked extremely well for him! Whiney once
explained "It is a lot easier to find your errors in four lines of code than in four
hundred." [2] Though his style is not for most people!
typedef char C;typedef long I;
typedef struct a{I t,r,d[3],p[2];}*A;
#define P printf
#define R return
#define V1(f) A f(w)A w;
#define V2(f) A f(a,w)A a,w;
#define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}}
I *ma(n){R(I*)malloc(n*4);}mv(d,s,n)I *d,*s;{DO(n,d[i]=s[i]);}
tr(r,d)I *d;{I z=1;DO(r,z=z*d[i]);R z;}
A ga(t,r,d)I *d;{A z=(A)ma(5+tr(r,d));z->t=t,z->r=r,mv(z->d,d,r);
R z;}
V1(iota){I n=*w->p;A z=ga(0,1,&n);DO(n,z->p[i]=i);R z;}
V2(plus){I r=w->r,*d=w->d,n=tr(r,d);A z=ga(0,r,d);
DO(n,z->p[i]=a->p[i]+w->p[i]);R z;}
V2(from){I r=w->r-1,*d=w->d+1,n=tr(r,d);
A z=ga(w->t,r,d);mv(z->p,w->p+(n**a->p),n);R z;}
V1(box){A z=ga(1,0,0);*z->p=(I)w;R z;}
V2(cat){I an=tr(a->r,a->d),wn=tr(w->r,w->d),n=an+wn;
A z=ga(w->t,1,&n);mv(z->p,a->p,an);mv(z->p+an,w->p,wn);R z;}
V2(find){}
V2(rsh){I r=a->r?*a->d:1,n=tr(r,a->p),wn=tr(w->r,w->d);
A z=ga(w->t,r,a->p);mv(z->p,w->p,wn=n>wn?wn:n);
if(n-=wn)mv(z->p+wn,z->p,n);R z;}
V1(sha){A z=ga(0,1,&w->r);mv(z->p,w->d,w->r);R z;}
V1(id){R w;}V1(size){A z=ga(0,0,0);*z->p=w->r?*w->d:1;R z;}
pi(i){P("%d ",i);}nl(){P("\n");}
pr(w)A w;{I r=w->r,*d=w->d,n=tr(r,d);DO(r,pi(d[i]));nl();
if(w->t)DO(n,P("< ");pr(w->p[i]))else DO(n,pi(w->p[i]));nl();}
C vt[]="+{~<#,";
A(*vd[])()={0,plus,from,find,0,rsh,cat},
(*vm[])()={0,id,size,iota,box,sha,0};
I st[26]; qp(a){R a>='a'&&a<='z';}qv(a){R
a<'a';}
A ex(e)I *e;{I a=*e;
if(qp(a)){if(e[1]=='=')R st[a-'a']=ex(e+2);a= st[ a-'a'];}
R qv(a)?(*vm[a])(ex(e+1)):e[1]?(*vd[e[1]])(a,ex(e+2)):(A)a;}
noun(c){A z;if(c<'0'||c>'9')R
0;z=ga(0,0,0);*z->p=c-'0';R z;}
verb(c){I i=0;for(;vt[i];)if(vt[i++]==c)R i;R 0;}
I *wd(s)C *s;{I a,n=strlen(s),*e=ma(n+1);C c;
DO(n,e[i]=(a=noun(c=s[i]))?a:(a=verb(c))?a:c);e[n]=0;R e;}
main(){C s[99];while(gets(s))pr(ex(wd(s)));}
[1]
https://code.jsoftware.com/wiki/Essays/Incunabulum
One summer weekend in 1989, Arthur Whitney visited Ken Iverson at Kiln Farm and
produced—on one page and in one afternoon—an interpreter fragment on the AT&T 3B1
computer. I (Roger Hui) studied this interpreter for about a week for its organization and
programming style; and on Sunday, August 27, 1989, at about four o'clock in the
afternoon, wrote the first line of code that became the implementation described in this
document.
[2]
http://archive.vector.org.uk/art10501320