From 069a0fd86f9bb239476235ed795a3a1d330d203e Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 1 Jun 2016 14:16:53 +0200 Subject: added a few APLish unicode shortcuts for some of the primitives/Stream methods * Unicode identifiers allowed in LuaJIT 2 * We add the shortcuts directly to applause.lua but using Unicode escapes. Thus we don't have to maintain a separate file and we can still edit applause.lua using a non-UTF editor like SciTECO * Stream:sub (subtract) renamed to Stream:minus. This was previously overwritten by the SubStream wrapper. --- applause.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/applause.lua b/applause.lua index 91c879a..68d233b 100644 --- a/applause.lua +++ b/applause.lua @@ -226,6 +226,7 @@ end function Stream:map(fnc) return MapStream:new(self, fnc) end +Stream["\u{00A8}"] = Stream.map -- APL Double-Dot -- Register all unary functions from the math package -- as stream operations/methods (creates a stream that calls @@ -263,7 +264,7 @@ function Stream:add(n) return self:map(function(x) return x+n end) end -function Stream:sub(n) +function Stream:minus(n) return self:map(function(x) return x-n end) end @@ -271,10 +272,12 @@ function Stream:mul(n) return self:map(function(x) return x*n end) end Stream.gain = Stream.mul +Stream["\u{00D7}"] = Stream.mul -- APL Multiply/Signum function Stream:div(n) return self:map(function(x) return x/n end) end +Stream["\u{00F7}"] = Stream.div -- APL Divide function Stream:mod(n) return self:map(function(x) return x%n end) @@ -283,6 +286,7 @@ end function Stream:pow(n) return self:map(function(x) return x^n end) end +Stream["\u{22C6}"] = Stream.pow -- APL Exponentiation function Stream:clip(min, max) min = min or -1 @@ -371,6 +375,7 @@ end function Stream.SinOsc(freq) return Stream.Phasor(freq):mul(2*math.pi):sin() end +Stream["\u{25CB}"] = Stream.SinOsc -- APL Circle -- Pulse between 0 and 1 in half a period (width = 0.5) function Stream.PulseOsc(freq) @@ -1706,6 +1711,7 @@ function tostream(v) end function iota(...) return IotaStream:new(...) end +_G["\u{2373}"] = iota -- APL Iota function line(v1, t, v2) return iota(t):mul((v2-v1)/t):add(v1) -- cgit v1.2.3