Created
July 1, 2020 13:15
-
-
Save altbodhi/1261607dd5e5566c21d5878ae7c41117 to your computer and use it in GitHub Desktop.
Nemerle Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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