Tacit programming: Difference between revisions

Jump to navigation Jump to search
1,818 bytes added ,  17:10, 7 April 2020
(13 intermediate revisions by 2 users not shown)
Line 32: Line 32:


== Trains ==
== Trains ==
A train is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. Arguments are processed by the following rules:
A train is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. Below, <source lang=apl inline>⍺</source> and <source lang=apl inline>⍵</source> refer to the arguments of the train. <source lang=apl inline>f</source>, <source lang=apl inline>g</source>, and <source lang=apl inline>h</source> are functions (which themselves can be tacit or not), and <source lang=apl inline>A</source> is an array. The arguments are processed by the following rules:


A 2-train is an ''atop'':
A 2-train is an ''atop'':
<source lang=apl>
{|
  (g h) ⍵ g (  h ⍵)
|<source lang=apl> (g h) ⍵</source>|| {{←→}} ||<source lang=apl>g (  h ⍵)</source>
⍺ (g h) ⍵ g (⍺ h ⍵)
|-
</source>
|<source lang=apl>⍺ (g h) ⍵</source>|| {{←→}} ||<source lang=apl>g (⍺ h ⍵)</source>
 
|}
A 3-train is a ''fork'':
A 3-train is a ''fork'':
<source lang=apl>
{|
  (f g h) ⍵ (  f ⍵) g (  h ⍵)
|<source lang=apl> (f g h) ⍵</source>|| {{←→}} ||<source lang=apl>(  f ⍵) g (  h ⍵)</source>
⍺ (f g h) ⍵ (⍺ f ⍵) g (⍺ h ⍵)
|-
</source>
|<source lang=apl>⍺ (f g h) ⍵</source>|| {{←→}} ||<source lang=apl>(⍺ f ⍵) g (⍺ h ⍵)</source>
|}
The ''left tine'' of a fork can be an array:
{|
|<source lang=apl>  (A g h)</source>|| {{←→}} ||<source lang=apl>A g (  h ⍵)</source>
|-
|<source lang=apl>⍺ (A g h) ⍵</source>|| {{←→}} ||<source lang=apl>A g (⍺ h ⍵)</source>
|}


The ''left tine'' of a fork (but not an atop) can be an array:
Only [[dzaima/APL]] allows <source lang=apl inline>(A h)</source>, which it treats as <source lang=apl inline>A∘h</source>.<ref>dzaima/APL: [https://github.com/dzaima/APL/blob/ceea05e25687988ed0980a4abf4b9249b736543f/docs/differences.txt#L19 Differences from Dyalog APL]. Retrieved 09 Jan 2020.</ref>
<source lang=apl>
  (A g h) ⍵ ⬄ A g (  h ⍵)
⍺ (A g h) ⍵ ⬄ A g (⍺ h ⍵)
</source>


== Examples ==
== Examples ==
Line 57: Line 60:
=== Plus and minus ===
=== Plus and minus ===
<source lang=apl>
<source lang=apl>
       (+,-)2
       (+,-) 2     ⍝ ±2
2 ¯2
2 ¯2
       1 2 3 (+,-) 4
       5 (+,-) 2  ⍝ 5±2
5 6 7 ¯3 ¯2 ¯1
7 3
      (2 3⍴0) (+,-) 1
1 1 1 ¯1 ¯1 ¯1
1 1 1 ¯1 ¯1 ¯1     
</source>
</source>


Line 119: Line 119:
</source>
</source>
For a more parallel comparison of the notations, see the [[Comparison_with_traditional_mathematics#Practical_example|comparison with traditional mathematics]].  
For a more parallel comparison of the notations, see the [[Comparison_with_traditional_mathematics#Practical_example|comparison with traditional mathematics]].  
== External links ==
== Tutorials ==
* Dyalog: [http://help.dyalog.com/16.0/Content/RelNotes14.0/Function%20Trains.htm version 14.0 release notes]
* APL Cultivation: [https://chat.stackexchange.com/rooms/52405/conversation/lesson-23-transcribing-to-and-reading-trains Transcribing to and reading trains]
* APLtrainer: [https://www.youtube.com/watch?v=kt4lMZbn-so How to read trains in Dyalog APL code] (video)
* APLtrainer: [https://www.youtube.com/watch?v=A2LqqBosvY0 Function trains in APL] (video)
* Dyalog Webinar: [https://www.youtube.com/watch?v=Enlh5qwwDuY?t=440 Train Spotting in Dyalog APL] (video)
* Dyalog '13: [https://www.youtube.com/watch?v=7-93GzDqC08 Train Spotting in Version 14.0] (video)
== Documentation ==
* [http://help.dyalog.com/16.0/Content/RelNotes14.0/Function%20Trains.htm Announcement]
* [http://help.dyalog.com/latest/Content/Language/Introduction/Trains.htm Dyalog]
==References==
<references/>
{{APL syntax}}
{{APL syntax}}

Navigation menu