Skip to content
Thin cover for Dyalog APL's ⌺
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE proper name Nov 28, 2017
README.md add y Y w W and fix description of N Jun 20, 2018
Stencil.dyalog
stencil silence ⎕FIX Dec 5, 2017

README.md

Stencil

Introduction

Stencil is a thin cover for Dyalog APL's ⌺ Stencil operator and is intended as golfing language and an easy interface for common tasks involving . Stencil code can in fact easily be rewritten as normal Dyalog APL code.

Feel free to contact me, Adám, in Stack Exchange's APL chat room to learn more about Stencil and Dyalog APL.

In-APL Usage

Execute 2⎕FIX'file://path/Stencil.dyalog to load the operator.

The syntax is result←opts (code Stencil specs) input, but opts is optional.

For the specifics of opts, code, and specs, see the linked guidance for the corresponding TIO fields.

Input is an array specifying the initial state.

opts result
none final state or last state before going to a previously encountered state
vector of states
scalar non-negative integer
0-by-0 numeric matrix
number a state

If code is a function, then identifiers may be both single- and multi-letter, and spaces are needed to separate them, i.e. me is not equivalent to m e, and ⎕IO is not set to 0 either. However, the predefined values listed below are available.

TIO User guide

Try It Online is a code testing website for many programming languages, both practical and recreational ones, made by Stack Exchange user Dennis. The following describes the relevant fields when using Stencil on TIO.

Command-line options

This may be any one of the following options:

opt Effect
none return final state or last state before going to a previously encountered state
return list of states from input to final state or last state before going to a previously encountered state
return the number of states in the above
output states until stable, or forever if cyclic
number return the state after that many states

combined with any of the following options:

opt Effect
P ┌───┐ Plane:
│   │ left and right disconnected
└───┘ lower and upper disconnected
C ┌───┐ Cylinder:
↑   ↑ left and right joined
└───┘ lower and upper disconnected
T ┌─→─┐ Torus:
↑   ↑ left and right joined
└─→─┘ lower and upper joined
M ┌─→─┐ Möbius strip:
│   │ left and right disconnected
└─←─┘ lower and upper twist-joined
K ┌─→─┐ Klein bottle:
↑   ↑ left and right joined
└─←─┘ lower and upper twist-joined
R ┌─→─┐ Real projective plane:
↑   ↓ left and right twist-joined
└─←─┘ lower and upper twist-joined
I ┌   ┐ Infinite:
      left and right expand and shrink as needed
└   ┘ lower and upper expand and shrink as needed

Code

This describes what shall be returned for each neighbourhood. It may be a function, or one or more character vectors.

If a single character vector, then this forms the body (i.e. without outer curly braces) of a dfn left operand to . For more information about the operator, see its documentation.

If two character vectors, then the first will be used as a dfn snippet ( is appended to its right) to post-process the result(s).

If three or more character vectors, then the last will additionally be used as a dfn snippet ( is appended to its right) to pre-process the input(s).

Stencil provides some shortcuts not available to with the original . All identifiers are expected to be single-letter, and no spaces are needed to separate them, i.e. me is equivalent to m e. The following values are pre-defined:

Note that all code runs with ⎕IO←0 (0-based Index Origin).

Examples:

3 5 will use 3-row, 5-column neighbourhoods

⍪3 3 will use neighbourhoods of size 3 in every dimension, and step size

name Description
multi-dimensional Moore neighbourhood with self
M vector of Moore neighbourhood with self
m count of non-empty cells in the above
E vector of moorE neighbourhood without self
e count of non-empty cells in the above
V vector of Von neumann neighbourhood with self
v count of non-empty cells in the above
N vector of von neumanN neighbourhood without self
n count of non-empty cells in the above
S scalar self
s Boolean (1 or 0) for whether above is non-empty
P vector of Booleans for each dimension whether it has been padded or not
p number of dimensions which have been padded
vector of amounts of padding for each dimension
W original input
w flattened original input
Y preprocessed input
y flattened preprocessed input

In the above table, Moore neighbordhood means the entire n×m neighbourhood, while von Neumann neighbourhood means cells orthogonal to the self.

Input

Each line is an APL expression for an initial state. Each will be processed separately.

Arguments

This allows specifying the neighbourhood and step size. The arguments will be joined with spaces and executed as an APL expression to be used as right operand for . Stencil provides two shortcuts not available to with original . If a single size is given, it will be used for every dimension. If no size is given, size 3 will be used in every dimension.

Examples:

3 5 will use 3-row, 5-column neighbourhoods

⍪5 3 will use neighbourhoods of size 5 in every dimension with a step size of 3 in every dimension

Examples

Hello, World!

Code: S

Input Hello, World!

Every character will be replaced by itSelf.

Game of Life

Code: 3∊me

A cell will be alive in the next genration if there are 3 live cells either counting itself or not.

To get just the next generation, add the command-line option 1.

To list all generations, add the command-line options .

To calculate the period of a cyclic pattern (an oscillator or a spaceship, add the command-line options ≢I

To check whether a patter is a still life, add the command-line options ≢I and let code be 1=3∊me.

Primality checker

Command-line option: 1

Code: ~S∊1,∘.×⍨2+⍳S

Input has one or more lists of integers. For each such Self, it generates the integers from 0 to Self-1 (⍳S), adds 2 (2+), giving from 2 to Self+1, creates a multiplication table (∘.×⍨), prepends a column of ones (1,), and asks whether the Self is a member thereof (S∊), and then negates that (~).

You can’t perform that action at this time.