Code Monkey home page Code Monkey logo

apl.swift's Introduction

APL.swift

APL comes equipped with a rich and varied combinator library for the manipulation of arrays and scalar values. The novelty of the language's approach is that it completely divorces itself from the pervasiveness of English in traditional programming languages. That is to say the combinators are given 1-symbol aliases and a breathtakingly simple semantics such that the language itself transcends all language barriers. Seeing as unicode characters are being embraced as operators in Swift, a full port of the complete array calculus should be possible while preserving these original names; albeit with a much more liberal use of parenthesis.

By embedding APL in a type system like the one Swift uses, it can be made an overall safer calculus at the cost of syntactic simplicity.

Operators

Operators in APL come in two forms: Verbs and Adverbs. Naturally, a verb is a Monadic or Diadic (one or two argument) function that acts upon its operands to produce a result. An adverb is therefore a function that acts on a verb to lift it into a higher order function. For example, APL defines the adverb /, or across, as a means of lifting a verb over an array. (This allows something like +/ 1 2 3 4 to be read literally as 'plus across the array [1, 2, 3, 4]').

Some operators will be interdefined, but will never clash with the Swift Standard Library, or with each other (Swift does not catch mutually (co-)recursive operators as of yet). Generally, the more specialized the function, the better chance it will be interdefined. Interestingly, all of APL's combinators can be derived from one another in some way, shape, or form, save some basic arithmetic and IO operators.

APL makes no provisions for side-effecting code, but the Standard Library necessitates inclusion of a random number generator and an arc4random()-like function. IO is also possible from the Standard Library, but is not considered a part of the array calculus. Side effecting operators like Roll will attempt to perform their duties by leaving as little perturbed as possible to maintain purity.

Semantics

All operators are right associative, and evaluation proceeds right to left. For example,

!w ÷ !a × (!w - a)

should be parsed as

(!2 ÷ (!4 × (!2 - 4)))

and interpreted as

=> (!2 ÷ (!4 × (2 - 4)))
=> (!2 ÷ (!4 × -2))
=> (!2 ÷ (24 × -2))
=> (!2 ÷ -48)
=> (!2 ÷ -48)
=> -0.04166666667

Booleans are a large part of APL, but their chosen form is either 0 or 1 for true and false respectively. Functions will never return [Bool], but will instead opt for [Int] for display purposes only.

apl.swift's People

Contributors

codafi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.