John Scholes' Conway's Game of Life: Difference between revisions

Jump to navigation Jump to search
→‎Translations: Link to zverok's Ruby version
(→‎Translations: Link to zverok's Ruby version)
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Perhaps the most famous APL video is [[John Scholes]] explaining his own implementation of [[Conway's Game of Life]] in [[Dyalog APL]].<ref>[[John Scholes|Scholes, John]]. [https://www.youtube.com/watch?v=a9xAKttWgP4 "Conway's Game of Life in APL"]. 2009-01-26.</ref> Scholes also published notes<ref>[[John Scholes|Scholes, John]]. [http://dfns.dyalog.com/n_life.htm life] in the [[dfns workspace]].</ref> on the Game of Life, including alternate implementations, in his [[dfns workspace]].
Perhaps the most famous APL video is [[John Scholes]] explaining his own implementation of [[Conway's Game of Life]] in [[Dyalog APL]].<ref>[[John Scholes|Scholes, John]]. [https://www.youtube.com/watch?v=a9xAKttWgP4 "Conway's Game of Life in APL"]. 2009-01-26.</ref> In the video, Scholes develops the following [[dfn]] one step at a time:
<source lang=apl>
      life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
</source>


Here is the full implementation:
Scholes also published notes<ref>[[John Scholes|Scholes, John]]. [http://dfns.dyalog.com/n_life.htm life] in the [[dfns workspace]].</ref> on the Game of Life, including alternate implementations, in his [[dfns workspace]]. The workspace includes a function which differs in a few small details.
<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∘.⌽⊂⍵}
</source>
</source>


In this page we will break down the function to see how each part operates. If you're completely new to APL, you probably won't understand all of it right away—consider also reading some [[Simple examples]] or APL [[introductions]]. However, you should be able to follow the general ideas. Bear in mind that APL evaluates expressions from [[Evaluation order|right to left]] unless you use parentheses.
In this page we will break down the function <source lang=apl inline>Life</source> to see how each part operates. If you're completely new to APL, you probably won't understand all of it right away—consider also reading some [[Simple examples]] or APL [[introductions]]. However, you should be able to follow the general ideas. Bear in mind that APL evaluates expressions from [[Evaluation order|right to left]] unless you use parentheses.


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]].
Line 276: Line 279:
       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 ==
Line 304: Line 311:
== References ==
== References ==
<references />
<references />
[[Category:Examples]][[Category:Dyalog APL examples]]

Navigation menu