User Tools

Site Tools


ch2_3_pack_sym

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ch2_3_pack_sym [2021/04/22 01:42] adminch2_3_pack_sym [2025/01/29 08:35] (current) admin
Line 24: Line 24:
 </code> </code>
  
-FIND-SYMBOL+''FIND-SYMBOL''
  
-MAKE-SYMBOL+Finds symbol by name in a package. Expects one string argument the symbol name - and optional argument which is a package designator. Package designator can be string or symbol or package object itself. If the package name is not supplied, dynamic current package is used. Returns the symbol if it is found, otherwise ''NIL''. If it is found, also prints the symbol's relation to the package. As in Common LISP, this function returns two values, the second is a keyword which characterizes the relation.
  
-INTERN+<code lisp> 
 +>(find-symbol "PI"           ; USER package will be searched 
 +PI 
 +:INHERITED                     ; it is inherited from base package LABLISP
  
-SYMBOL-PACKAGE+>(find-symbol "PI" "LABLISP" ; now we search in LABLISP package 
 +PI 
 +:EXTERNAL                      ; there the symbol is external 
 +</code>
  
-PACKAGE-NAME+It is prefered to call the packages by string names, when we explicitly know it. It is also possible to use a symbol, with the name same as the name of the package. But it is important to know that the package is not bound to the symbol.
  
-FIND-PACKAGE, MAKE-PACKAGE, IN-PACKAGE, LIST-ALL-PACKAGES, USE-PACKAGE, UNUSE-PACKAGE+<code lisp> 
 +(find-symbol "PI" 'user)      ; USER package will be searched as above 
 +</code>
  
-IMPORTEXPORTUNINTERN, UNEXPORT+The name of the symbol ''USER'' names existing packagebut as a byproductwe created a new symbol ''USER'' and interned it in "USER" package. Using symbols as package designators might lead to confussion as to where the symbol is actually interned (see below ''INTERN''
  
-PACKAGE-USE-LIST. PACKAGE-USED-BY-LIST, PACKAGE-INTERNAL-SYMBOLS, PACKAGE-EXTERNAL-SYMBOLS, +<code lisp> 
 +(find-symbol "PI" *PACKAGE*)  ; *PACKAGE* is global variable  
 +</code> 
 + 
 +Here the symbol ''*PACKAGE*'' is evaluated to the dynamic current package. So the last example is identical to call the function without the optional package argument.  
 +   
 +''MAKE-SYMBOL'' 
 + 
 +Creates new symbol with given name, outside of any package (homeless). Expects one string argument. 
 + 
 +<code lisp> 
 +>(make-symbol "BLA"       
 +#:BLA                      ; the prefix means that the symbol is homeless  
 +</code> 
 + 
 +The example above creates the symbol, it is returned, but then it is discrded, because it has no owner and no binding. 
 + 
 +''INTERN'' 
 + 
 +Like ''FIND-SYMBOL'', looks up symbol by name in a package, and returns it the same way as ''FIND-SYMBOL''. But  when it is not present, it makes a new symbol with the package as owner. Expects one string argument - the symbol name - and optional argument which is a package designator. Returns two values, like ''FIND-SYMBOL''
 + 
 +<code lisp> 
 +>(intern "BLA"      ; without the package designator give, will use USER package 
 +BLA 
 +NIL                   ; NIL means that it is a new symbol 
 + 
 +>(intern "BLA"      ; we can call it again, for USER package 
 +BLA 
 +:INTERNAL             ; now it is already present as internal symbol 
 +</code> 
 + 
 +''SYMBOL-PACKAGE'' 
 + 
 +Expects single argument that must be symbol. Returns the symbol's home package - the package where the symbol was interned. 
 + 
 +<code lisp> 
 +>(symbol-package 'pi) 
 +#<The LABLISP package> 
 +</code> 
 + 
 +''PACKAGE-NAME'' 
 + 
 +Expects single argument that must be package object. Returns the name as string. 
 + 
 +<code lisp> 
 +>(package-name *package*) 
 +"USER" 
 +</code> 
 + 
 +''FIND-PACKAGE'' 
 + 
 +Expects one argument that must be package designator. Package designator can be string or symbol or package object itself. Returns the package object, if it exists. 
 + 
 +<code lisp> 
 +>(find-package "USER"
 +#<The USER package> 
 +</code> 
 + 
 +''MAKE-PACKAGE'' 
 + 
 +Expects single argument that must be string. Creates and returns new package with that name, unless it already exists - in that case complains and returns ''NIL''. New package always uses the LabLisp base package ''LABLISP'', see below: ''USE-PACKAGE''
 + 
 +<code lisp> 
 +>(make-package "P1"
 +#<The P1 package> 
 +</code> 
 + 
 +''IN-PACKAGE'' 
 + 
 +Expects single argument that must be string. Switches the current package (dynamic variable ''*PACKAGE*'') to the package named by the string - if it exists - and returns the package. 
 + 
 +<code lisp> 
 +>(in-package "P1"   ; assuming we made the P1 package in previous example 
 +#<The P1 package> 
 +</code> 
 + 
 +''LIST-ALL-PACKAGES'' 
 + 
 +No arguments, returns list of all packages in the environment. 
 + 
 +<code lisp> 
 +>(list-all-packages)     
 +(#<The USER package> #<The LABLISP package> #<The KEYWORD package> ; vanilla lablisp environment 
 +</code> 
 + 
 +''USE-PACKAGE'' 
 + 
 +Adds one or more packages to be used by a target package. Exported symbols from the source package(s), will be accessible through the target package. First argument is package designator or list of package designators. Second argument is optional target package designator, default is the dynamic current package.((dynamic current package means package bound to *PACKAGE* symbol in dynamic environment))  
 + 
 +Beware of name conflicts! 
 + 
 +<code lisp> 
 +>(use-package "P1" "P2"    ; use P1 in P2  
 +
 +</code> 
 + 
 +''UNUSE-PACKAGE'' 
 + 
 +Removes one or more packages from a target package's use list. First argument is package designator or list of package designators to be removed. Second argument is optional target package designator, default is the dynamic current package.  
 + 
 +<code lisp> 
 +>(unuse-package "P1" "P2"  ; stop using P1 in P2  
 +
 +</code> 
 + 
 +''PACKAGE-USE-LIST'' 
 + 
 +Lists all packages that are used by a target package. Single argument is target package designator. The argument is optional, defaults to the dynamic current package.  
 + 
 +Following two examples assume the situation after the ''USE-PACKAGE'' example above. 
 + 
 +<code lisp> 
 +>(package-use-list "P2"                       
 +(#<The P1 package> #<The LABLISP package>   ; any new package has access to base lablisp 
 +</code> 
 + 
 +''PACKAGE-USED-BY-LIST'' 
 + 
 +Lists all packages that use a target package. Single argument is target package designator. The argument is optionaldefaults to the dynamic current package.  
 + 
 +<code lisp> 
 +>(package-used-by-list "P1"
 +(#<The P2 package>            ; package P1 is used by P2 
 +</code> 
 + 
 + 
 +''IMPORT'' 
 + 
 +Symbol becomes internal of the target package, if the symbol was //homeless//, the target package becomes symbol's home package. First argument is symbol or list of symbols. Second argument is optional target package designator, default is the dynamic current package. 
 + 
 +Beware of name conflicts! 
 + 
 + 
 +''UNINTERN'' 
 + 
 +Removes symbol from package, so it is no longer accessible as internal or external symbol. If the package is the symbol's home pacakge, then the symbol becomes //homeless//. First argument is symbol or list of symbols. Second argument is optional target package designator, default is the dynamic current package. 
 + 
 +The name ''UNINTERN'' is slightly misleading, the command is mostly used to revert ''IMPORT'', but it revets ''INTERN'' as well. 
 + 
 +''EXPORT'' 
 + 
 +Makes inherited or internal symbol to be external in given package. If the symbol is inherited, ''EXPORT'' will first ''IMPORT'' the symbol, them move from internal list to external list. First argument is symbol or list of symbols. Second argument is optional target package designator, default is the dynamic current package. 
 + 
 +Beware of name conflicts! 
 + 
 +''UNEXPORT'' 
 + 
 +Undoes ''EXPORT'', moves symbol from external list to internal list. First argument is symbol or list of symbols. Second argument is optional target package designator, default is the dynamic current package. 
 + 
 +''PACKAGE-INTERNAL-SYMBOLS'' 
 + 
 +Lists all internal symbols of a target package. Single argument is target package designator. The argument is optionaldefaults to the dynamic current package.  
 + 
 +''PACKAGE-EXTERNAL-SYMBOLS''  
 + 
 +Lists all external symbols of a target package. Single argument is target package designator. The argument is optionaldefaults to the dynamic current package. 
  
  
  
  
ch2_3_pack_sym.1619077375.txt.gz · Last modified: 2021/04/22 01:42 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki