Apple3.14/implementation.ijs

This is an implementation of Apple3.14 in J, written by User:Conor O'Brien.

Assumptions
I assume the following, since detail is to be desired on the actual spec.


 * 1) All programs must start with   in that case exactly, followed by an optional carriage return  and a necessary newline ;
 * 2) all programs must end with the   command, and that any amount of text may come after it, but will not be executed;
 * 3) all lines not starting with   followed by a space are ignored;
 * 4) any invalid number passed to a   command causes an error;
 * 5) negative numbers passed to a   command print an newline;
 * 6) and that multiple  s are allowed.

Apple314.ijs
Without further ado, this is the program, :

getpi =: '3'"_`('3.',[:":10#.[:([:-/1 10*[:<.@o.10x^1 0+])"0 i.)@.* isn  =: [:<./'0123456789'e.~] throw =: (5)1!:2&5,&LF 3 : 0]1!:1(3)   NB. split on newlines and remove carriage returns   lines =. <;._1 LF, y -. CR   if. -. 'apple3.14' -: > {. lines do. throw 'error: first line is not "apple3.14"' end.   NB. remove first line   lines =. }. lines   for_line. lines do.     if. 'end' -: >line do. return.     elseif. 'goto' -: > 0 { wln =. ;: >line do.       num =. >1 { wln       if.     isn num                       do. echo getpi ". num elseif. ('-' -: {. num) *. isn }. num do. echo '&#39; elseif. 1                            do. throw 'error: malformed number "', num , '"' end. end. end. ) exit 0

Running the program
You can execute programs like this:

On windows:

type | Apple314.ijs

On bash/related:

cat | Apple314.ijs

Further notes
This program currently does not display the entirety of sufficiently long strings. However, this is currently being worked on.