TryAPL: Difference between revisions

Jump to navigation Jump to search
117 bytes added ,  10:30, 11 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 26: Line 26:
Creating a [[wikipedia:bookmarklet|bookmarklet]] with the following URL, will enable clicking on the bookmark to pop up a box wherein one can enter an APL expression, which will then be executed, and the result shown in another pop-up:
Creating a [[wikipedia:bookmarklet|bookmarklet]] with the following URL, will enable clicking on the bookmark to pop up a box wherein one can enter an APL expression, which will then be executed, and the result shown in another pop-up:
<source lang=js>
<source lang=js>
javascript:((()=>{with(new XMLHttpRequest){open(`POST`,`https://tryapl.org/Exec`);setRequestHeader(`Content-Type`,`application/json;charset=utf-8`);send(JSON.stringify([0,0,0,prompt()]));onload=(_=>alert(eval(responseText)[3].join`\n`+`\n`))}})())</source>
javascript:((()=>{with(new XMLHttpRequest){open(`POST`,`https://tryapl.org/Exec`);setRequestHeader(`Content-Type`,`application/json;charset=utf-8`);send(JSON.stringify([0,0,0,prompt()]));onload=(_=>alert(eval(responseText)[3].join`\n`+`\n`))}})())</syntaxhighlight>


=== Chat box exec ===
=== Chat box exec ===
Line 32: Line 32:


=== Chatbot ===
=== Chatbot ===
[[wikipedia:Stack Exchange|Stack Exchange]] moderator "hyper-neutrino" hosts a [[wikipedia:chatbot|chatbot]] using TryAPL's name and icon, active in two Stack Exchange chat rooms; the [[APL Orchard]] and the Stack Exchange's [[sandbox (software_development)|sandbox]] chat room. To use it, write [[APL Orchard#inline|inline code]] or a [[APL Orchard#Multi-line messages|multi-line code block]], and prepend <source lang=apl inline>⎕←</source> or <source lang=apl inline>⋄</source> to lines you wish to run, in any of the two chat rooms:<ref>For details, see [https://codegolf.stackexchange.com/users/75949 the chat bot's profile].</ref>
[[wikipedia:Stack Exchange|Stack Exchange]] moderator "hyper-neutrino" hosts a [[wikipedia:chatbot|chatbot]] using TryAPL's name and icon, active in two Stack Exchange chat rooms; the [[APL Orchard]] and the Stack Exchange's [[sandbox (software_development)|sandbox]] chat room. To use it, write [[APL Orchard#inline|inline code]] or a [[APL Orchard#Multi-line messages|multi-line code block]], and prepend <source lang=apl inline>⎕←</syntaxhighlight> or <source lang=apl inline>⋄</syntaxhighlight> to lines you wish to run, in any of the two chat rooms:<ref>For details, see [https://codegolf.stackexchange.com/users/75949 the chat bot's profile].</ref>


* [https://apl.chat APL Orchard]
* [https://apl.chat APL Orchard]
Line 46: Line 46:
=== API ===
=== API ===


Requests to TryAPL's backend consist of submitting a [[wikipedia:POST (HTTP)|POST]] request to https://tryapl.org/Exec containing a 4-element list <source lang=js inline>["state", size, "hash", "input"]</source> where the first three elements can use the placeholder values <source lang=js inline>""</source> or <source lang=js inline>0</source>. The server responds with a similar 4-element list <source lang=js inline>["state", size, "hash", ["lines", "of", "output"]]</source>. The first three elements are kept on the front-end and sent back with the next request, or cleared to restart with default state.
Requests to TryAPL's backend consist of submitting a [[wikipedia:POST (HTTP)|POST]] request to https://tryapl.org/Exec containing a 4-element list <source lang=js inline>["state", size, "hash", "input"]</syntaxhighlight> where the first three elements can use the placeholder values <source lang=js inline>""</syntaxhighlight> or <source lang=js inline>0</syntaxhighlight>. The server responds with a similar 4-element list <source lang=js inline>["state", size, "hash", ["lines", "of", "output"]]</syntaxhighlight>. The first three elements are kept on the front-end and sent back with the next request, or cleared to restart with default state.


If the output begins with a backspace character (U+08) then the actual output only begins after the second backspace character, and the text between the two backspace characters describes the role of the text. As 27 Jun 2021, only one tag has been implemented, <source lang=js inline>"\bhelp\b"</source> for which the text is the URL of help page requested by <source lang=apl inline>]Help</source>
If the output begins with a backspace character (U+08) then the actual output only begins after the second backspace character, and the text between the two backspace characters describes the role of the text. As 27 Jun 2021, only one tag has been implemented, <source lang=js inline>"\bhelp\b"</syntaxhighlight> for which the text is the URL of help page requested by <source lang=apl inline>]Help</syntaxhighlight>


==== XMLHttpRequest ====
==== XMLHttpRequest ====
Line 59: Line 59:
onload = (_ => alert(eval(responseText)[3].join("\n") + "\n"))
onload = (_ => alert(eval(responseText)[3].join("\n") + "\n"))
}
}
</source>
</syntaxhighlight>
==== Fetch ====
==== Fetch ====
This is a function that uses the [[wikipedia:XMLHttpRequest#Fetch_alternative|Fetch]] API to send a request given as input a string code:
This is a function that uses the [[wikipedia:XMLHttpRequest#Fetch_alternative|Fetch]] API to send a request given as input a string code:
Line 82: Line 82:
   console.log(sumReduce);
   console.log(sumReduce);
})();
})();
</source>
</syntaxhighlight>


If you want to load a namespace containing some functions, you have to change state, size and hash variables. To have these parameters just go on https://tryapl.org/ [Developer Tools > Network]. Here, after typing on TryAPL <source lang="js" inline>increment ← 1∘+</source>, will appear a file named Exec: in the Response tab there will be a JSON containing the three values.
If you want to load a namespace containing some functions, you have to change state, size and hash variables. To have these parameters just go on https://tryapl.org/ [Developer Tools > Network]. Here, after typing on TryAPL <source lang="js" inline>increment ← 1∘+</syntaxhighlight>, will appear a file named Exec: in the Response tab there will be a JSON containing the three values.


<source lang="js">
<source lang="js">
Line 105: Line 105:
   console.log(result);
   console.log(result);
})();
})();
</source>
</syntaxhighlight>


== In media ==
== In media ==

Navigation menu