Comments (1)
The simplest way is without a doubt enclosing the lambda expression in parentheses:
((x Str) -> say x)("Yo anonymous!")
, and then calling with parentheses syntax for the arguments.
Note that fragments do not need typed parameters, because they are invoked in a given context where the types can be inferred, and thus they can't be used stand alone (unless typed into a lambda).
Lambdas however, that can be used "stand alone", and passed around, need to have their arguments typed. This is because (unless you use closured variables in it) it is a C-compatible function (pointer), and because there's no telling where it will be passed.
Thus ((x) ~> say x)("Yo anonymous!")
will not work:
can't execute `((x)~>
$.raise("can't execute `say(x)` at /tmp/foo.ox:1:9: `x` has no type")
-- my-lambda is a neat and tidy super compatible first class function
my-lambda = (x Str) -> y = stuff x; do-more-stuff y
my-lambda "foo"
-- arg is _yielded_ to the fragment, and type inferred in the process:
some-fun-taking-fragment (x) ~> y = stuff x; do-more-stuff y
It might be possible to implement type inference for when calling a lambda and/or fragment immediately, not sure how hard it would be, probably some crazy edge cases...
The "man-or-boy" compiler challenge (which exist only to terrorize compilers) shows that Onyx is a man-compiler, but, unfortunately self-reference is not possible in the lambda-body without declaring it before (b = raw () -> T
) :-/
-- "man-or-boy.ox"
a(k T, x1, x2, x3, x4, x5) ->
b = raw () -> T
if k <= 0 ? x4() + x5() : (b = () -> k -= 1; a k, b, x1, x2, x3, x4)()
say a 10, () -> 1, () -> -1, () -> -1, () -> 1, () -> 0
I think it's quite a bit harder then it's worth. How big portion of your code is actually made out of such acrobatics?
from onyx-lang.
Related Issues (20)
- Is this still being maintained? HOT 1
- Idea: replacing `+=` etc. with the canonical "self-call-assign" HOT 4
- Feature: terse array literals HOT 1
- Taking a look at how to effectively further the project HOT 5
- Request: Tagged unions HOT 3
- GUI in ONYX ? HOT 2
- [Question] Does this language has reader macros implemented and supports template programming? HOT 2
- Ditch Global Variables from the Language (Use Type Scoped Vars for Those Cases) HOT 4
- `Self` and `this` vs Other Namings HOT 3
- Feature: spread operator HOT 4
- Dead? HOT 4
- So it's dead then? HOT 3
- `in` operator HOT 1
- Tool: Stylizer / Formatter
- Type Reasoning Keywords HOT 20
- Allow Prime (Apostrophe in Reality) Signs at End of Identifiers HOT 10
- "Route '66 Style"* Syntax For Code Blocks (Braces) HOT 18
- Syntax Flow, Unresolved Ideas - Suggestions Welcome HOT 2
- Write Documentation for Onyx Lang HOT 3
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 onyx-lang.