Questions tagged [apl]

APL (named after the book A Programming Language) is an interactive array-oriented language. It is based on a mathematical notation developed by Kenneth E. Iverson. Do not use this tag for Alexa Presentation Language; use [alexa-presentation-language] instead.

Wiki

APL, short for A Programming Language, is an interactive array-oriented language and integrated development environment. It is an interpreted language with built-in array capabilities and outstanding debugging features that makes the language a perfect choice for the agile approach. APL is also the first functional programming language ever, and it is also considered as a tacit programming language.

Example

APL uses symbols, array comprehension, and implied Iverson brackets to make its code concise and enable thinking about it much like Mathematical formulas.

This example assigns the vector (list) value 4 5 6 7 to N:

N ← 4 5 6 7 

The code below then adds 4 to all elements of the vector (giving 8 9 10 11):

N + 4

Now we can get a Boolean mask indicating results of 10 or higher (giving 0 0 1 1):

10 ≤ N + 4

And sum that to find out how many sums fulfilled the criteria (giving 2):

+/ 10 ≤ N + 4

Tag usage

The tag should be used for programming related problems in implementing or using the APL programming language. Please avoid theoretical and conceptual questions on Stack Overflow. Other tags such as , or can also be used with tag . Make sure to specify which dialect you use, for example by using the tag.

Read more

341 questions
5
votes
1 answer

How to find the index of the first row of a matrix that satisfies two conditions in APL Language?

One more question to learn how to use APL Language. Suppose you have an array, as an example: c1 c2 c3 c4 c5 c6 3 123 0 4 5 6 3 134 0 2 3 4 3 231 180 1 2 5 4 121 0 3 2 4 4 124 120 4 6 3 4 222 222 5 3 5 So, how to find out which…
5
votes
1 answer

How would I go about counting the amount of each alphanumerical in an array? (APL)

I can't figure out how to take a matrix and count the amount of the alphanumerical values for each row. I will only be taking in matrices with the values I'm counting. For example, if I got: ABA455 7L9O36G …
JTP
  • 85
  • 4
5
votes
1 answer

Explanation of quicksort in APL

I am attempting to understand the classic quicksort in APL: Q←{1≥≢⍵:⍵ ⋄ S←{⍺⌿⍨⍺ ⍺⍺ ⍵} ⋄ ⍵((∇S))⍵⌷⍨?≢⍵} There are some things I don't understand, and some stylistic choices that bother me, so I'm going to list all of them out. I hope…
Siddharth Bhat
  • 823
  • 5
  • 15
5
votes
1 answer

foldr vs foldl as reduce operator in APL

In Kenneth Iverson’s A Programming Language the reduction operation op/ is defined as a foldl (left fold): The ◌-reduction of a vector is denoted by ◌/ and defined as z←◌/ ⟺ z = (⋯((₁ ◌ ₂) ◌ ₃) ◌ ⋯ ᵢ) However in modern APLs, it is clearly a…
lelf
  • 237
  • 1
  • 8
5
votes
3 answers

Assigning a niladic function

A non-niladic function F can be assigned to a variable G with G ← F However, if F is niladic, how do I prevent it from being evaluated?
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
5
votes
1 answer

In what way is the distinction between scalars and vectors useful in APL?

I'm an experienced software engineer beginning to study APL, and in order to get a better feel for the language early on, I would like to understand why the language exposes to the coder the difference between scalars and vectors. As far as I can…
5
votes
1 answer

K pattern for iterator protocol

I'm playing with John Earnest's K implementation in the context of Project Euler problems. Many of the problems involve taking the first n terms, or all terms <= n, from an infinite series (particularly primes). It could also involve taking items…
chrispsn
  • 243
  • 1
  • 4
5
votes
3 answers

Creating a vector of closures in Dyalog

I would like to define a vector of anonymous functions that take a single parameter, then map a parameter x across this vector, returning an array of the results of f(x) for each index. Is this possible in Dyalog? I ask because my naive attempt at…
Ian Martin
  • 95
  • 6
5
votes
6 answers

How to interleave two given vectors in APL

I'm trying to solve a problem using APL, for which I have two vectors v1 and v2, with relative length of at most +1, depending on the input. That means that ((≢v1)-(≢v2))∊¯1 0 1. What would be the best way to interleave said vectors, so to create a…
J. Sallé
  • 213
  • 1
  • 8
5
votes
5 answers

in APL how do I turn a vector (of length n) into a diagonal matrix (nxn)?

I had a J program I wrote in 1985 (on vax vms). One section was creating a diagonal matrix from a vector. a=(n,n)R1,nR0 b=In a=bXa Maybe it wasn't J but APL in ascii, but these lines work in current J (with appropriate changes in the primitive…
osmanfb1
  • 53
  • 2
5
votes
4 answers

How to split a number into its digits in APL

In APL, how can I split an integer or number into a vector containing its digits? What is the most concise (shortest) way of doing this?
lmq_305
  • 65
  • 6
5
votes
5 answers

"APL Object Notation" in Dyalog APL

How to convert any Dyalog APL value to a character vector that could be passed to ⍎ to get the same value? How this is expected to look like: x←2 3⍴⍳6 x←1,⊂x x←x,⊂'foo' y←desired_function x DPX…
Olexa
  • 577
  • 2
  • 16
5
votes
4 answers

APL Keymapping on Linux (GNU APL)

My Grandfather was an APL programmer at IBM back in the 60s/70s. He has recently started using Linux and I have been helping him to setup and use GNU APL (http://www.gnu.org/software/apl/). The biggest headache for me at the moment is the…
theamoeba
  • 1,331
  • 13
  • 14
5
votes
2 answers

How does reduce/scan work in APL with user defined functions?

I'm trying to find the length of the longest unbroken chain of 1s in a boolean vector in APL. In Haskell, if I had a boolean list represented by 1s and 0s, I could do something like this: Prelude> scanl (\acc x -> x*(acc+1)) 0…
ackien
  • 521
  • 1
  • 5
  • 10
5
votes
3 answers

Understanding APL's Inner Product

Here is an excerpt from the Mastering Dyalog APL book, from the chapter on Inner Products: HMS is a variable which contains duration in Hours, Minutes, and Seconds: HMS ← 3 44 29 Chapter J – Operators 397 We would like to convert it into seconds.…
syntagma
  • 23,346
  • 16
  • 78
  • 134
1 2
3
22 23