TryAPL: Difference between revisions

Jump to navigation Jump to search
6,073 bytes added ,  10:33, 11 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
mNo edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[File:TryAPL logo.png|frame|right|TryAPL's logo.]]
[[File:TryAPL logo.png|thumb|right|TryAPL's logo.]]
'''TryAPL''' is online service that allows trying out a subset of [[Dyalog APL]]. The back-end is a [https://github.com/Dyalog/Jarvis Jarvis] server that uses [[Adám Brudzewsky]]'s [https://github.com/abrudz/dyalog-safe-exec Safe Execute] to provide [[wikipedia:sandbox (computer_security)|sandbox]]ing.
 
'''TryAPL''' is online service that allows trying out a subset of [[Dyalog APL]]. The back-end is a [https://github.com/Dyalog/Jarvis Jarvis] server that uses [[Adám Brudzewsky]]'s [https://github.com/abrudz/dyalog-safe-exec Safe Execute] to provide [[wikipedia:sandbox (computer_security)|sandbox]]ing. The source code for TryAPL was released under the [[wikipedia:MIT License|MIT License]] on 15 July 2021.<ref>[[Dyalog Ltd.]] [https://github.com/Dyalog/TryAPL TryAPL]. GitHub.</ref>


== Interfaces ==
== Interfaces ==
Since version 3.0, TryAPL's [[wikipedia:front end and back end|front end and back end]] are completely separate, with a very simple API, and no [[wikipedia:server-side|server-side]] state. This has enabled the [[community]] to develop their own interfaces to the back-end.
Since version 3.0, TryAPL's [[wikipedia:front end and back end|front end and back end]] are completely separate, with a very simple [[#API|API]], and no [[wikipedia:server-side|server-side]] state. This has enabled the [[community]] to develop their own interfaces to the back-end.


=== TryAPL.org ===
=== TryAPL.org ===
[https://tryapl.org TryAPL.org] is the original and main web interface for the back-end:
[https://tryapl.org TryAPL.org] is the original and main web interface for the back-end:
[[File:TryAPL|center|thumb|TryAPL's web inferface]]
[[File:TryAPL|center|thumb|TryAPL's web inferface]]
The source code is available [https://github.com/razetime/APLgolf/ on Github].


=== TryAPL Mini ===
=== TryAPL Mini ===
[https://janiczek.github.io/tryapl-elm/ TryAPL Mini] is an alternative web interface written in [[wikipedia:Elm (programming language)|Elm]], focusing on exploration of [[primitive]]s. Half of the screen is used to display information about whichever [[glyph]] the user last hovered their mouse over on the built-in [[Typing_glyphs#Web|language bar]].
[https://janiczek.github.io/tryapl-elm/ TryAPL Mini] is an alternative web interface written in [[wikipedia:Elm (programming language)|Elm]], focusing on exploration of [[primitive]]s. Half of the screen is used to display information about whichever [[glyph]] the user last hovered their mouse over on the built-in [[Typing_glyphs#Web|language bar]].
The source code is available [https://github.com/janiczek/tryapl-elm/ on GitHub].


=== APLgolf ===
=== APLgolf ===
[https://razetime.github.io/APLgolf/ APLgolf] is a website that assists in composing answers for [[code golf|Code Golf]] [[wikipedia:Stack Exchange|Stack Exchange]].
[https://razetime.github.io/APLgolf/ APLgolf] is a website that assists in composing answers for [[code golf|Code Golf]] [[wikipedia:Stack Exchange|Stack Exchange]].
The source code is available [https://github.com/razetime/APLgolf/ on GitHub].
=== Bookmarklet ===
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:
<syntaxhighlight 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`))}})())</syntaxhighlight>


=== Chat box exec ===
=== Chat box exec ===
Line 19: 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 <syntaxhighlight lang=apl inline>⎕←</syntaxhighlight> or <syntaxhighlight 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]
* [https://chat.stackexchange.com/rooms/1/sandbox Sandbox]
* [https://chat.stackexchange.com/rooms/1/sandbox Sandbox]
The source code is available [https://github.com/hyper-neutrino/apl-bot on GitHub].


=== Twitter bot ===
=== Twitter bot ===
[https://twitter.com/tryaplbot TryAPL Bot] is a [[wikipedia:Twitter bot|Twitter bot]] run by Rodrigo Girão Serrão using TryAPL icon. It responds to [[wikipedia:Twitter#Tweets|tweets]] that [[wikipedia:mention (blogging)|mention]] it. To use it, post a tweet that contains the bot's handle (<code>@tryaplbot</code>) and code in backticks, for example <code>`⍳3`</code>. Multiple such code sections can be included in a single message, and assignments made in earlier ones are preserved for the later ones. Since tweets do not support any type of formatting, the bot responds with an image of an APL [[session]] where the requested code has been entered, and the result is shown. It also includes a link to try the expression on [[#TryAPL.org|TryAPL.org]] and if the result is a single line that can fit in the tweet, it is included there too.
[https://twitter.com/tryaplbot TryAPL Bot] is a [[wikipedia:Twitter bot|Twitter bot]] run by Rodrigo Girão Serrão using TryAPL icon. It responds to [[wikipedia:Twitter#Tweets|tweets]] that [[wikipedia:mention (blogging)|mention]] it. To use it, post a tweet that contains the bot's handle (<code>@tryaplbot</code>) and code in backticks, for example <code>`⍳3`</code>. Multiple such code sections can be included in a single message, and assignments made in earlier ones are preserved for the later ones. Since tweets do not support any type of formatting, the bot responds with an image of an APL [[session]] where the requested code has been entered, and the result is shown. It also includes a link to try the expression on [[#TryAPL.org|TryAPL.org]] and if the result is a single line that can fit in the tweet, it is included there too.
The source code is available [https://github.com/RojerGS/TryAPL-Bot on GitHub].
=== 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 <syntaxhighlight lang=js inline>["state", size, "hash", "input"]</syntaxhighlight> where the first three elements can use the placeholder values <syntaxhighlight lang=js inline>""</syntaxhighlight> or <syntaxhighlight lang=js inline>0</syntaxhighlight>. The server responds with a similar 4-element list <syntaxhighlight 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, <syntaxhighlight lang=js inline>"\bhelp\b"</syntaxhighlight> for which the text is the URL of help page requested by <syntaxhighlight lang=apl inline>]Help</syntaxhighlight>
==== XMLHttpRequest ====
A minimal (no-state) TryAPL front-end can be implemented as follows using the [[wikipedia:XMLHttpRequest|XMLHttpRequest]] API:
<syntaxhighlight lang=js>
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>
==== Fetch ====
This is a function that uses the [[wikipedia:XMLHttpRequest#Fetch_alternative|Fetch]] API to send a request given as input a string code:
<syntaxhighlight lang=js>
async function executeAPL(code) {
  const res = await fetch("https://tryapl.org/Exec", {
    method: 'POST',
    headers: { 'Content-Type': 'application/json; charset=utf-8' },
    body: JSON.stringify(['', 0, '', code]),
  });
  const data = await res.json(); // data contains the server response
  return data[3]; // return the output of the function
}
// To call the function you must use an async/await statement.
(async () => {
  let resultSum = await executeAPL(`2+2`);
  let reshape = (await executeAPL(`2 2⍴⍳${resultSum}`))
    .map(row => row.split` `.map(x => +x));
  let sumReduce = (await executeAPL(`+/ (↑⍣≡0∘⎕JSON) '${JSON.stringify(reshape)}'`))
    .map(row => row.split` `.map(x => +x));
  console.log(sumReduce);
})();
</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 <syntaxhighlight 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.
<syntaxhighlight lang="js">
let state = 'c-ocK2UHbD6oBCo<$(l+5DX+5l%hycQBgoav5N>QHY|XESU^xIb|oSjO|?X0LNtOHO=4n-(R6#oE_My}-g`Iy<?ZtvR#CI(eCO`od3$GPXJ%hfzNIR8l+&V_owJ?9ysT%MiVq7d?&(<aep5a3uIjnR6YWUVt}B}AM3%f?-)R}8CL8ZJUK>n#e`9{2N>TADRVAooq^NXV9n<fpXmNIAVVFavQvRm#>iV;BdD^dfm2ul@(Lw9TT3@e{G3I#XPRhwP1nK)xFX{hj-u}gTt5WKyQhr}rzU)iJYpxrwzD`y5S9@;;T^-XrWSi>Pt7j&{QX6LlRMXzILF=P3%A=vHQb`o6&bd6wD6TUQ!+9*?5Rbk{KtJ@yfa0~JR3efv2+2snU<|=f$ofr#tg{RZ!*GniNa;^|WEsyA)RtQG??bGMdZ-UyG?3?opE9n;0PX$fF?S1yZkR9EGEQ>Mh|SRgEzt_C(FSc1f_4Z+dxRkz9U!m26C%(VT_9Vv8@fZbVGs1w=2GVQ5tbuU+8Dzs;%cnH25iJ;6krRsVjH$&2X<jM3T6Ir00(ghNAMUYa1mE=9k(zVi<#iDGJeMGN8gJ$Ux~F?hxIaN<Tnv_VlVdNFp6*#$8a1caSEq#24`^&=Wzj-a2Z!{4ZTnYO{w3T7)%V5HN&$6$+{snA@(8Ggga_+?S(toC-=%)C7;f{<2aw@tkevoab3XT^py3?xfLw<oukwumqnZa4|vKtKt9IM))?Nh4!I{45eP*Hf-sBU#SjDFEb~hYm;Hc5#L^yz8?@cTZQO-?Dri<tsDY($<QZ*Y4SNL2hC&s%!57{zLoiMEa32p4jfe7nq%Osm5gW-qp_3KFT$xAmQ+degh$8PnE=u-2=3yabl8;8bt8p(Be-~VI-vux4M!k9)EXtHOGcRj-;C{I+`}PM}AFS~E-KF2GUR3)_pStzx`!;Ck=O1u&)x5m?#b=r|Z_%<<>o#pe+J&|c3-8deQ$*)3UAuLU?9nr4?!61PmtMDf!@km+4vufVUAf9TPF1TpySTblui;+P!*le?u}fke+-TY)@Zr0)4qb`9K0Y=sK5IgD--Jp1`VSbGm^A3U<dnffCVw|&XlmN~=^uRf(Z|C+nL2Iyj8A9I8vfbr&qsVQa(CgVJ>Tv<d+z+jsEpUf-1_nMPr=K-|LyX^umAdc!OmT|^Z)pBQ{!<f{<-<<GONsjjdQ-*uzuURt$pr1-uz_Zj_q~Uto`{1n`;#x9XtK+k)p%LPn<e=^cU0j*v9F3|67(m`tSQhGxfiY{{TCxArt';
let size = 2090;
let hash = 'b#I;?EZD=8s=YfFKk=g-u;6Uc`dwiu3Val5Gt`%rAhCWd4~6Z_WwqIp<R`FEoA*lr*Z0=uC*HY#_2JbY';
async function executeAPL(code) {
  const res = await fetch("https://tryapl.org/Exec", {
    method: 'POST',
    headers: { 'Content-Type': 'application/json; charset=utf-8' },
    body: JSON.stringify([state, size, hash, code]),
  });
  const data = await res.json();
  return data[3];
}
(async () => {
  let result = await executeAPL(`increment 27`);
  console.log(result);
})();
</syntaxhighlight>


== In media ==
== In media ==
=== Videos ===
=== Presentations ===
TryAPL and its development history has been presented at [[Dyalog user meeting]]s and in a [[Dyalog webinar]]:
TryAPL and its development history has been presented at [[Dyalog user meeting]]s and in a [[Dyalog webinar]]:


Line 34: Line 114:
* Brian Becker and [[Adám Brudzewsky]]: [https://dyalog.tv/Dyalog17/?v=ddBjIkyebuY Try APL Online] at [[Dyalog '17]]
* Brian Becker and [[Adám Brudzewsky]]: [https://dyalog.tv/Dyalog17/?v=ddBjIkyebuY Try APL Online] at [[Dyalog '17]]
* [[Richard Park]]: [https://dyalog.tv/Webinar/?v=w4t13pge4mw TryAPL - The Next Generation] webinar
* [[Richard Park]]: [https://dyalog.tv/Webinar/?v=w4t13pge4mw TryAPL - The Next Generation] webinar
* [[Richard Park]]: [https://dyalog.tv/Webinar/?v=cBDmWY_a25Q Presenting TryAPL v3] webinar


=== Hacker News ===
=== Hacker News ===
Line 41: Line 122:
* [https://news.ycombinator.com/item?id=4090097 June 10, 2012]
* [https://news.ycombinator.com/item?id=4090097 June 10, 2012]
* [https://news.ycombinator.com/item?id=6323136 Sept 3, 2013]
* [https://news.ycombinator.com/item?id=6323136 Sept 3, 2013]
* [https://news.ycombinator.com/item?id=9774875 June 24, 2015]
* [https://news.ycombinator.com/item?id=9774875 June 24, 2015] (more than 20 comments)
* [https://news.ycombinator.com/item?id=16505134 March 2, 2018]
* [https://news.ycombinator.com/item?id=16505134 March 2, 2018]
* [https://news.ycombinator.com/item?id=18134675 Oct 3, 2018]
* [https://news.ycombinator.com/item?id=18134675 Oct 3, 2018]
Line 49: Line 130:
* [https://news.ycombinator.com/item?id=24442871 Sep 11, 2020]
* [https://news.ycombinator.com/item?id=24442871 Sep 11, 2020]
* [https://news.ycombinator.com/item?id=24818619 Oct 18, 2020]
* [https://news.ycombinator.com/item?id=24818619 Oct 18, 2020]
* [https://news.ycombinator.com/item?id=27460887 Jun 10, 2021] (lots of comments)
* [https://news.ycombinator.com/item?id=27460887 Jun 10, 2021] (more than 200 comments)


On occasion, the server has been overwhelmed by the increased traffic, known as a [[wikipedia:hug of death|hug of death]].
On occasion, the server has been overwhelmed by the increased traffic, known as a [[wikipedia:hug of death|hug of death]].

Navigation menu