Symbols and Packages in Lisp
A lisp symbol is a data object that has three user-visible components:The property list is the list that effectively provides each symbol with many modifiable named components.The print name must be the  string, which is the sequence of characters used to identify the symbol.The package cell must refer to package object. A package is a data structure used to locate a symbol once given the symbols name.A symbol is uniquely identified by its name only when considered relative to a package.
overviewThe property ListThe Print nameCreating symbolsPackagesTranslating strings to SymbolsExport and import symbolsName conflictsBuilt-in packages
The property listA property list contains two or more entries, with each entry associated with the key called the indicator.A property list is very much similar to an association list in its purpose, but the difference is that a property list is an object with unique identity.A property list is implemented as a memory cell containing a list with even number(possibly zero) of elements. Each pair of elements in the list constitutes an entry: the first item is the indicator, the second item is the value.When the symbol is created its property list is initially empty, properties are created by using get within a set form.
get symbol indicator1 &optional defaultGet searches the property list of the symbol for an indicator eq to indicator1. if one is found, the corresponding value is returned, else default is returned.Suppose the property list of foo is ( bar t baz 3 hunoz “huh?”)Then ex: (get ‘foo ‘baz)3                     (get ‘foo ‘hunoz)”Huh?”                     (get ‘foo ‘Zoo) nil
remprop symbol indicator1This removes the symbol from the property with an indicator eq to indicator1.Suppose if property foo was (color blue height 6.3)After using (remprop ‘foo ‘height) the property becomes (color blue)Returns the list that contains the property pairs of the symbol, the contents of the property lists are extracted and returned.symbol-plist symbol
getf place indicator1 &optional defaultgetf searches for the property list stored in place for an indicator eq to indicator1, if found returns the corresponding value, else returns the default or nil.remf removes from the property list stored in the place the property with an indicator eq to indicator1 . The property indicator and the corresponding value are removed by destructively splicing the property list.remf place indicator1
get-properties place indicator-listget-properties searches the property list stored in place for any of the indicators in the indicator-list untill it finds the first property in the property list.Get-properties returns three values:The first two values are indicator and the value of the first property whose indicator was in indicator list.
The third is the tail of the property whose tail is the indicator.The Print NameEvery symbol has an associated string called the print name used for its external representation. returns the print name of the symbol syn.Ex: (symbol-name ‘xy) “XY”symbol-name syn
Creating SymbolsSymbols are used in two different ways:An interned symbol is one that is indexed by its print name in its catalog called a package.An uninterned symbol is one that is used simply as a data object with no special cataloguing.An uninterned symbol is printed with #: followed by its print name.make-symbol print-name  creates a new uninterned symbol whose print name is the string print-name.
copy-symbol sym &optional copy-props returns a new uninterented symbol with the same name as of the sym.If copy-props is non-nil, then the initial value and function definition of the new symbol will be the same as those of the sym, and the property list of the new symbol will be a copy of sym’s.gensym &optional  x gensym invents a print name and creates a new symbol with that print name. it returns new uninterented symbol.The invented new print name consists of a prefix( which defaults to G) , followed by decimal representation of a number.The number is increased by 1 every time gensym is called.
gentamp &optional prefix package gentemp like gensym, creates and returns new symbol. The only difference is gentemp interns the symbol in the package.Symbol-package sym  returns the contents of the package cell of that symbol. This will be a package object or nil.Keywordp object returns true if the argument is a symbol and that symbol is a keyword.
PackagesA package is a data structure that is used for mapping the print names (strings) to symbols.The string-to symbol mappings available in the given package are divided into two classes:  external( to be chosen carefully and are advertised to users of the package)
 internal( normally hidden from other packages).A symbol is said to be interned in a package if it is accessible in that package and also is owned.
