Execute Brain****/J: Difference between revisions

m
Fixed syntax highlighting.
m (update for j804)
m (Fixed syntax highlighting.)
 
Line 1:
<langsyntaxhighlight Jlang="j">require'general/misc/prompt' NB. was require'misc' in j602
 
NB. operations
Line 63:
run=: [: flush step^:(pc < #@[)^:_
 
execute=: 2 }. compile@] run 0 0,0: :[</langsyntaxhighlight>
 
Here is hello world:
 
<langsyntaxhighlight Jlang="j">hello=: 0 :0
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
Line 89:
> + . print '!'
> . print '\n'
)</langsyntaxhighlight>
 
Example use:
<langsyntaxhighlight Jlang="j"> execute hello
Hello World!
 
0 87 100 33 10</langsyntaxhighlight>
 
execute compiles the program, generates an initial state of a blank tape with the data and instruction pointers both being zero, runs the program and then returns as its result the final state of the tape.
Line 103:
Or, here is the addDigit program from wikipedia, with explicit compilation and run as separate operations:
 
<langsyntaxhighlight Jlang="j"> (compile ',>++++++[<-------->-],[<+>-]<.') run 0 0
 
23
5
0 30 53 0</langsyntaxhighlight>
 
Here, 2 and 3 were provided as input, and 5 was displayed as the result.
Line 119:
When investigating a bug, you can use:
 
<langsyntaxhighlight Jlang="j">next=: (1 + 1 { ])`1:`]} ([ smoutput)</langsyntaxhighlight>
 
This means that programs when run (or traced) will display each tape state after it has been generated, which means that when the program crashes you will have displayed a tape state shortly before the crash.
9,482

edits