Don't need assert each, because assert by itself should work just fine.

   assert 1 1 0 1
|assertion failure: assert

Though in a different sort of general case you might need each, rank or a ravel:

   assert 5~:i.3 3

vs.

   assert, 5~:i.3 3
|assertion failure: assert

Thanks,

-- 
Raul

On Fri, Nov 13, 2015 at 3:51 PM, 'Pascal Jasmin' via Programming
<programm...@jsoftware.com> wrote:
> This is some awesome witchcraft,
>
>
> func=: 3 : 0
> doc=.[(y,'_doc')=: 0 : 0
> lines=.LF cut doc
> 0!:0 > {: lines
> examples=.[(y,'_examples')=:3 }. each (#~ (<'ex:') E. 3 {. each [) lines
> assert each ". each examples
> ''
> )
>
> This is the witchcraft line
>
> doc=.[(y,'_doc')=: 0 : 0
>
> it reuses the function's own closing )
>
> A modifier version... there is line wrap.  A blank line precedes and succeeds 
> wrap points
>
> lrA =: 1 : '5!:5 < ''u'''
> strbracket =: 0&{@:[ , ] , 1&{@:[
>
> func2=: 2 : 0
> doc=.[(n,'_doc')=: 0 : 0
> lines=.LF cut doc
>
> examples=.[(n,'_examples')=: [:`[:`(;L:1@(([, <@:(' -: (' , (u lrA) , 
> ')'"_),])/ each))`(;L:1@((([, <@:(' -: '"_),])`([, <@:('(' , (u lrA) , 
> ')'"_),])/) each) )@.(# every) '()' strbracket leaf ([: }. ';'&cut)each  (#~ 
> (<'ex;') E. 3 {. each [) lines
>
>
> NB. assert each ". each examples
> (n) =: u
> assert each ". each examples
> )
>
> +/ func2 'asdf'
> Documentation header for sum
> ex; 6 ; 1 2 3
> ex; 3 2$4 5 2 3 2 3     ; 3 1 1 ; 1 2
> function def was conj u parameter. name is n.
> )
>
> asdf_examples
> ┌────────────────────┬──────────────────────────────────────┐
> │(6 ) -: (+/)( 1 2 3)│(3 2$4 5 2 3 2 3) -: (3 1 1)(+/)( 1 2)│
> └────────────────────┴──────────────────────────────────────┘
>
>
>
>
> ----- Original Message -----
> From: Joe Bogner <joebog...@gmail.com>
> To: programm...@jsoftware.com
> Cc:
> Sent: Friday, November 13, 2015 12:24 PM
> Subject: Re: [Jprogramming] essay: toy byte code interpreter
>
> 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
> ----------------------------------------------------------------------
> 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