From ac1b2333867b68a67210e27f9aa9de89c38862e9 Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 29 Jul 2022 19:03:50 +0000 Subject: implement string->float --- neb/std/types.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'neb') diff --git a/neb/std/types.py b/neb/std/types.py index cc40066..44906d8 100644 --- a/neb/std/types.py +++ b/neb/std/types.py @@ -108,6 +108,18 @@ stringtoint_multi = MultiFunction("string->int") stringtoint_multi.register(stringtoint_func) TYPES.register("string->int", stringtoint_multi) +def interpretStringToFloat(symbol, args, env, ns): + try: + val = float(args[0].value) + return Float(val) + except: + raise InterpretPanic(symbol, "can't convert to a :float", args[0]) + +stringtofloat_func = Builtin("string->float", interpretStringToFloat, [Arg("arg", TypeEnum.STRING)], return_type=Type(":float")) +stringtofloat_multi = MultiFunction("string->float") +stringtofloat_multi.register(stringtofloat_func) +TYPES.register("string->float", stringtofloat_multi) + def interpretToString(symbol, args, env, ns): item = args[0] if isinstance(item, String): -- cgit v1.2.3