Compiling APL to JavaScript (2014)

tosh1 pts0 comments

Vector, the Journal of the British APL Association

23 captures<br>25 Oct 2014 - 19 Aug 2025

Dec<br>JAN<br>Feb

14

2014<br>2015<br>2016

success

fail

About this capture

COLLECTED BY

Organization: Internet Archive

These crawls are part of an effort to archive pages as they are created and archive the pages that they refer to. That way, as the pages that are referenced are changed or taken from the web, a link to the version that was live when the page was written will be preserved.

Then the Internet Archive hopes that references to these archived pages will be put in place of a link that would be otherwise be broken, or a companion link to allow people to see what was originally intended by a page's authors.

The goal is to fix all broken links on the web.

Crawls of supported "No More 404" sites.

Collection: Wikipedia Near Real Time (from IRC)

This is a collection of web page captures from links added to, or changed on, Wikipedia pages. The idea is to bring a reliability to Wikipedia outlinks so that if the pages referenced by Wikipedia articles are changed, or go away, a reader can permanently find what was originally referred to.

This is part of the Internet Archive's attempt to rid the web of broken links.

TIMESTAMPS

The Wayback Machine - https://web.archive.org/web/20150114032647/http://archive.vector.org.uk/art10501160

Kenneth E. Iverson<br>1920-2004

Current issue

Vol.26 No.1

Articles in press

Full index

Volumes

26

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

home

advertise

archive

character-mapped code

contribute

in press

team

subscribe

about us

blog

books

community

committee

consultants

events

latest jobs

sponsors

contact

fonts

interpreters

video

© 1984-2015

British APL Association

All rights reserved.

Archive articles posted online on request: ask the<br>archivist.

Not XML: content/published/swedapl/image.jpg

archive/26/1

Volume 26, No.1

Compiling APL to JavaScript

Nick Nickolov (nick.nickolov@gmail.com)

This article is about github.com/ngn/apl[1], an<br>APL to JavaScript compiler written in CoffeeScript. It gives an overview of<br>the project and its dialect of APL, then proceeds to describe three major<br>implementational obstacles and the design decisions taken to overcome them.

Introduction

The list of languages that compile to JavaScript is growing steadily for a good<br>reason: almost every modern consumer device can run a browser with a JavaScript<br>interpreter in it. And for the server theres NodeJS. As a language,<br>JavaScript has its subset of good parts and if you restrict your coding to<br>them, its actually a very decent language. The execution model is reminiscent<br>of Lisp with its lambdas and lexical closures, despite the superficially C-like<br>syntax. As a matter of fact, getting rid of those curly braces, semicolons,<br>and other noise is easy thanks to CoffeeScript, which gives a comfortable layer<br>of syntactic sugar over raw JavaScript.

I started an open source project for an APL compiler targeting JavaScript.<br>Though incomplete and of poor performance, its good enough for experimenting<br>with short programs, such as the Game of Life or the N Queens problem.

I made a conscious decision to deviate from the APL tradition in several ways.

Function definition

Lambdas are supported (function literals enclosed in curly braces, a.k.a.<br>dfns) but the del (∇) syntax for function definition is not. So, instead of

∇R←A f B<br>R←...

one is forced to write

f←{...}

Variable scoping

Scoping is always lexical. This means that the two occurrences of a below

f←{a←123}<br>g←{a←456}<br>h←{...}

are different variables and neither of them is accessible from within h,<br>regardless of the order and nesting of f, g, h invocations.

A variable is considered to belong to the outermost ancestor scope where it is<br>mentioned. So, the first two occurrences of a below are the same variable and the third<br>a is distinct from them:

f←{<br>a←123<br>g←{a←456}<br>h←{a←789}

Note that assignment doesnt necessarily create a local variable. If the<br>variable is already present in any enclosing scope, assignment will set that<br>variable.

A variable must not be used before it is assigned a value. The compiler<br>can detect most violations of that:

⎕←⍳ a ⍝ compiler error<br>a←5

Phrasal forms

Expressions consisting of a sequence of two or three functions are said to<br>form a hook or a fork respectively and the result is a new function defined<br>as follows:

(fg)⍵ ←→ ⍵fg⍵<br>⍺(fg)⍵ ←→ ⍺fg⍵<br>(fgh)⍵ ←→ (f⍵)g(h⍵)<br>⍺(fgh)⍵ ←→ (⍺f⍵)g(⍺h⍵)

Examples usages of phrasal forms are the arithmetic mean written as<br>+/ ÷ ⍴ and continued fraction evaluation as (+÷)\.

Non-privileged primitives

Primitives are just like any other variable, only as if implicitly defined in<br>the root scope. As a side effect, they can be overridden:

3⍟4 ⍝ returns 1.2618595071429148<br>⍟←{⍺+2×⍵}<br>3⍟4 ⍝ returns 11

One use of this fact might be to introduce comparison tolerance, which isnt<br>supported by default:

⎕CT←1e¯13<br>=←{(|⍺-⍵)≤⎕CT×(|⍺)⌈|⍵}

Its okay to use single...

archive javascript variable pages from wikipedia

Related Articles