TryAPL: Difference between revisions

Jump to navigation Jump to search
6 bytes removed ,  21:29, 1 January 2022
m
Line 63: Line 63:
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:
<source lang=js>
<source lang=js>
async function evaluateAPL(code) {
async function executeAPL(code) {
   const res = await fetch("https://tryapl.org/Exec", {
   const res = await fetch("https://tryapl.org/Exec", {
     method: 'POST',
     method: 'POST',
Line 75: Line 75:
// To call the function you must use an async/await statement.
// To call the function you must use an async/await statement.
(async () => {
(async () => {
   let resultSum = await evaluateAPL(`2+2`);
   let resultSum = await executeAPL(`2+2`);
   let reshape = (await evaluateAPL(`2 2⍴⍳${resultSum}`))
   let reshape = (await executeAPL(`2 2⍴⍳${resultSum}`))
     .map(row => row.split` `.map(x => +x));
     .map(row => row.split` `.map(x => +x));
   let sumReduce = (await evaluateAPL(`+/ (↑⍣≡0∘⎕JSON) '${JSON.stringify(reshape)}'`))
   let sumReduce = (await executeAPL(`+/ (↑⍣≡0∘⎕JSON) '${JSON.stringify(reshape)}'`))
     .map(row => row.split` `.map(x => +x));
     .map(row => row.split` `.map(x => +x));
   console.log(sumReduce);
   console.log(sumReduce);
Line 91: Line 91:
let hash = 'b#I;?EZD=8s=YfFKk=g-u;6Uc`dwiu3Val5Gt`%rAhCWd4~6Z_WwqIp<R`FEoA*lr*Z0=uC*HY#_2JbY';
let hash = 'b#I;?EZD=8s=YfFKk=g-u;6Uc`dwiu3Val5Gt`%rAhCWd4~6Z_WwqIp<R`FEoA*lr*Z0=uC*HY#_2JbY';


async function evaluateAPL(code) {
async function executeAPL(code) {
   const res = await fetch("https://tryapl.org/Exec", {
   const res = await fetch("https://tryapl.org/Exec", {
     method: 'POST',
     method: 'POST',
Line 102: Line 102:


(async () => {
(async () => {
   let result = await evaluateAPL(`increment 27`);
   let result = await executeAPL(`increment 27`);
   console.log(result);
   console.log(result);
})();
})();

Navigation menu