Comments (2)
APL can actually do "under"... ish. Its Star Diaeresis (⍣) operator repeats an operation N times, but the number of times can actually be ¯1.
It's gonna be really hard to show a legible example, because of how APL reads in general, but I'll still try:
(×∘2)⍣¯1⊢3 ⍝ The whole operation
(×∘2) ⍝ A partially applied multiplication operator, in Raku this'd be *×2
⍣¯1 ⍝ Repeated -1 times, inverse of this function
⊢3 ⍝ Applied to 3
This results in 1.5
.
The way you could have "dual" would be to first, apply the "forward" operation, then apply the whole block, then apply the inverse of the "forward" operation.
I'm gonna post a "dual" here. I can detail it, but it's gonna be hard to read no matter what.
⍺⍺
is "function to the left", ⍵⍵
is "function to the right", and ⍵
is "argument to the right".
f←{⍺⍺⍣¯1⊢⍵⍵⍺⍺⍵}
(×∘2)f(+∘2)⊢5
6
(×∘2)
is the function to the left (⍺⍺
), (+∘2)
is the function to the right (⍵⍵
), 5
is the argument to the right (⍵
).
So what happens is this:
(×∘2)⍣¯1⊢2+2×5
Which calculates (2*5+2)/2, 6.
A bit long-winded for a narrow use case, but the sentiment is the same. Dyalog APL Extended, which is an extension to Dyalog APL, has this "under" function as the operator ⍢.
from alma.
@vendethiel Thank you for the explanation. It's good to know about prior art. I agree APL is somewhat opaque, but (thanks to your explanations), I think I actually got it.
It feels to me the under
macro is doing something more, semantically. The APL version passes around values fairly to transform forwards-and-backwards fairly explicitly. The under
macro implicitly injects/wraps forward
and backward
calls around values which cross in and out (respectively) of the lexical environment of the under
block.
I don't recall seeing that technique before; the closest thing it reminds me of is our treatment of free variables in quasi
blocks (which turn into "direct lookups" per #410). Maybe variable interpolations in Raku regexes could be considered a variant of this pattern, too. under
is lexically changing the "meaning" of free variables — I'm a bit surprised myself at how OK I am with that. It feels slightly related to exists
(#292) and delete
(#290) in that it "changes how we evaluate something" (but via a syntax transformation).
from alma.
Related Issues (20)
- React in some way to MetaOCaml HOT 13
- Add Records and Tuples (as a syntax extension) like in the TC39 proposal
- Consider code coverage (as a code generation technique) HOT 9
- Consider having a ? operator on calls (like Rust) for error propagation HOT 3
- React in some way to Flatt's "Binding as a set of scopes" work in Racket HOT 6
- Suggestion: add alma to an online evaluator HOT 1
- Get off Travis HOT 1
- Move get, set, and has to be on Dict instead of on dictionary instances
- MOP _и_ AST? Por que los dos? HOT 3
- Alma's (and Raku's) quasi scoping is significantly different from Scheme's/Lisp's HOT 16
- Add a test for nested unquotes HOT 1
- Reasons for modules HOT 72
- The quasi in the example name.alma doesn't need to take a closure
- Handle (ignore) the BOM
- Fix mis-implemented test
- A unification of access paths HOT 2
- Handling of MAIN over-catches X::ParameterMismatch exceptions
- Add a test for unquotes _not_ being first-class syntax
- Add a closure test to the test suite
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alma.