Skip to content

Instantly share code, notes, and snippets.

@porky11
Created August 26, 2019 13:22
Show Gist options
  • Save porky11/b84e704692eef2f96c513a1bfb049d4f to your computer and use it in GitHub Desktop.
Save porky11/b84e704692eef2f96c513a1bfb049d4f to your computer and use it in GitHub Desktop.
Parsing arbitrary numbers types as values to specific number types
inline value-to-number-maker (number-type)
fn (value)
match ('typeof value)
case i8
number-type
value as i8
case i16
number-type
value as i16
case i32
number-type
value as i32
case i64
number-type
value as i64
case u8
number-type
value as u8
case u16
number-type
value as u16
case u32
number-type
value as u32
case u64
number-type
value as u64
case f32
number-type
value as f32
case f64
number-type
value as f64
default
error "value cannot be parsed as number"
let value-to-f32 =
value-to-number-maker f32
let x y z =
decons
(list-parse "1\n2.0\n3:u8") as list
3
let x y z =
va-map value-to-f32 x y z
print x "/" y "/" z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment