Skip to content

Instantly share code, notes, and snippets.

@altbodhi
Created July 1, 2020 13:15
Show Gist options
  • Save altbodhi/1261607dd5e5566c21d5878ae7c41117 to your computer and use it in GitHub Desktop.
Save altbodhi/1261607dd5e5566c21d5878ae7c41117 to your computer and use it in GitHub Desktop.
Nemerle Sample
using System.Console;
using System.Threading;
using System.Threading.Tasks;
using Nemerle;
using Nemerle.Async;
enum Tone {
| REST = 0
| GbelowC = 196
| A = 220
| Asharp = 233
| B = 247
| C = 262
| Csharp = 277
| D = 294
| Dsharp = 311
| E = 330
| F = 349
| Fsharp = 370
| G = 392
| Gsharp = 415
}
enum Duration {
| WHOLE = 1600
| HALF = WHOLE/2
| QUARTER = HALF/2
| EIGHTH = QUARTER/2
| SIXTEENTH = EIGHTH/2
}
[Record]
struct Note {
public ToneVal : Tone;
public DurVal : Duration;
public override ToString() : string {
$"$ToneVal\t$DurVal" }
}
def mary = [ Note(Tone.B, Duration.QUARTER),
Note(Tone.A, Duration.QUARTER),
Note(Tone.GbelowC, Duration.QUARTER),
Note(Tone.A, Duration.QUARTER),
Note(Tone.B, Duration.QUARTER),
Note(Tone.B, Duration.QUARTER),
Note(Tone.B, Duration.HALF),
Note(Tone.A, Duration.QUARTER),
Note(Tone.A, Duration.QUARTER),
Note(Tone.A, Duration.HALF),
Note(Tone.B, Duration.QUARTER),
Note(Tone.D, Duration.QUARTER),
Note(Tone.D, Duration.HALF)];
def Play(notes) {
foreach(n in notes) {
WriteLine(n);
if (n.ToneVal == Tone.REST)
Thread.Sleep(n.ToneVal :> int)
else
Beep(n.ToneVal :> int, n.DurVal :> int)
}
};
def play = async {
await Task.Run(fun () {Play(mary);});
};
WriteLine("Sync");
while(!play.IsCompleted)
Thread.Sleep(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment