TryAPL

From APL Wiki
(Redirected from Tryapl)
Jump to navigation Jump to search
TryAPL's logo.

TryAPL is online service that allows trying out a subset of Dyalog APL. The back-end is a Jarvis server that uses Adám Brudzewsky's Safe Execute to provide sandboxing. The source code for TryAPL was released under the MIT License on 15 July 2021.[1]

Interfaces

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

TryAPL.org

TryAPL.org is the original and main web interface for the back-end:

File:TryAPL
TryAPL's web inferface

The source code is available on Github.

TryAPL Mini

TryAPL Mini is an alternative web interface written in Elm, focusing on exploration of primitives. Half of the screen is used to display information about whichever glyph the user last hovered their mouse over on the built-in language bar.

The source code is available on GitHub.

APLgolf

APLgolf is a website that assists in composing answers for Code Golf Stack Exchange.

The source code is available on GitHub.

Bookmarklet

Creating a 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:

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`))}})())

Chat box exec

Chat box exec is a userscript that adds an Execute button () to right of the message input area in Stack Exchange's chat rooms. Clicking this button, or hitting access-key[2] x, executes the first line of the text that is currently in the message input area, and appends the result to the area, while also formatting the message to be rendered in monospace font. One can then hit the send button or press Enter to submit the message. With a userscript extension (for example Tampermonkey) installed, navigating to the raw file, should cause the extension to suggest automated installation. Alternatively, the script can be downloaded from the userscripts GitHub repository of Razetime, or from the Greasyfork userscript host under the name Chat box exec.

Chatbot

Stack Exchange moderator "hyper-neutrino" hosts a chatbot using TryAPL's name and icon, active in two Stack Exchange chat rooms; the APL Orchard and the Stack Exchange's sandbox chat room. To use it, write inline code or a multi-line code block, and prepend ⎕← or to lines you wish to run, in any of the two chat rooms:[3]

The source code is available on GitHub.

Twitter bot

TryAPL Bot is a Twitter bot run by Rodrigo Girão Serrão using TryAPL icon. It responds to tweets that mention it. To use it, post a tweet that contains the bot's handle (@tryaplbot) and code in backticks, for example `⍳3`. 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 and if the result is a single line that can fit in the tweet, it is included there too.

The source code is available on GitHub.

API

Requests to TryAPL's backend consist of submitting a POST request to https://tryapl.org/Exec containing a 4-element list ["state", size, "hash", "input"] where the first three elements can use the placeholder values "" or 0. The server responds with a similar 4-element list ["state", size, "hash", ["lines", "of", "output"]]. 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, "\bhelp\b" for which the text is the URL of help page requested by ]Help

XMLHttpRequest

A minimal (no-state) TryAPL front-end can be implemented as follows using the XMLHttpRequest API:

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"))
}

Fetch

This is a function that uses the Fetch API to send a request given as input a string code:

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);
})();

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 increment ← 1∘+, will appear a file named Exec: in the Response tab there will be a JSON containing the three values.

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);
})();

In media

Presentations

TryAPL and its development history has been presented at Dyalog user meetings and in a Dyalog webinar:

Hacker News

TryAPL is frequently featured on Hacker News:

On occasion, the server has been overwhelmed by the increased traffic, known as a hug of death.

Notes

  1. Dyalog Ltd. TryAPL. GitHub.
  2. The keyboard combination varies by browser and operating system. For details, see W3Schools' HTML accesskey Attribute article.
  3. For details, see the chat bot's profile.
APL community [edit]
Activities ConferencesUser groups and meetupsIverson AwardExercises
Chat rooms and forums APL FarmAPL OrchardAPL Wiki
People Phil AbramsBrian BeckerBob BerneckyLarry BreedCharles BrennerJim BrownAdám BrudzewskyGitte ChristensenPeter DonnellyJohn EarnestAdin FalkoffGarth FosterLib GibsonAaron HsuRoger HuiKen IversonMorten KrombergDick LathwellMarshall LochbaumEugene McDonnellRoger MooreTrenchard MoreAlan PerlisRaghu RanganathanHenry RichAl RoseJohn ScholesIan SharpBob SmithGeoff StreeterJoey TuttleArthur Whitney
Other APL TrustAPL Quote QuadBlogsBooksCase studiesFamous APL usersHumourJobsMerchandisePapersPodcastsTryAPLTry It OnlineVideo channels