Skip to content

Commit

Permalink
Merge pull request #1059 from tidalcycles/dollar-colon
Browse files Browse the repository at this point in the history
anonymous patterns + muting
  • Loading branch information
felixroos authored Apr 18, 2024
2 parents e0c4997 + 93d151b commit f427b56
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ export function repl({
const scheduler =
sync && typeof SharedWorker != 'undefined' ? new NeoCyclist(schedulerOptions) : new Cyclist(schedulerOptions);
let pPatterns = {};
let anonymousIndex = 0;
let allTransform;

const hush = function () {
pPatterns = {};
anonymousIndex = 0;
allTransform = undefined;
return silence;
};
Expand All @@ -82,6 +84,15 @@ export function repl({
// set pattern methods that use this repl via closure
const injectPatternMethods = () => {
Pattern.prototype.p = function (id) {
if (id.startsWith('_') || id.endsWith('_')) {
// allows muting a pattern x with x_ or _x
return silence;
}
if (id === '$') {
// allows adding anonymous patterns with $:
id = `$${anonymousIndex}`;
anonymousIndex++;
}
pPatterns[id] = this;
return this;
};
Expand Down

0 comments on commit f427b56

Please sign in to comment.