Exemplo n.º 1
0
    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())
Exemplo n.º 2
0
    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'))
Exemplo n.º 3
0
    def __call__(self, forms, var_env, func_env, macro_env):
        """Behavior of ExportSystemFunction.
        """
        args = self.eval_forms(forms, var_env, func_env, macro_env)

        symbol_designator = args.car
        package_designator = args.cdr.car

        # Checks package_designator whether it is given or not.
        if package_designator is Null():
            package_designator = None

        if isinstance(symbol_designator, Cons):
            # If symbol_designator is symbol list, exports all symbols.
            while symbol_designator.cdr is not Null():
                PackageManager.export(symbol_designator=symbol_designator.car, package_designator=package_designator)
                symbol_designator = symbol_designator.cdr

            # The last symbol.
            return PackageManager.export(symbol_designator=symbol_designator.car, package_designator=package_designator)

        else:
            return PackageManager.export(symbol_designator=symbol_designator, package_designator=package_designator)