New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composable functions #390
Composable functions #390
Conversation
Continuing discussion from #368 (comment) .. Ah I was confused,
But To fully replace a pattern you could do: s("bd sd").every(3, constant(s("cp")))
Anyway, this sort of thing works now: s("bd sd").every(3, fast(2).rev().iter(4).out(s("bd*5")).fast(2)) |
Ok instead of confusing things with munging So |
Finally got some time to think this through a bit more.
This is a little strange, in that we are using method calls both as methods (like If we keep that (and I think we clearly should), then I think it follows that we should also support the (currently non-working) If we fix that, then This means we can do We can also do I'm still unsure whether The problem is that the second parameter to Ideally, So TODO:
|
This was easy to do but the problem is that I feel like I'm going around in circles on this one.. |
Ok according to the principle of least surprise.. I think in this one, the s("bd sd").n("3 4").every(3, s("cp").fast(2))
// shorthand for:
s("bd sd").n("3 4").every(3, constant(s("cp").fast(2))) So end-users have to learn the hopefully fairly straightforward principle that if the pass a pattern rather than a function, the pattern replaces the pattern they're calling it on. Of the alternatives: s("bd sd").n("3 4").every(3, x => x.set.in(s("cp")).fast(2))
s("bd sd").n("3 4").every(3, x => x.set.in(s("cp").fast(2))) The first one is not really possible to implement, and the second is probably not what they want in most cases. edit argh but we can't do this, as we also want to support patterns-of-functions.. So maybe best to just keep things super simple - raise an error if an object is found where a function is expected. |
sounds reasonable. We could also simplify passing functions to transpile: s("bd").lastOf(2, set.speed(2)) into s("bd").lastOf(2, x=>x.speed(2)) or alternatively, find a way to implement set to support that.
shouldn't this already work? at least this works atm: s("bd").lastOf(3, cat(x=>s("sd"), x=>x.speed("2"))) when lastOf receives the param, the pattern is already unwrapped, so it either gets s("bd").lastOf(3, cat(s("sd"), set.speed("2"))) in that case, lastOf will receive
I don't think that would be a problem. This applies fast before merge: s("bd").lastOf(3, s("sd").fast(2)) (link) This applies fast to the outer pattern: s("bd").lastOf(3, set.s("sd").fast(2)) (link) In this case, the result is actually the same, but I think there should be cases where it makes a difference.. |
This is possible without transpilation.
I don't think so, because strudel has no way to tell whether
But if it's a pattern, we don't know if it's a pattern of functions or a pattern of (in this case) objects.
In the above,
Some confusion here - this was from an earlier point in my train of thought, where I was still trying to make Currently I think
|
…rcase for alignments.
… and alignments, with chained controls
Summary of changes:
Other minor changes:
|
great! |
This reverts commit cbae355.
Revert "Another attempt at composable functions - WIP (#390)"
Maybe I don't understand how it works but this:
produces an error in the Strudel REPL ( |
edit: did not read properly, not realizing that this was the actual PR where this was added (before it was reverted again). |
Oh I'm pretty sure with this PR (#390) edit Hmm I'm remembering the issue now.. Yes I guess this needed all the composability that didn't work out :/ |
Giving up on #368 (patterns that behave like composable functions depending on the context), for lack of javascript type inference.
Instead trying functions-as-functions and patterns-as-patterns. Single-argument functions of patterns get dressed up with all the registered pattern method names, which are simply there to do function composition (which are also then dressed up) or finally apply the composed of functions to a pattern.
So far these are equivalent: