Thanks, good trick. I was looking for something like that (had escaped me even though I'm sure I've seen it before).
by the way, I meant to include this in my previous email that I was particularly satisfied to be able to write the whole program without resorting to 13 : 0 once (even in the repl) I didn't intentionally avoid it, I just was comfortable enough not to reach for it. In my first 3 months of J a few years ago, I don't think I could barely have written a tacit expression without it. I'll have to remind newcomers that the pain of tacit is temporary! On Thu, Nov 12, 2015 at 8:29 PM, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: > just a tweak to compile it to a verb, > > eval =:1 : ' a: 1 : m' > > run =: (; <;._2 (0 : 0)) 1 : ' a: 1 : m' > (0&{ , >:@:(1 {:: ]) ; 2&}.)@:(((1 {:: ]) { [) ((0 > {:: ]) ; (1 {:: ]) ; {.@:(3 {:: ]) ; }.@:(3 {:: ] > ))`((0 {:: ]) ; (1 {:: ]) ; '' ; <@:((0 { [) , 3 { > :: ]))`]`(+/@:}.@:[ ((0 {:: ]) ; (1 {:: ]) ; '' ; > <@:((0 { [) , 3 {:: ])) ])`([: (([: *@-~/ 2&({::)) > ((0 {:: ]) ; (1 {:: ]) ; '' ; <@:((0 { [) , 3 {:: > ])) ]) [: ([ ((0 {:: ]) ; (1 {:: ]) ; ((2 {:: ]) > , 2 {:: [) ; 3 {:: ]) (0 {:: ]) ; (1 {:: ]) ; {.@: > (3 {:: ]) ; }.@:(3 {:: ]))^:2 ])`((0 {:: ]) ; _ ; > '' ; 3 {:: ])`]`]`([ (<@:(2&{."1@:(0 {:: ]) i. 6 , > 1 {:: [) 1} ])^:(1 = 2 {:: ]) (0 {:: ]) ; (1 {:: > ]) ; {.@:(3 {:: ]) ; }.@:(3 {:: ]))`(([: (0 0 $ 1! > :2&2)@({"_)&(<;._1 '|exiting|greater than') 1&({:: > )@:[) ] ])@.(0 {:: [) ])^:(1 = (1 {:: ]) < <:@:#@: > [)^:_ (] ;&(0;'';'')) > ) > > > > run (3 6 5),(0 0 0),:(9 0 0) > > maybe this is useful > > result =: 2 {:: run@,&(,: 9 0 0) > > result (3 6 5),: (0 0 0) > 11 > > ----- Original Message ----- > From: Joe Bogner <joebog...@gmail.com> > To: programm...@jsoftware.com > Cc: > Sent: Thursday, November 12, 2015 3:59 PM > Subject: Re: [Jprogramming] essay: toy byte code interpreter > > I've added a pure functional tacit version: > http://code.jsoftware.com/wiki/User:Joe_Bogner/ByteCodeInterpreter#Tacit_Version > > Here's a silly proof: > > NB. wrapped at 50 characters so line fees shouldn't cause issues > > run =: (; <;._2 (0 : 0)) eval > (0&{ , >:@:(1 {:: ]) ; 2&}.)@:(((1 {:: ]) { [) ((0 > {:: ]) ; (1 {:: ]) ; {.@:(3 {:: ]) ; }.@:(3 {:: ] > ))`((0 {:: ]) ; (1 {:: ]) ; '' ; <@:((0 { [) , 3 { > :: ]))`]`(+/@:}.@:[ ((0 {:: ]) ; (1 {:: ]) ; '' ; > <@:((0 { [) , 3 {:: ])) ])`([: (([: *@-~/ 2&({::)) > ((0 {:: ]) ; (1 {:: ]) ; '' ; <@:((0 { [) , 3 {:: > ])) ]) [: ([ ((0 {:: ]) ; (1 {:: ]) ; ((2 {:: ]) > , 2 {:: [) ; 3 {:: ]) (0 {:: ]) ; (1 {:: ]) ; {.@: > (3 {:: ]) ; }.@:(3 {:: ]))^:2 ])`((0 {:: ]) ; _ ; > '' ; 3 {:: ])`]`]`([ (<@:(2&{."1@:(0 {:: ]) i. 6 , > 1 {:: [) 1} ])^:(1 = 2 {:: ]) (0 {:: ]) ; (1 {:: > ]) ; {.@:(3 {:: ]) ; }.@:(3 {:: ]))`(([: (0 0 $ 1! > :2&2)@({"_)&(<;._1 '|exiting|greater than') 1&({:: > )@:[) ] ])@.(0 {:: [) ])^:(1 = (1 {:: ]) < <:@:#@: > [)^:_ (] ;&(0;'';'')) > ) > > > > This program will add 6 and 5 together, pop the result into the > current value register and then exit > > (; run) (128!:2) (3 6 5),(0 0 0),:(9 0 0) > > > The resulting frame is the program, instruction pointer, current > value, and stack (empty) > > > +-----+-+--++ > |3 6 5|2|11|| > |0 0 0| | || > |9 0 0| | || > +-----+-+--++ > > > Further demonstration of the power of J's tacit engine. A toy > interpreter like this shows we can write code in an explicit > mini-language and have it run tacitly. I'm not sure of practical uses > and I'm not advocating using this for anything serious. J's tacit > engine acts as a virtual machine for the byte code. > > On Tue, Nov 10, 2015 at 4:57 PM, 'Pascal Jasmin' via Programming > <programm...@jsoftware.com> wrote: >> J is arguably already bytecode... ascii. And fairly terse. >> >> an extension to this: >> http://code.jsoftware.com/wiki/User:PascalJasmin/JON_assignment_free_pure_functional_DSL >> >> would be to use instead of an assignment system, an object that is a >> combination of queue, stack and dictionary that stores and retrieves results. >> >> >> >> >> ----- Original Message ----- >> From: Joe Bogner <joebog...@gmail.com> >> To: programm...@jsoftware.com >> Cc: >> Sent: Tuesday, November 10, 2015 4:49 PM >> Subject: Re: [Jprogramming] essay: toy byte code interpreter >> >> Thanks. I don't have any application of it yet other than demystifying >> the concept of a bytecode interpretation. It does open up some >> interesting options of doing cool stuff with stacks in J. >> >> I am also thinking it would be a neat hack to implement a subset of J >> in J using interpreted bytecode. I would then probably write an >> interpreter of the bytecode in another language too for fun. >> >> >> >> >> >> On Tue, Nov 10, 2015 at 4:33 PM, 'Pascal Jasmin' via Programming >> <programm...@jsoftware.com> wrote: >>> Its cool. >>> >>> is your interest to do cool stuff with stacks in J, make a stack language >>> or interpret bytecode? >>> >>> >>> If its the first, I have many suggestions. >>> >>> >>> ________________________________ >>> From: Joe Bogner <joebog...@gmail.com> >>> To: programm...@jsoftware.com >>> Sent: Tuesday, November 10, 2015 4:07 PM >>> Subject: [Jprogramming] essay: toy byte code interpreter >>> >>> >>> I wrote this over lunch today and was pleased to see how simple it >>> was. I'm posting here for those who don't follow Recent Changes. >>> Feedback welcome >>> >>> http://code.jsoftware.com/wiki/User:Joe_Bogner/ByteCodeInterpreter >>> >>> I'd be interested in any speedups to the timing test that still permit >>> jumps. It's fine as-is for a toy though >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm > >> >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm