bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] miscellāneum


From: Hudson Flavio Meneses Lacerda
Subject: [Bug-apl] miscellāneum
Date: Thu, 28 Feb 2019 19:59:16 -0300

Hi Jürgen,



=1= Syntatic-Sugar Symbols

While trying ngn-apl, I noticed that it allows single-character
non-ASCII/APL identifiers, something I considered potentially useful
some time ago, when I wrote some operators as exercise using GNU APL.
I used very short operator names (mostly one letter) so that the main
function will not be eclipsed by the operator name.  Simple symbols
might look more suitable and expressive, specially if spaces are
optional. It is not easy to figure out whether a name is a function
(verb), a variable (noun) or an operator (adverb); more symbols allow
for more conventions distinguishing names.  That is not standard, of
course.


ł ← {(1↑⍵) ⍶ (1↓⍵)}  ⍝  Fn ł A B  ⇔  A Fn B   (cut out first; move left)

        ׳ π, 1…10


Here is an example with a high sugar dose:

N ← 200        ⍝ Number of samples
t ← (0…N−1)÷N  ⍝ Time
f ← 7          ⍝ Frequency
A ← sin π·t    ⍝ Amplitude (sine window)

⎕PLOT  A·cos 2·π·f·t


In ngn-apl, one can have definitions like:

¿ ← {⍵×{«Math.random()»}¨⍵}   ⍝ (random float between 0.0 and ⍵)
π ← ○1
· ← ×
¬ ← ∼
º ← {⌊⍵+.5}   ⍝ round
… ← [integer sequence with starting and ending values]
cos ← {2○⍵}
sin ← {1○⍵}
atan ← {¯3○⍵}
∠ ← {180×(12○⍵)÷○1} ⍝ (angle in degrees from complex number)
% ← {⍵÷100}
√ ← {⍵*.5 ; ⍵*÷⍺}  ⍝ (in ngn-apl, ';' separates monadic and diadic code)
Σ ← +/
Π ← ×/
✀ ← [split string at spaces or left argument]
φ ← 0.5×1+(5*÷2)   ⍝ phi - golden ratio constant
⇗ ← {⍵[⍋⍵]} ⍝ sort upwards
⇘ ← {⍵[⍒⍵]} ⍝ sort downwards
⅟ ← {÷⍵}
½ ← {⍵×.5}
∃ ← ∨/
∀ ← ∧/


While some of the examples above are clearly superfluous (like Σ ¬ ·
replacing already easy-to-read +/ ∼ ×), other definitions can make
the code more readable (e.g. ○ functions as sin, cos etc.):

⎕PLOT  A·cos 2·π·f·t
   versus
⎕PLOT  A×2○○2×f×t


This '…' is very handy and intuitive:

35…40    ⇔    35 36 37 38 39 40
35…30    ⇔    35 34 33 32 31 30


The main issue may be how to input the symbols from the keyboard (easy
within GNU Emacs + TeX Input Method, or using the "compose key").



=2= EOF

GNU APL might have some command-line option to --quit the program after
running all the required scripts (without ')off').  Currently I use a
bash script 'aplscript' that appends a file which only instruction is
')off'.

Maybe also an option to load an alternative 'preferences' file (or to
set individual options, like ^D tally to exit).



=3= Optimization Questions

That is just of curiosity: how do the 10 efficiency suggestions by
Bergquist (p.34−37) apply to GNU APL?


=4= Boxing

Boxing might have an option to use raised numbers (¹²³…) to display
lengths of axes. Normal-sized numbers are confusing in cases like this:

      ]boxing 21
      ⊂ 3 5 ⍴ ⌽⍳15 
┌5─────────────┐
315 14 13 12 11│
│10  9  8  7  6│
│ 5  4  3  2  1│
└──────────────┘

(¿315?)

┌⁵─────────────┐
³15 14 13 12 11│
│10  9  8  7  6│
│ 5  4  3  2  1│
└──────────────┘

(Maybe that is too small…)

Is there a boxing option with extra spaces?

┌5───────────────┐
3 15 14 13 12 11 │
│ 10  9  8  7  6 │
│  5  4  3  2  1 │
└────────────────┘



Best,
Hudson






reply via email to

[Prev in Thread] Current Thread [Next in Thread]