Consistency rulesIn dealing with package system, it is useful to follow the consistency rules:Read-read consistency: reading the same print name always results in the same(eq) symbol.
Print-read consistency: An interned symbol always as a sequence of characters that, when read back in, yields the same (eq) symbol.
Print-print consistancy:if two interned symbols are not eq, then their printed representations will be different sequence of characters.Package namesEach package is assigned a name when it is created, though can be changed later.The function find-package translates a package name or nickname into associated package.The function package-name returns the name of the package.The function package-nicknames returns the list of all the nicknames for a package.
Translating strings to symbolsWhatever packet object is currently the value of *package* is referred to as current-package.When the lisp reader has obtained a string of characters thought to name a symbol, that name is looked up in the current package.If the name is found, the corresponding  symbol is returned, if the name is not found, a new  symbol is created for it and is placed in the current package as an internal symbol.External symbol in some other package is referred  through the qualified name, consisting of the package name, then a colon, then the name of the symbol.Ex:  editor: buffer refers to external symbol buffer accessible in the package named editor.
The following four symbol qualifying syntaxes are used:foo: bar look up bar among the external symbols of the package named foo, printed when the symbol bar is external in its home package foo and is not accessible in the current package.foo::bar interns bar as if foo is the current page,  printed when symbol bar is internal in its home page foo, and is not accessible in the current page.:bar interns bar as the external symbol in the keyword package and makes it evaluate to itself. Printed if the home page of the symbol bar is keyword.#:bar creates a new uninterned symbol named BAR. Printed when the symbol BAR is uninterented(has no home package )
Exporting and Importing SymbolsSymbols from one package may be exported to imported from other packages by the use of functions export and import respectively.(import ‘editor:buffer) takes the external symbol named buffer in the editor package and adds it to the current package as an internal symbol.A symbol is said to be shadowed by another symbol in some package if the first symbol would be accessible by inheritance if not for the presence of the second symbol.
To import a symbol without the possibility of getting the error because of shadowing use the function shadowing-import.Use package causes a package to inherit all of the external symbols from some other package.Unlike import, use-package does not cause any of the new symbols to be present in the current package, but makes them accessible by inheritance.
The function export takes the symbol that is accessible in some specified package, and makes it an external symbol of that package.If the symbol is directly present as an internal symbol, the it is imply changed to external status.If the symbol is accessible via use-package, the symbol is first imported to the package and then exported.If the same name is being used more than once name-conflicts may occur, so care has to be taken to avoid any such name conflicts.
Built-in PackagesCommon lisp built-in packages:Lisp contains the primitives of the common lisp system.Its external symbols include all of the user defined functions such as car, car and *package*.user package is the current package at the time a Common Lisp system starts up. common-lisp package contains the primitives of the ANSI commomLisp system.common-lisp-user is by default the current package at the time, an ANSI common Lisp system starts up.

More Related Content

PPTX
Regular expressions in Python
PDF
Let’s Learn Python An introduction to Python
PPSX
Programming with Python
PDF
Python revision tour i
PDF
Syntax analysis
PPT
Introduction to Python - Part Two
PPTX
Chapter 9 python fundamentals
PPTX
11 Unit 1 Chapter 02 Python Fundamentals
Regular expressions in Python
Let’s Learn Python An introduction to Python
Programming with Python
Python revision tour i
Syntax analysis
Introduction to Python - Part Two
Chapter 9 python fundamentals
11 Unit 1 Chapter 02 Python Fundamentals

What's hot (19)

