def testPackageManager_import(self): # PackageManager.import_ imports symbol to symbol container of the specific package. # The package_name argument is omitted, # the method imports symbol to PackageManager.current_package.symbol_container. # IMPORT is interned to PakageManager.package_container['COMMON-LISP-USER']. PackageManager.intern(symbol_designator=String('IMPORT'), package_designator=String('COMMON-LISP-USER')) # Add value to the variable space. PackageManager.package_container['COMMON-LISP-USER'].env['VARIABLE']['IMPORT'] = String('VALUE') PackageManager.import_(symbol_designator=Symbol('COMMON-LISP-USER::IMPORT')) symbol, status = PackageManager.find_symbol(symbol_designator=String('IMPORT')) self.assertTrue(symbol is Symbol('IMPORT')) self.assertTrue(status is Keyword(':INTERNAL')) self.assertTrue(PackageManager.current_package.env['VARIABLE']['IMPORT'] is String('VALUE')) # The package_designator argument is supplied to the specified package. # IMPORT-WITH-PACKAGE is interned to COMMON-LISP package. PackageManager.intern(symbol_designator=String('IMPORT-WITH-PACKAGE'), package_designator=String('COMMON-LISP')) # Add value to the variable space. PackageManager.package_container['COMMON-LISP'].env['VARIABLE']['IMPORT-WITH-PACKAGE'] = String('VALUE') PackageManager.import_(symbol_designator=Symbol('COMMON-LISP::IMPORT-WITH-PACKAGE'), package_designator=Symbol('COMMON-LISP-USER')) symbol, status = PackageManager.find_symbol(symbol_designator=String('IMPORT-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Symbol('IMPORT-WITH-PACKAGE')) self.assertTrue(status is Keyword(':INTERNAL')) self.assertTrue(PackageManager.package_container['COMMON-LISP-USER'].env['VARIABLE']['IMPORT-WITH-PACKAGE'] is String('VALUE'))
def testPackageManager_find_symbol(self): # PackageManager.find_symbol returns symbol represented by symbol_designator and status. # The package_designator argument is omitted, # PackageManager.current_package.symbol_container is checked. # FIND-SYMBOL is interned to PackageManager.current_package in advance. PackageManager.intern(symbol_designator=String('FIND-SYMBOL')) symbol, status = PackageManager.find_symbol(symbol_designator=String('FIND-SYMBOL')) self.assertTrue(symbol is Symbol('FIND-SYMBOL')) self.assertTrue(status, Keyword(':INTERNAL')) # If symbol_designator dose not exist in PackageManager.current_package, # it must return Null object as symbol and status. symbol, status = PackageManager.find_symbol(symbol_designator=String('FIND-SYMBOL-NOT-EXIST')) self.assertTrue(symbol is Null()) self.assertTrue(status is Null()) # The package_designator argument is supplied to the specified package. # FIND-SYMBOL-WITH-PACKAGE is interned to COMMON-LISP-USER package in advance. PackageManager.intern(symbol_designator=String('FIND-SYMBOL-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) symbol, status = PackageManager.find_symbol(symbol_designator=String('FIND-SYMBOL-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Symbol('FIND-SYMBOL-WITH-PACKAGE')) self.assertTrue(status is Keyword(':INTERNAL')) # If symbol_designator dose not exist in the specified package, # it must return Null object as symbol and status. symbol, status = PackageManager.find_symbol(symbol_designator=String('FIND-SYMBOL-WITH-PACKAGE-NOT-EXIST'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Null()) self.assertTrue(status is Null())
def use_package_helper(package_name_to_use, package_name): """Import helper function. Other modules use this function to import symbol from original package. Args: symbol_name: str. A symbol name that include package (for example `COMMON-LISP::CAR`). package_name: str. A package name that import symbol indicated by a symbol name. """ PackageManager.use_package(Symbol(package_name_to_use), Symbol(package_name))
def expand_hepler(cls, forms): """Expand quotes recursively. """ if not isinstance(forms, Cons): # An argument is not an instance of Cons, it is quoted. return Cons(Symbol('QUOTE'), Cons(forms, Null())) if forms.car is Symbol('UNQUOTE'): # Unquote (,). return forms.cdr.car elif isinstance(forms.car, Cons) and forms.car.car is Symbol('UNQUOTE-SPLICING'): # Unquote-splicing (,@). return Cons(Symbol('APPEND'), Cons(forms.car.cdr.car, Cons(cls.expand_hepler(forms.cdr), Null()))) else: # Expands recursively and returns cons. return Cons(Symbol('CONS'), Cons(cls.expand_hepler(forms.car), Cons(cls.expand_hepler(forms.cdr), Null())))
def testPackageManager_in_package(self): # PackageManager.in_package changes PackageManager.current_package to package_designator. # PackageManager.current_package is chenged to COMMON-LISP-USER. PackageManager.in_package(package_designator=Symbol('COMMON-LISP-USER')) # Check PackageManager.current_package and *PACKAGE* variable in COMMON-LISP package. self.assertTrue(PackageManager.current_package is PackageManager.package_container['COMMON-LISP-USER']) self.assertTrue(PackageManager.package_container['COMMON-LISP'].env['VARIABLE']['*PACKAGE*'] is PackageManager.current_package) # PackageManager.current_package is chenged to COMMON-LISP as default for other tests. PackageManager.in_package(package_designator=Symbol('COMMON-LISP'))
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of LambdaSystemMacro. """ from clispy.expander import Expander params, body = forms.car, forms.cdr # Expands body recursively. body = Expander.expand(body, var_env, func_env, macro_env) # The body of a lambda has an implicit progn. forms = Cons(Symbol('LAMBDA'), Cons(params, Cons(Cons(Symbol('PROGN'), body), Null()))) return forms
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of BlockSystemMacro. """ from clispy.expander import Expander name, body = forms.car, forms.cdr # Expands body recursively. body = Expander.expand(body, var_env, func_env, macro_env) # The body of a block has an implicit progn. forms = Cons(Symbol('BLOCK'), Cons(name, Cons(Cons(Symbol('PROGN'), body), Null()))) return forms
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of FletSystemMacro. """ from clispy.expander import Expander bindings, body = forms.car, forms.cdr # Expands body recursively. body = Expander.expand(body, var_env, macro_env, macro_env) # The body of flet has an implicit progn. forms = Cons(Symbol('FLET'), Cons(bindings, Cons(Cons(Symbol('PROGN'), body), Null()))) return forms
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of FletSpecialOperator. """ from clispy.evaluator import Evaluator bindings, body = forms.car, forms.cdr.car funcs = [] exps = [] while bindings is not Null(): func, exp = bindings.car.car, bindings.car.cdr # Interns symbol that represents function name into current package. PackageManager.intern(String(func.value)) funcs.append(func.value) exp = Cons(Symbol('LAMBDA'), exp) # The scope of the name bindings dose not encompasse the function definitions. exps.append(Evaluator.eval(exp, var_env, func_env, macro_env)) bindings = bindings.cdr # The bindings are in parallel. func_env = func_env.extend(params=funcs, args=exps) return Evaluator.eval(body, var_env, func_env, macro_env)
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of FletSpecialOperator. """ from clispy.evaluator import Evaluator bindings, body = forms.car, forms.cdr.car funcs = [] exps = [] # For encompassing the function definitions themselves, # a function environment is extended in advance. local_func_env = func_env.extend() while bindings is not Null(): func, exp = bindings.car.car, bindings.car.cdr # Interns symbol that represents function name into current package. PackageManager.intern(String(func.value)) funcs.append(func.value) exp = Cons(Symbol('LAMBDA'), exp) # The scope of the name bindings encompasses the function definitions # themselves as well as the body. exps.append(Evaluator.eval(exp, var_env, local_func_env, macro_env)) bindings = bindings.cdr # The bindings are in parallel. local_func_env.update(zip(funcs, exps)) return Evaluator.eval(body, var_env, local_func_env, macro_env)
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of DefmacroSystemMacro. """ from clispy.expander import Expander name, params, body = forms.car, forms.cdr.car, forms.cdr.cdr # Expands body, recursively. body = Expander.expand(body, var_env, func_env, macro_env) # The value of the last form executed is returned as the expansion of the macro. body = Cons(Cons(Symbol('PROGN'), body), Null()) # The body of a defmacro has an implicit block. forms = Cons(Symbol('DEFMACRO'), Cons(name, Cons(params, Cons(Cons(Symbol('BLOCK'), Cons(name, body)), Null())))) return forms
def testPackageManager_get_package_name(self): # PackageManager.get_package_name returns package name represented by package_designator. # IF package_designator is None, it returns None. self.assertTrue(PackageManager.get_package_name(package_designator=None) is None) # Then package_designator is String or Symbol, it returns package name. self.assertTrue(PackageManager.get_package_name(String('COMMON-LISP')) is 'COMMON-LISP') self.assertTrue(PackageManager.get_package_name(Symbol('COMMON-LISP')) is 'COMMON-LISP')
def testPackageManager_intern(self): # PackageManager.intern interns symbol_designator to Package.symbol_container. # The package_designator argument is omitted, # symbol_designator is interned to PackageManager.current_package.symbol_container. symbol, status = PackageManager.intern(symbol_designator=String('TEST-INTERN')) self.assertTrue(symbol is Symbol('TEST-INTERN')) self.assertTrue(status is Null()) self.assertTrue('TEST-INTERN' in PackageManager.current_package.symbol_container.keys()) self.assertEqual(PackageManager.current_package.symbol_container['TEST-INTERN'], [Symbol('TEST-INTERN'), Keyword(':INTERNAL'), None]) # The package_designator argument is supplied to the specified package. symbol, status = PackageManager.intern(symbol_designator=String('INTERN-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Symbol('INTERN-WITH-PACKAGE')) self.assertTrue(status is Null()) self.assertTrue('INTERN-WITH-PACKAGE' in PackageManager.package_container['COMMON-LISP-USER'].symbol_container.keys()) self.assertEqual(PackageManager.package_container['COMMON-LISP-USER'].symbol_container['INTERN-WITH-PACKAGE'], [Symbol('INTERN-WITH-PACKAGE'), Keyword(':INTERNAL'), None])
def assign_helper(symbol_name, value, package_name, env='VARIABLE', status=':INTERNAL'): """Assign helper function. Other modules use this function to assign value. Args: symbol_name: str. A symbol name. value: mix. An assigned value. package_name: str. A package name. env: str. An environment is selected from 'VARIABLE', 'FUNCTION' or 'MACRO'. status: str. A status is selected from ':INTERNAL' or ':EXTERNAL' """ PackageManager.intern(String(symbol_name), String(package_name)) PackageManager.package_container[package_name].env[env][ symbol_name] = value if status == ':EXTERNAL': PackageManager.export(Symbol(symbol_name), Symbol(package_name))
def testPackageManager_export(self): # PackageManager.export changes symbol status in symbol container to :EXTERNAL. # The package_designator argument is omitted, # status in PackageManager.current_package.symbol_container is changed. # EXPORT is interned to PackageManager.current_package in advance. PackageManager.intern(symbol_designator=String('EXPORT')) PackageManager.export(symbol_designator=Symbol('EXPORT')) symbol, status = PackageManager.find_symbol(symbol_designator=String('EXPORT')) self.assertTrue(symbol is Symbol('EXPORT')) self.assertTrue(status is Keyword(':EXTERNAL')) # The package_designator argument is supplied to the specified package. # EXPORT-WITH-PACKAGE is interned to COMMON-LISP-USER pacakge in advance. PackageManager.intern(symbol_designator=String('EXPORT-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) PackageManager.export(symbol_designator=Symbol('EXPORT-WITH-PACKAGE'), package_designator=Symbol('COMMON-LISP-USER')) symbol, status = PackageManager.find_symbol(symbol_designator=String('EXPORT-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Symbol('EXPORT-WITH-PACKAGE')) self.assertTrue(status is Keyword(':EXTERNAL'))
def import_(cls, symbol_designator, package_designator=None): """Import adds symbol or symbols to the internals of package, checking for name conflicts with existing symbols either present in package or accessible to it. Once the symbols have been imported, they may be referenced in the importing package without the use of a package prefix when using the Lisp reader. Args: symbol_designator: Symbol. a symbol name. package_designator: Symbol. a package name that imports symbol represented symbol_name. Retruns: T """ # Get symbol_name and package_name. symbol_name = symbol_designator.value package_name = cls.get_package_name(package_designator) # Split and get symbol_name, base_package_name and status_check. symbol_name, base_package_name, status_check = cls.split_symbol_name( symbol_name) # Get base package instance. The default is the current package. base_package = cls.get_package(base_package_name) # Get package instance. The default is the current package. package = cls.get_package(package_name) # Check symbol status. _, status, _ = base_package.symbol_container.find( symbol_name)[symbol_name] if status_check and (status is not Keyword(':EXTERNAL')): raise PackageError('The symbol ' + symbol_name + ' is not external in the ' + package_name + ' package.') # Import symbol and value. package.symbol_container[symbol_name] = [ Symbol(symbol_name), Keyword(':INTERNAL'), None ] try: package.env['VARIABLE'][symbol_name] = base_package.env[ 'VARIABLE'].find(symbol_name)[symbol_name] except LookupError: try: package.env['FUNCTION'][symbol_name] = base_package.env[ 'FUNCTION'].find(symbol_name)[symbol_name] except LookupError: package.env['MACRO'][symbol_name] = base_package.env[ 'MACRO'].find(symbol_name)[symbol_name] return T()
def testInternSystemFunction_call(self): # Make an instance of InternSystemFunction. intern_ = InternSystemFunction() # Calls intern_. forms = Parser.parse('("G1")') retval = intern_(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk return value. self.assertEqual(retval[0], Symbol('G1')) self.assertEqual(retval[1], Null()) # Second calls intern_. forms = Parser.parse('("G1")') retval = intern_(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk second return value. self.assertEqual(retval[0], Symbol('G1')) self.assertEqual(retval[1], Keyword(':INTERNAL'))
def testFindSystemFunction_call_existed_symbol(self): # Make an instance of FindSymbolSystemFunction. find_symbol = FindSymbolSystemFunction() # Calls find_symbol. forms = Parser.parse('("CAR")') retval = find_symbol(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk return value. self.assertEqual(retval[0], Symbol('CAR')) self.assertEqual(retval[1], Keyword(':EXTERNAL'))
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of IfSystemMacro. """ from clispy.expander import Expander # If else_form is Null, then else_form is set to Null. test_form, then_form, else_form = forms.car, forms.cdr.car, forms.cdr.cdr.car # Expands body recursively. test_form = Expander.expand(test_form, var_env, func_env, macro_env) then_form = Expander.expand(then_form, var_env, func_env, macro_env) else_form = Expander.expand(else_form, var_env, func_env, macro_env) forms = Cons(Symbol('IF'), Cons(test_form, Cons(then_form, Cons(else_form, Null())))) return forms
def testExportSystemFunction_call(self): # Make an instance of FindSymbolSystemFunction, InternSystemFunction # and ExportSystemFunction. find_symbol = FindSymbolSystemFunction() intern_ = InternSystemFunction() export = ExportSystemFunction() # Calls intern_. forms = Parser.parse('("G2")') retval = intern_(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk return value. self.assertEqual(retval[0], Symbol('G2')) self.assertEqual(retval[1], Null()) # Calls export. forms = Parser.parse("('G2)") retval = export(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk return value. self.assertEqual(retval, T()) # Calls find_symbol. forms = Parser.parse('("G2")') retval = find_symbol(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Chesk return value. self.assertEqual(retval[0], Symbol('G2')) self.assertEqual(retval[1], Keyword(':EXTERNAL'))
def intern(cls, symbol_designator, package_designator=None): """The first value returned by intern, symbol_designator, is the symbol that was found or created. The meaning of the secondary value, status, is as follows: :INTERNAL The symbol was found and is present in package as an internal symbol. :EXTERNAL The symbol was found and is present as an external symbol. :INHERITED' The symbol was found and is inherited via use-package (which implies that the symbol is internal). nil No pre-existing symbol was found, so one was created. Args: symbol_designator: String. a symbol name. package_designator: String. a package name. Returns: (Symbol, Keyword) """ # Get symbol_name and package_name. symbol_name = symbol_designator.value package_name = cls.get_package_name(package_designator) # Get package. The default is the current package. package = cls.get_package(package_name) # Check whether symbol already exists or not. # If symbol is not exist, Add symbol to package.symbol_container. if symbol_name in package.symbol_container.keys(): symbol, status, _ = package.symbol_container.find( symbol_name)[symbol_name] return symbol, status else: symbol = Symbol(symbol_name) status = Keyword(':INTERNAL') try: package.symbol_container.find(symbol_name)[symbol_name] = [ symbol, status, None ] except LookupError: package.symbol_container[symbol_name] = [symbol, status, None] # (intern "Never-Before") => |Never-Before|, NIL return symbol, Null()
def test_eval_forms(self): forms = Parser.parse("(1 'hoge \"fuga\")") # Evaluates forms args = SystemFunction.eval_forms( forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO'], ) # Checks type of args. self.assertIsInstance(args, Cons) # Checks args self.assertTrue(args.car is Integer(1)) self.assertTrue(args.cdr.car is Symbol('HOGE')) self.assertTrue(args.cdr.cdr.car is String('fuga')) self.assertTrue(args.cdr.cdr.cdr is Null())
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of FunctionSpecialOperator. """ if isinstance(forms.car, Cons) and forms.car.car is Symbol('LAMBDA'): return Lambda(forms.car.cdr, var_env, func_env, macro_env) else: # Gets symbol_name, package_name, and status_check. func_name, package_name, status_check = PackageManager.split_symbol_name( forms.car.value) # Gets the function binded by the symbol. try: # First, tries to get the value from lexical environment. return func_env.find(func_name)[func_name] except LookupError: # If LookupError is raised, tries to get from another package. return PackageManager.find(func_name, package_name, status_check, env='FUNCTION')[func_name]
def testDefunSytemFunction_call(self): # Makes an instance of DefunSystemFunction. defun = DefunSystemFunction() # Calls defun. forms = Parser.parse('(func (x) (* x x x))') retval = defun(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Checks retval. self.assertEqual(retval, Symbol('FUNC')) # Gets function object. func = PackageManager.find('FUNC', package_name=None, status_check=False, env='FUNCTION')['FUNC'] # Checks type. self.assertIsInstance(func, Lambda)
def testDefmacroSystemFunction_call(self): # Makes an instance of DefmacroSystemFunction. defmacro = DefmacroSystemFunction() # Calls defmacro. forms = Parser.parse('(mac (x) `(* ,x ,x ,x))') retval = defmacro(forms, PackageManager.current_package.env['VARIABLE'], PackageManager.current_package.env['FUNCTION'], PackageManager.current_package.env['MACRO']) # Checks retval. self.assertTrue(retval, Symbol('MACRO')) # Gets macro object. mac = PackageManager.find('MAC', package_name=None, status_check=False, env='MACRO')['MAC'] # Checks type. self.assertIsInstance(mac, Lambda)
def testPackageManager_use_package(self): # PackageManager.use_package inherited symbol in package_designator_to_use. # The package_designator argument is omitted, # symbol is inherited, and interned to PackageManager.current_package.symbol_container. # USE-PACKAGE-INTERNAL and USE-PACKAGE-EXTERNAL are interned to COMMON-LISP-USER. PackageManager.intern(symbol_designator=String('USE-PACKAGE-INTERNAL'), package_designator=String('COMMON-LISP-USER')) PackageManager.intern(symbol_designator=String('USE-PACKAGE-EXTERNAL'), package_designator=String('COMMON-LISP-USER')) # Only status of USE-PACKAGE-EXTERNAL is changed to :EXTERNAL. PackageManager.export(symbol_designator=Symbol('USE-PACKAGE-EXTERNAL'), package_designator=Symbol('COMMON-LISP-USER')) PackageManager.use_package(package_designator_to_use=Symbol('COMMON-LISP-USER')) # When status is :EXTERNAL, the symbol is inherited. symbol, status = PackageManager.find_symbol(symbol_designator=String('USE-PACKAGE-EXTERNAL')) self.assertTrue(symbol is Symbol('USE-PACKAGE-EXTERNAL')) self.assertTrue(status is Keyword(':INHERITED')) # When statis is not :EXTERNAL, the symbol is not inherited. symbol, status = PackageManager.find_symbol(symbol_designator=String('USE-PACKAGE-INTERNAL')) self.assertTrue(symbol is Null()) self.assertTrue(status is Null()) # The package_designator argument is supplied to the specified package. # USE-PACKAGE-INTERNAL-WITH-PACKAGE and USE-PACKAGE-EXTERNAL-WITH-PACKAGE are interned to COMMON-LISP. PackageManager.intern(String('USE-PACKAGE-INTERNAL-WITH-PACKAGE')) PackageManager.intern(String('USE-PACKAGE-EXTERNAL-WITH-PACKAGE')) # Only status of USE-PACKAGE-EXTERNAL-WITH-PACKAGE is changed to :EXTERNAL. PackageManager.export(Symbol('USE-PACKAGE-EXTERNAL-WITH-PACKAGE')) PackageManager.use_package(package_designator_to_use=Symbol('COMMON-LISP'), package_designator=Symbol('COMMON-LISP-USER')) # When status is :EXTERNAL, the symbol is inherited. symbol, status = PackageManager.find_symbol(symbol_designator=String('USE-PACKAGE-EXTERNAL-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Symbol('USE-PACKAGE-EXTERNAL-WITH-PACKAGE')) self.assertTrue(status is Keyword(':INHERITED')) # When statis is not :EXTERNAL, the symbol is not inherited. symbol, status = PackageManager.find_symbol(symbol_designator=String('USE-PACKAGE-INTERNAL-WITH-PACKAGE'), package_designator=String('COMMON-LISP-USER')) self.assertTrue(symbol is Null()) self.assertTrue(status is Null())
def type_of(cls): """Returns a type specifier for a type that has the objects as an element. """ return Symbol('FUNCTION')
def repl(cls, prompt='=>', inport=InPort(sys.stdin), out=sys.stdout, zen=True): PackageManager.in_package(String("COMMON-LISP-USER")) while True: try: if prompt is not None: # Set prompt. try: prompt = PackageManager.current_package.package_nicknames[ 0] + '=>' except IndexError: prompt = PackageManager.current_package.package_name + '=>' # Wait input. print(prompt, end=' ', file=out, flush=True) # Parse inport. forms = Parser.parse(inport) # Check eof. if forms is Symbol('#<EOF-OJBECT>'): return # Expand token. forms = Expander.expand( forms, var_env=PackageManager.current_package.env['VARIABLE'], func_env=PackageManager.current_package.env['FUNCTION'], macro_env=PackageManager.current_package.env['MACRO']) # Evaluate expression. retval = Evaluator.eval( forms, var_env=PackageManager.current_package.env['VARIABLE'], func_env=PackageManager.current_package.env['FUNCTION'], macro_env=PackageManager.current_package.env['MACRO']) # Print return value. if out is not None: print(retval, end="\n\n", file=out, flush=True) except Interrupt: if zen: # Print the zen of python at random. print(random.choices(cls.the_zen_of_python)[0], end="\n\n", file=out, flush=True) return except Exception as e: print( "------------------------------------------------------------" ) print("{}: {}".format(type(e).__name__, e), end="\n\n", file=out, flush=True)
def __call__(self, forms, var_env, func_env, macro_env): """Behavior of QuoteSystemMacro. """ # Retruns itself. return Cons(Symbol('QUOTE'), forms)