From 6d79ccffe9f5de6e733d214f46f54e76367973c3 Mon Sep 17 00:00:00 2001 From: sveta Date: Fri, 19 Apr 2024 12:30:51 +0300 Subject: [PATCH] changes for Kwargs --- python/hyperon/atoms.py | 9 ++++++++- python/hyperon/stdlib.py | 9 +-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/python/hyperon/atoms.py b/python/hyperon/atoms.py index 7d065860a..1c98d9c6c 100644 --- a/python/hyperon/atoms.py +++ b/python/hyperon/atoms.py @@ -383,7 +383,7 @@ def execute(self, *atoms, res_typ=AtomType.UNDEFINED): except: raise RuntimeError(f"Incorrect kwarg format {kwarg}") try: - kwargs[repr(kwarg[0])] = kwarg[1].get_object().content + kwargs[get_string_value(kwarg[0])] = kwarg[1].get_object().content except: raise NoReduceError() continue @@ -705,3 +705,10 @@ def iterator(self): for r in res: result.append(Bindings(r)) return iter(result) + +def get_string_value(value) -> str: + if not isinstance(value, str): + value = repr(value) + if len(value) > 2 and ("\"" == value[0]) and ("\"" == value[-1]): + return value[1:-1] + return value diff --git a/python/hyperon/stdlib.py b/python/hyperon/stdlib.py index a35142ab3..fc9f2a437 100644 --- a/python/hyperon/stdlib.py +++ b/python/hyperon/stdlib.py @@ -3,7 +3,7 @@ import os from .atoms import ExpressionAtom, E, GroundedAtom, OperationAtom, ValueAtom, NoReduceError, AtomType, MatchableObject, \ - G, S, Atoms + G, S, Atoms, get_string_value from .base import Tokenizer, SExprParser from .ext import register_atoms, register_tokens import hyperonpy as hp @@ -63,13 +63,6 @@ def bool_ops(): r"not": notAtom } -def get_string_value(value) -> str: - if not isinstance(value, str): - value = repr(value) - if len(value) > 2 and ("\"" == value[0]) and ("\"" == value[-1]): - return value[1:-1] - return value - class RegexMatchableObject(MatchableObject): ''' To match atoms with regular expressions'''