PDF
Python revision tour II
PPTX
Learn Python The Hard Way Presentation
PDF
Python-01| Fundamentals
PPT
Introduction to Python Language and Data Types
PPTX
Python Programming Basics for begginners
PPT
Javascript
PPTX
Subroutines in perl
PDF
Python cheat-sheet
PPTX
Python second ppt
PPTX
Python language data types
PPTX
Introduction To Programming with Python-3
PDF
Perl_Part1
PPTX
Python Session - 4
PPT
The Java Script Programming Language
PPT
The JavaScript Programming Language
PPTX
Lexical analyzer
PPT
Introduction to Python
PPTX
Operator precedance parsing
PPTX
Python-The programming Language
Python revision tour II
Learn Python The Hard Way Presentation
Python-01| Fundamentals
Introduction to Python Language and Data Types
Python Programming Basics for begginners
Javascript
Subroutines in perl
Python cheat-sheet
Python second ppt
Python language data types
Introduction To Programming with Python-3
Perl_Part1
Python Session - 4
The Java Script Programming Language
The JavaScript Programming Language
Lexical analyzer
Introduction to Python
Operator precedance parsing
Python-The programming Language
Ad

Viewers also liked (11)

PPT
The packaging industry in india
PDF
Plastic packaging market in india 2014 -Sample
PPTX
PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.
PPT
strip packaging
PPTX
Packaging
PDF
Flexible packaging materials 2013
PPT
The Best Package Designs in the World!
PPTX
Packaging ppt
PPTX
Blister packing
PPSX
Packaging & labeling in food industries
PPTX
Marketing - Packaging Project CBSE
The packaging industry in india
Plastic packaging market in india 2014 -Sample
PACKAGING OF TABLETS: TYPES, MATERIALS AND QC.
strip packaging
Packaging
Flexible packaging materials 2013
The Best Package Designs in the World!
Packaging ppt
Blister packing
Packaging & labeling in food industries
Marketing - Packaging Project CBSE
Ad

Similar to LISP: Symbols and packages in lisp (20)

PPTX
LISP: Data types in lisp
PPTX
LISP: Data types in lisp
PPTX
AI Programming language (LISP)
PPTX
LISP: Input And Output
PPTX
LISP: Input And Output
PPTX
LISP:Control Structures In Lisp
PPTX
LISP: Control Structures In Lisp
PPTX
AI UNIT-4 Final (2).pptx
PDF
Advanced features of Lisp functions Advanced features of Lisp functions
PPTX
A brief introduction to lisp language
PDF
Introduction To Lisp
PPTX
LISP: Macros in lisp
PPTX
LISP: Macros in lisp
PDF
Scope Graphs: A fresh look at name binding in programming languages
PDF
Maxbox starter
PPT
(Ai lisp)
PPT
Advance LISP (Artificial Intelligence)
PPTX
LISP:Program structure in lisp
PPTX
LISP: Program structure in lisp
PDF
iRODS Rule Language Cheat Sheet
LISP: Data types in lisp
LISP: Data types in lisp
AI Programming language (LISP)
LISP: Input And Output
LISP: Input And Output
LISP:Control Structures In Lisp
LISP: Control Structures In Lisp
AI UNIT-4 Final (2).pptx
Advanced features of Lisp functions Advanced features of Lisp functions
A brief introduction to lisp language
Introduction To Lisp
LISP: Macros in lisp
LISP: Macros in lisp
Scope Graphs: A fresh look at name binding in programming languages
Maxbox starter
(Ai lisp)
Advance LISP (Artificial Intelligence)
LISP:Program structure in lisp
LISP: Program structure in lisp
iRODS Rule Language Cheat Sheet

More from LISP Content (8)

PPTX
LISP:Declarations In Lisp
PPTX
LISP: Errors In Lisp
PPTX
LISP: Object Sytstem Lisp
PPTX
LISP: Loops In Lisp
PPTX
LISP: Type specifiers in lisp
PPTX
LISP: Scope and extent in lisp
PPTX
LISP: Predicates in lisp
PPTX
LISP: Introduction To Lisp
LISP:Declarations In Lisp
LISP: Errors In Lisp
LISP: Object Sytstem Lisp
LISP: Loops In Lisp
LISP: Type specifiers in lisp
LISP: Scope and extent in lisp
LISP: Predicates in lisp
LISP: Introduction To Lisp

Recently uploaded (20)

