apl – a programming language

26
APL – A Programming Language By Bryan Wilson

Upload: bryan-wilson

Post on 06-Jul-2015

351 views

Category:

Documents


2 download

DESCRIPTION

My current favorite language~

TRANSCRIPT

Page 1: Apl – a programming language

APL – A Programming Language

By Bryan Wilson

Page 2: Apl – a programming language

//TODO - Header

• Short History

• Brief APL Rundown

• APL Details and Tools

• Syntax

– Data, Structures, Classes

– Functions, Operands

– System Variables, Functions

• Expanding APL

Page 3: Apl – a programming language

30 Second History

• This language is crazy

• History sheds light on why

Page 4: Apl – a programming language

Enter Kenneth E. Iverson

Profession: Mathematics “5 is greater than 1. Look”

Page 5: Apl – a programming language

His Notation

Relic found in ancient Mayan ruins.

Page 6: Apl – a programming language

A Pointless Language

• Entirely dynamic, highly abstract

• Largely interpreted (line by line execution)

• “Keywords” are symbols

• Tacit programming

• Short programs, probably about 1 line

• Write-only language

Page 7: Apl – a programming language

How the magic happens

• Right to left evaluation, except for parens

5 + 5 10 5 x 5 25 5 × 5 + 5

50

(5 × 5) + 5

30

Page 8: Apl – a programming language

Time to get crazy

• Types of data are largely done for you

1 2 3 + 5

6 7 8

¼9

1 2 3 4 5 6 7 8 9

2 4 ½¼9

1 2 3 4 5 6 7

8 9 1 2 3 4 5

Page 9: Apl – a programming language

Stop. Demotime.

Page 10: Apl – a programming language

Boring APL stuff

• Specifications

– ISO (International Standards Organization

– APL2, by IBM

• Interpreted

– Thus, Interpreters

• APL+

• APLX

• Dyalog APL

• VisualAPL

Page 11: Apl – a programming language

Interpreters

• Use workspaces, and have unique specs

– Workspace

– System Variables

– System Functions

• Modes

– Calculator mode

– Definition mode

Page 12: Apl – a programming language

Simple Data

• A number

– 24595

– Can be decimal or negative

• A character

– ‘s’

– Wrapped in single quotes

– ‘Use two ‘’ to escape the ‘’ ‘

Page 13: Apl – a programming language

Data Structures

• May have data, has dimensions

• Data does not have dimensions

• Struct – 1 item, no dimensions

• Vector- 1d list of items

• Matrix -2D..nD list of items

• Item can be character, number or structure

• Data structures can have mixed data, or nested

Page 14: Apl – a programming language

Data and structure syntax

• To store a variable [name] „ [variable]

• Names can start with a letter and NOTHING else

• Names can have numbers and some symbols

• Don’t duplicate names

Page 15: Apl – a programming language

Functions

• Types – 0 arguments (niladic)

– 1 argument (monadic) • Everything to the right

– 2 arguments (dyadic) • Everything to the right

• First item to the left

• Can return data/data structure

• Bucket brigade

• Can be named like data

• One symbol, 1-2 functions, depending on arguments

Page 16: Apl – a programming language

Operations

• Modify the function of…functions.

– How functions are applied to data

• In addition to 0-2 arguments, can take 1-2 operands

• Functions can be operands

• Can also be named like functions

Page 17: Apl – a programming language

Classes

• Logical grouping of data and functions

„ŒNEW CLASSNAME

[classname].[function/property]

• Can have constructors.

• Some interpreters let you use external classes

– .NET

Page 18: Apl – a programming language

Alienspeak • Arithmetic

+, -, ×, ÷, ⌈, ⌊, |

• Algebraic ⍳ , ? , * , ⍟, ○, ! , ⌹

• Comparative <, ≤, =, ≥, >, ≠, ≡, ∊, ⍳, ⍷

• Logical ~, ∨, ^, ⍱, ⍲

• Manipulative ⍴, ≡, , , ∊, ~, ⌽, ⍉, ↑, ↓, ⊂, ⊃

Page 19: Apl – a programming language

Continued Mathyspeak

• Sorting

⍋, ⍒, ⊤, ⊥

• Miscellaneous

⎕, ⍞, ⋄, ⍕, ⍝, ⍎, ⌷, ⌻,¯

• Operators

/, \, ., ∘. , ¨, [ ]

Page 20: Apl – a programming language

Defining your own functions

• It can be done! Watch!

Page 21: Apl – a programming language

System Variables and Functions

• Variables

– Easy to pick out, they start with Œ

– Change depending on interpreter

• Functions

– Start with a )

– Also change depending on interpreter

Page 22: Apl – a programming language

Can’t cover everything!

• Can you have threads?

– Yes. Some interpreters.

• Can you have labels?

– In function and operation definitions.

– This includes if/else and try/catch blocks

• Where can I learn more?

– Classes quoted at ~$2000 per day per person

Page 23: Apl – a programming language

The future is J

• APL transformed to be easier to read

quicksort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#)

Page 24: Apl – a programming language

Summary

• Simply put:

– Dynamic

– Abstract

– Powerful

– Awesome

Page 25: Apl – a programming language

Questions for YOU

1. ⍳9 Returns what?

1 2 3 4 5 6 7 8 9

2. What does an operator in APL do?

Changes how a function is applied to data

3. To create a 3 dimensional array:

(1 2 3) ⍴ (5 4)

Page 26: Apl – a programming language

Questions for me?

There are three things a man must do

before his life is done

write two lines in APL,

and make the damn thing run