Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utnut!cs.utexas.edu!wupost!decwrl!decwrl!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Implementation of forks in C
Message-ID: <1993May28.040559.24278@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
Date: Fri, 28 May 1993 04:05:59 GMT
Lines: 84

 How are forks implemented in the source?

  For example,

  z=(A)divide(df1(y,slash(ds(CPLUS))),tally(y)); R(z);

is a translation of the statement (+/ % #) ,

but could this be implemented as a fork? Something like :

   z=(A)folk(y,slash(ds(CPLUS)),divide,tally); 

Or is the result of folk a verb?, if so how do I create a
verb using slash, divide, and tally?, and can verbs be
tacitly defined in the source?

Attached is a LinkJ hack and a sample session.

Notice that translating code from J to C (but using
the J functions in the source) does not guarantee
improved performance. BTW , the timesharing
nature of this system accounts for the variablity
of performance times.

#include <stdio.h>
#include <string.h>
#include "lj.h"
#include <math.h>
#include "jc.h"

static F1(test){A z,t,a,b,c;
  /* z=(A)folk(y,slash(ds(CPLUS)),divide,tally); */
  z=(A)divide(df1(y,slash(ds(CPLUS))),tally(y)); R(z);
 }

C jc(k,f1,f2)I k;AF*f1,*f2;
{ switch(k){
  case 0:
   *f1=test;
   *f2=NULL;
   R 1;
  default:
   ASSERT(0,EVNONCE);       
  }
}

main()
{A t;C s[456];
 jinit();
 while(1)
 {
  printf("   ");
  if(NULL==gets(s)||'\004'==*(s+strlen(s)-1))exit(0);
  t=jx(s);
  if(jerr)printf("jerr: %d\n",jerr); else if(!asgn)jpr(t);
 }
}

$ 
$ /usr/s3/emclean/j/src/j
   0!:2 <'send1'
test =. 6!:2,7!:2@]
avfork =. +/ % #
avhack =. 10!:0
b =. i. 10000
avhack b
4999.5
avfork b
4999.5
(50) test 'avfork b'
0.0712 80452
(50) test 'avhack b'
0.0868 80540
(50) test 'avfork b'
0.071 80452
(50) test 'avhack b'
0.0742 80540
(50) test 'avfork b'
0.0752 80452
(50) test 'avhack b'
0.0868 80540


   