PPTX
future_of_ai_comprehensive_20250822032121.pptx
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Auditboard EB SOX Playbook 2023 edition.
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
future_of_ai_comprehensive_20250822032121.pptx
Module 1 Introduction to Web Programming .pptx
Consumable AI The What, Why & How for Small Teams.pdf
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Data Virtualization in Action: Scaling APIs and Apps with FME
sustainability-14-14877-v2.pddhzftheheeeee
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Auditboard EB SOX Playbook 2023 edition.
Custom Battery Pack Design Considerations for Performance and Safety
Co-training pseudo-labeling for text classification with support vector machi...
Build Your First AI Agent with UiPath.pptx
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Improvisation in detection of pomegranate leaf disease using transfer learni...
Taming the Chaos: How to Turn Unstructured Data into Decisions

LISP: Symbols and packages in lisp

  • 2. A lisp symbol is a data object that has three user-visible components:The property list is the list that effectively provides each symbol with many modifiable named components.The print name must be the string, which is the sequence of characters used to identify the symbol.The package cell must refer to package object. A package is a data structure used to locate a symbol once given the symbols name.A symbol is uniquely identified by its name only when considered relative to a package.
  • 3. overviewThe property ListThe Print nameCreating symbolsPackagesTranslating strings to SymbolsExport and import symbolsName conflictsBuilt-in packages
  • 4. The property listA property list contains two or more entries, with each entry associated with the key called the indicator.A property list is very much similar to an association list in its purpose, but the difference is that a property list is an object with unique identity.A property list is implemented as a memory cell containing a list with even number(possibly zero) of elements. Each pair of elements in the list constitutes an entry: the first item is the indicator, the second item is the value.When the symbol is created its property list is initially empty, properties are created by using get within a set form.
  • 5. get symbol indicator1 &optional defaultGet searches the property list of the symbol for an indicator eq to indicator1. if one is found, the corresponding value is returned, else default is returned.Suppose the property list of foo is ( bar t baz 3 hunoz “huh?”)Then ex: (get ‘foo ‘baz)3 (get ‘foo ‘hunoz)”Huh?” (get ‘foo ‘Zoo) nil
  • 6. remprop symbol indicator1This removes the symbol from the property with an indicator eq to indicator1.Suppose if property foo was (color blue height 6.3)After using (remprop ‘foo ‘height) the property becomes (color blue)Returns the list that contains the property pairs of the symbol, the contents of the property lists are extracted and returned.symbol-plist symbol
  • 7. getf place indicator1 &optional defaultgetf searches for the property list stored in place for an indicator eq to indicator1, if found returns the corresponding value, else returns the default or nil.remf removes from the property list stored in the place the property with an indicator eq to indicator1 . The property indicator and the corresponding value are removed by destructively splicing the property list.remf place indicator1
  • 8. get-properties place indicator-listget-properties searches the property list stored in place for any of the indicators in the indicator-list untill it finds the first property in the property list.Get-properties returns three values:The first two values are indicator and the value of the first property whose indicator was in indicator list.
  • 9. The third is the tail of the property whose tail is the indicator.The Print NameEvery symbol has an associated string called the print name used for its external representation. returns the print name of the symbol syn.Ex: (symbol-name ‘xy) “XY”symbol-name syn
  • 10. Creating SymbolsSymbols are used in two different ways:An interned symbol is one that is indexed by its print name in its catalog called a package.An uninterned symbol is one that is used simply as a data object with no special cataloguing.An uninterned symbol is printed with #: followed by its print name.make-symbol print-name creates a new uninterned symbol whose print name is the string print-name.
  • 11. copy-symbol sym &optional copy-props returns a new uninterented symbol with the same name as of the sym.If copy-props is non-nil, then the initial value and function definition of the new symbol will be the same as those of the sym, and the property list of the new symbol will be a copy of sym’s.gensym &optional x gensym invents a print name and creates a new symbol with that print name. it returns new uninterented symbol.The invented new print name consists of a prefix( which defaults to G) , followed by decimal representation of a number.The number is increased by 1 every time gensym is called.
  • 12. gentamp &optional prefix package gentemp like gensym, creates and returns new symbol. The only difference is gentemp interns the symbol in the package.Symbol-package sym returns the contents of the package cell of that symbol. This will be a package object or nil.Keywordp object returns true if the argument is a symbol and that symbol is a keyword.
  • 13. PackagesA package is a data structure that is used for mapping the print names (strings) to symbols.The string-to symbol mappings available in the given package are divided into two classes: external( to be chosen carefully and are advertised to users of the package)
  • 14. internal( normally hidden from other packages).A symbol is said to be interned in a package if it is accessible in that package and also is owned.
  • 15. Consistency rulesIn dealing with package system, it is useful to follow the consistency rules:Read-read consistency: reading the same print name always results in the same(eq) symbol.
  • 16. Print-read consistency: An interned symbol always as a sequence of characters that, when read back in, yields the same (eq) symbol.
  • 17. Print-print consistancy:if two interned symbols are not eq, then their printed representations will be different sequence of characters.Package namesEach package is assigned a name when it is created, though can be changed later.The function find-package translates a package name or nickname into associated package.The function package-name returns the name of the package.The function package-nicknames returns the list of all the nicknames for a package.
  • 18. Translating strings to symbolsWhatever packet object is currently the value of *package* is referred to as current-package.When the lisp reader has obtained a string of characters thought to name a symbol, that name is looked up in the current package.If the name is found, the corresponding symbol is returned, if the name is not found, a new symbol is created for it and is placed in the current package as an internal symbol.External symbol in some other package is referred through the qualified name, consisting of the package name, then a colon, then the name of the symbol.Ex: editor: buffer refers to external symbol buffer accessible in the package named editor.
  • 19. The following four symbol qualifying syntaxes are used:foo: bar look up bar among the external symbols of the package named foo, printed when the symbol bar is external in its home package foo and is not accessible in the current package.foo::bar interns bar as if foo is the current page, printed when symbol bar is internal in its home page foo, and is not accessible in the current page.:bar interns bar as the external symbol in the keyword package and makes it evaluate to itself. Printed if the home page of the symbol bar is keyword.#:bar creates a new uninterned symbol named BAR. Printed when the symbol BAR is uninterented(has no home package )
  • 20. Exporting and Importing SymbolsSymbols from one package may be exported to imported from other packages by the use of functions export and import respectively.(import ‘editor:buffer) takes the external symbol named buffer in the editor package and adds it to the current package as an internal symbol.A symbol is said to be shadowed by another symbol in some package if the first symbol would be accessible by inheritance if not for the presence of the second symbol.
  • 21. To import a symbol without the possibility of getting the error because of shadowing use the function shadowing-import.Use package causes a package to inherit all of the external symbols from some other package.Unlike import, use-package does not cause any of the new symbols to be present in the current package, but makes them accessible by inheritance.
  • 22. The function export takes the symbol that is accessible in some specified package, and makes it an external symbol of that package.If the symbol is directly present as an internal symbol, the it is imply changed to external status.If the symbol is accessible via use-package, the symbol is first imported to the package and then exported.If the same name is being used more than once name-conflicts may occur, so care has to be taken to avoid any such name conflicts.
  • 23. Built-in PackagesCommon lisp built-in packages:Lisp contains the primitives of the common lisp system.Its external symbols include all of the user defined functions such as car, car and *package*.user package is the current package at the time a Common Lisp system starts up. common-lisp package contains the primitives of the ANSI commomLisp system.common-lisp-user is by default the current package at the time, an ANSI common Lisp system starts up.
  • 24. Built-in packagesKeyword package contains all the keywords used by built-in or user-defined Lisp functions.System package name is reserved to the implementation. This is used to contain names of implementation-dependent system-interface functions. This package uses lisp and has the nickname sys.
  • 25. Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net