4,500
edits
m (Text replacement - "Category:Dyalog APL" to "Category:Dyalog APL examples") |
(integrate prominent link into body text) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
[https://www.youtube.com/watch?v=a9xAKttWgP4 '''John Scholes' Conway's Game of Life''' video] is perhaps the most famous APL video. In it, [[John Scholes]] explains his own implementation of [[Conway's Game of Life]] in [[Dyalog APL]], where he, one step at a time, develops the following [[dfn]]: | |||
<source lang=apl> | <source lang=apl> | ||
life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} | life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} | ||
Line 12: | Line 12: | ||
The code here is written for [[Dyalog APL]]. It also works in [[ngn/apl]], and other [[Nested array theory|nested]] array languages allow similar implementations: see [[#Translations]]. | The code here is written for [[Dyalog APL]]. It also works in [[ngn/apl]], and other [[Nested array theory|nested]] array languages allow similar implementations: see [[#Translations]]. | ||
In 2021, Conor Hoekstra remade the video with additional explanations.<ref>Hoekstra, Conor. [https://www.youtube.com/watch?v=pMslgySQ8nc APL + Game of Life = ❤️] in the [https://www.youtube.com/channel/UC1kBxkk2bcG78YBX7LMl9pQ code_report YouTube channel]. 2021-04-25.</ref> | |||
== The Glider == | == The Glider == | ||
Line 59: | Line 61: | ||
=== Visualising it === | === Visualising it === | ||
To make the pattern easier to see, we can use [[indexing]] to place a <source lang=apl inline>⌺</source> symbol where there's a cell and a <source lang=apl inline>·</source> otherwise, for example: | To make the pattern easier to see, we can use [[Bracket indexing|indexing]] to place a <source lang=apl inline>⌺</source> symbol where there's a cell and a <source lang=apl inline>·</source> otherwise, for example (note that <source lang=apl inline>⎕IO</source> is [[Index Origin]]): | ||
<source lang=apl> | <source lang=apl> | ||
Show←{'·⌺'[⎕IO+⍵]} | Show←{'·⌺'[⎕IO+⍵]} | ||
Line 279: | Line 281: | ||
grid ← glider⍢(¯3 ¯3∘↑) 10 10⍴0 ⍝ This works | grid ← glider⍢(¯3 ¯3∘↑) 10 10⍴0 ⍝ This works | ||
</source> | </source> | ||
=== Ruby === | |||
Github user zverok has translated Scholes' dfn to [[wikipedia:Ruby (programming language)|Ruby]] by first creating an <source lang=ruby inline>apl</source> module to implement parts of APL. The code is shown [https://github.com/zverok/ruby_as_apl on Github] and explained [https://zverok.github.io/blog/2020-05-16-ruby-as-apl.html on zverok's blog]. | |||
== Performance == | == Performance == |