Good reads. Each time I read them I pick up more.

I've gone ahead and rewrote the tacit code in a literate, tdd style:

http://code.jsoftware.com/wiki/User:Joe_Bogner/ByteCodeInterpreter#Tacit_Literate.2C_TDD_Version


The code is significantly longer, but the actual fixed representation
is slightly smaller. I think this style showcases some of what I love
about J - tight implementations, ability to mix code with data, and
testability/interactive nature.

We can question the value of some of the comments (probably better for
chat), but I'll throw it out here too.

Such as:

func 'op_jge'
    pops value from stack.
       if value is >= 0, sets instruction pointer to the label.
       otherwise continues

    x: bytecode where (op,param1,param2) and param2 indicates label to jump to
    y: bytecodeStruct

    (_,_,_) is a placeholder since the true x value is supplied and
not looked up


    no change test (ip remains 0 since _1 is top of stack):
    ex: 0 -: getIP (JGE,100,0) op_jge _1 op_push
((_,_,_),(LABEL,100,0),:(EXIT,0,0)) setCODE 0 setIP testStruct

    greater than jump (ip goes to 1 since 1 is top of stack and 1 is
the label position):
    ex: 1 -: getIP (JGE,100,0) op_jge 1 op_push
((_,_,_),(LABEL,100,0),:(EXIT,0,0)) setCODE 0 setIP testStruct

    another jump (move label to the end)
    ex: 2 -: getIP (JGE,100,0) op_jge 1 op_push
((_,_,_),(EXIT,0,0),:(LABEL,100,0)) setCODE 0 setIP testStruct

    jump but label is not found
    ex: 3 -: getIP (JGE,999,0) op_jge 1 op_push
((_,_,_),(EXIT,0,0),:(LABEL,100,0)) setCODE 0 setIP testStruct

    test equals (this is not yet implemented)
    ex: 2 -: getIP (JGE,100,0) op_jge 0 op_push
((_,_,_),(EXIT,0,0),:(LABEL,100,0)) setCODE 0 setIP testStruct

    op_jge =:  (findLabel setIP ])^:(0<:getVAL) op_pop
)

I suppose this whole block could be represented in another language in
a similar number of lines if we used the idea of that code is
documentation.

You can imagine an implementation like this:

function op_ge(world) {
   var val = pop(world);
   if (val >= 0) {
      return setIP(world, findLabel(world))
  }
  return world;
}

I think I'd rather read the J version since it's tested/testable and I
don't think pseudo-javascript version is nearly as clear.





On Thu, Nov 12, 2015 at 9:23 PM, 'Pascal Jasmin' via Programming
<programm...@jsoftware.com> wrote:
>
>
>
>
>
>>If someone has a dictionary or other doc reference handy that explains
> this I would be grateful to deepen my understanding, although it seems
> pretty straightforward
>
>
>
> http://code.jsoftware.com/wiki/User:Pascal_Jasmin/3_types_of_adverbs_conjunctions_and_binding
>
> and
>
>
> http://code.jsoftware.com/wiki/User:Pascal_Jasmin/modifiers_in_locales
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to