This document provides an overview of the Lisp programming language. It begins with some notable quotes about Lisp praising its power and importance. It then covers the basic syntax of Lisp including its use of prefix notation, basic data types like integers and booleans, and variables. It demonstrates how to print, use conditional statements like IF and COND, and describes lists as the core data structure in Lisp.
LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. It is a commonly used language for artificial intelligence (AI) programming.
LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. It is a commonly used language for artificial intelligence (AI) programming.
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
Also since {a} is regular, {a}* is a regular language which is the set of strings consisting of a's such as , a, aa, aaa, aaaa etc. Note also that *, which is the set of strings consisting of a's and b's, is a regular language because {a, b} is regular. Regular expressions are used to denote regular languages.
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
Knowledge representation and reasoning (KR) is the field of artificial intelligence (AI) dedicated to representing information about the world in a form that a computer system can utilize to solve complex tasks such as diagnosing a medical condition or having a dialog in a natural language
This presentation will introduce you to programming languages that support different programming paradigms and to give you the knowledge of basic concepts and techniques that will allow them to differentiate between various programming paradigms.
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
Also since {a} is regular, {a}* is a regular language which is the set of strings consisting of a's such as , a, aa, aaa, aaaa etc. Note also that *, which is the set of strings consisting of a's and b's, is a regular language because {a, b} is regular. Regular expressions are used to denote regular languages.
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
Knowledge representation and reasoning (KR) is the field of artificial intelligence (AI) dedicated to representing information about the world in a form that a computer system can utilize to solve complex tasks such as diagnosing a medical condition or having a dialog in a natural language
This presentation will introduce you to programming languages that support different programming paradigms and to give you the knowledge of basic concepts and techniques that will allow them to differentiate between various programming paradigms.
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
Functional Programming Past Present FutureIndicThreads
Presented at the IndicThreads.com Software Development Conference 2016 held in Pune, India. More at http://www.IndicThreads.com and http://Pune16.IndicThreads.com
--
An introduction to the basic concepts on functional programming, explaining why it is a hot topic for some years now, what it is and some suggestions of functional languages to be learned.
This is a talk from the March 2015 Austin Clojure Meetup in which I explored LISP 1.5 and showed how to run the original LISP 1.5 in an IBM 7094 simulator.
Natural Language Processing using JavaScript "Natural" Library. This deck covers Natural Language Understanding using JavaScript "Natural" library in detail
Discussed in detail about how to design and develop custom skills (think custom apps) for Amazon Alexa Voice service.
Discusses how to design voice based experiences in detail.
Workflows are a key component of server side of IoT solution along with Analytics, Rule Engine and IoT device management. IoT focused Workflow tools draw their inspiration of classical workflow tools that exist in market, but focus more on IoT use cases. For example they are able to connect with IoT devices using IoT specific protocols like CoAP or MQTT. Node-RED is a visual tool for wiring together hardware devices, APIs and online services in new and interesting ways. It’s build by IBM Emerging Technology team from group for IoT, though it’s not limited only to IoT.
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Aniruddha Chakrabarti
Swift has gained widespread popularity in just an year. So much so that Swift have emerged as the de-facto standard programming language for all Apple platforms including iOS, watchOS, tvOS and OS X. Apple also open sources Swift and soon after IBM ported Swift to Linux. Swift incorporates the language innovations that have happened in the last two decades. Swift is a compiled programming language and belongs to the ‘C’ family of languages similar to C++, Java, C#, Objective-C and D. Swift is influenced by dynamic programming languages like Python, Ruby and functional programming languages like Haskell.
Future of .NET - .NET on Non Windows Platforms. .NET has been so far targeted towards Windows only. Now Microsoft created a subset of .NET called .NET Core that would run on Linux and OS X apart from Windows.
High level overview of CoAP or Constrained Application Protocol. CoAP is a HTTP like protocol suitable for constrained environment like IoT. CoAP uses HTTP like request response model, status code etc.
memcached Distributed Cache. memcached is the most popular cache solution for low latency high throughput websites. improves the read timings drastically.
Provides an overview of Redis which is a Key Value NoSQL database and the different data types it supports. Also shows how to use Redis Client API from node.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Lisp
1. Aniruddha Chakrabarti
Associate Vice President & Chief Architect, Digital Practice, Mphasis
caniruddha@hotmail.com | in.linkedin.com/in/aniruddhac
Lisp (LISP)
2. The greatest single programming language ever designed.
Alan Kay, about LISP.
The most powerful programming language is Lisp. If you don't know Lisp (or its variant,
Scheme), you don't appreciate what a powerful language is. Once you learn Lisp you will
see what is missing in most other languages.
Richard Stallman [How I do my computing]
One of the most important and fascinating of all computer languages is Lisp, which was
invented by John McCarthy around the time Algol was invented.
Douglas Hofstadter, Gödel, Escher, Bach: an Eternal Golden Braid
Lisp is worth learning for the profound enlightenment experience you will have when you
finally get it; that experience will make you a better programmer for the rest of your days,
even if you never actually use Lisp itself a lot.
Eric S. Raymond, How to Become a Hacker
1958 - John McCarthy and Paul Graham invent LISP. Due to high costs caused by a post-
war depletion of the strategic parentheses reserve LISP never becomes popular...
Fortunately for computer science the supply of curly braces & angle brackets remains high.
Iry James, A Brief, Incomplete, and Mostly Wrong History of Programming Languages
Few remarkable quotes on Lisp
Source - http://www.paulgraham.com/quotes.html
3. Agenda
• What is Lisp, brief history and where Lisp is used
• Basic syntax, building blocks, prefix notation
• Data types
• Variables
• Constants
• IO (Read and Write/print)
• Control flow statements
• List and List comprehension
• Function and Lambda Expression
• Structure
4. What is Lisp
• Lisp (or LISP) is a family of computer programming languages with a long
history and a distinctive, fully parenthesized syntax.
• Invented in 1958 by John McCarthy
• Second-oldest high-level programming language in widespread use today;
only Fortran is older (by one year).
• Generally regarded as being the first functional programming language.
• Not a pure functional language as supports variable assignment.
• The name Lisp (historically LISP) derives from LISt Processor
• Multi paradigm – functional, procedural, reflective, meta
• First programming language that showed concepts and constructs of
functional programming
• Not an imperative programming language like C, C++, Java, C#
• Has many dialects, two of the following being most popular
– Common Lisp
– Scheme
5. History
• Invented by John McCarthy in 1958 while he was at MIT
• First implemented by Steve Russell on an IBM 704 computer.
• Common Lisp originated, during the 1980s and 1990s, in an attempt to unify
the work of several implementation groups.
Steve RussellJohn McCarthy
http://www.paulgraham.com/rootsoflisp.html
6. Where is Lisp (or it’s dialects) used
• AI (Artificial Intelligence)
• Academia / Education (in many CS courses)
– Structure and Interpretation of Computer Programs (MIT)
– DrRacket
• CAD (AutoCAD, CoCreate, and several others)
• Development environments (Emacs and others)
• Clojure a dialect of Lisp (targets the Java Virtual Machine, also CLR and
Javascript) has seen good acceptance in recent years
– http://dev.clojure.org/display/community/Clojure+Success+Stories
7. Lisp dialects & languages it influenced
• LISP 1 – First implementation.
• LISP 1.5 – First widely distributed version,
developed by McCarthy and others at MIT.
• Stanford LISP – This was a successor to LISP 1.5
developed at the Stanford AI Lab
• MACLISP – developed for MIT's Project MAC
• Common Lisp
• Scheme
• Emacs Lisp
• Clojure - a modern dialect of Lisp which
compiles to the Java virtual machine and
handles concurrency very well.
• Haskell
• Logo
• Lua
• Perl
• Python
• Racket
• JavaScript
• Ruby
• Smalltalk
• Tcl
• R
8. Lisp Program Structure
• LISP expressions are called symbolic expressions or s-
expressions. The s-expressions are composed of three valid
objects, atoms, lists and strings.
• Any s-expression is a valid program.
Example - (+ 1 2)
• LISP programs run either on an interpreter (REPL) or
as compiled code
• LISP expressions are case-insensitive, so the below lines are
same -
(write-line "Hello World")
(WRITE-LINE "Hello World")
• The basic numeric operations in LISP are +, -, *, and /
• LISP represents a function call f(x) as (f x), for example cos(45)
is written as (cos 45)
9. Basic Lisp Syntax
• Lisp has a different syntax than C like languages (C++, Java, C#)
• Uses parenthesis extensively - ( and )
• Uses prefix notation
For example the expression to add 1 and 2 would be (+ 1 2) in Lisp
Lisp C like languages
Math Operation (+ 1 2)
(+ 1 2 3 4)
1 + 2
1 + 2 + 3 + 4
Variable Assignment (defvar my-name "David") my-name = "David"
Invoking Functions (write-line "Hello World") printf("Hello World")
If, Else (if (> 2 3)
"bigger"
"smaller")
if (2 > 3){
"bigger"
}
else
"smaller"
}
Function definition (defun add (a b)
(+ a b))
int add(int a,int b){
return a + b;
}
10. Building Blocks of Lisp
• LISP programs are made up of three basic building blocks:
– Atom: An atom is a number or string of contiguous characters. It
includes numbers and special characters.
hello-from-lisp
name
123008907
*hello*
Block#221
Abc123
– List: Sequence of atoms and/or other lists enclosed in parentheses.
( i am a list)
(a ( a b c) d e fgh)
(father tom ( susan bill joe))
(sun mon tue wed thur fri sat)
( )
– String: Group of characters enclosed in double quotation marks.
" I am a string"
"a ba c d efg #$%^&!"
"Please enter the following details :"
"Hello from 'Tutorials Point'! "
12. Prefix / Polish Prefix notation
• No concepts of operators for primitive types
• Simple arithmetic operations also follow function calling syntax
function_name arg1 arg2... argN
operator arg1 arg2 ... argN
(+ 2 5)
7
(+ 2 5 3 4 9 20)
43
(+ 2.5 7.25)
9.25
13. Notations
Prefix Notation
(also called Polish
Notation or Polish Prefix
Notation)
places operators to the
left of their operands
operator arg1 arg2
+ 2 5
7
Infix Notation
operators are written
infix-style between the
operands they act on
arg1 operator arg2
2 + 5
7
Postfix Notation
(also called Reverse
Polish notation (RPN))
puts the operator in the
prefix position.
operator arg1 arg2
2 5 +
7
14. Comment
• A Lisp comment begins with a semi-colon.
; This is a Lisp comments - ignored by the interpreter.
(print "Hello World") ; this is an example of comment
; the following statement prints addition of 2 and 3
(print (+ 2 3))
• Supports multiple comment through #| … |#
#|
this is an example of multiple comment
as this comment is spread across multiple lines
|#
#| first line
this is an example of multiple comment
as this comment is spread across multiple lines
last line |#
15. Symbol
• Symbol is a name that represents data objects and interestingly
it is also a data object.
• A symbol is just a string of characters.
• There are restrictions on what you can include in a symbol and
what the first character can be, but as long as you stick to
letters, digits, and hyphens, you'll be safe.
17. Data types
• type-of function returns the data type of a given object
(defvar name "XYZ")
(defvar age 30)
(defvar salary 1234.567)
(defvar isMale T)
(print (type-of name))
(print (type-of age))
(print (type-of salary))
(print (type-of isMale))
(SIMPLE-BASE-STRING 3)
(INTEGER 0 281474976710655)
SINGLE-FLOAT
BOOLEAN
18. Declaring new variables (defvar)
• defvar – declares global dynamic variables. DEFVAR optionally sets it
to some value, unless it is already defined.
• defvar assigns a value only first time. variables are generally
immutable (meaning their value can not change)
(defvar my-name "David")
"David"
my-name
"David"
(defvar my-name "David")
(print my-name) ;prints “David”
(defvar my-name “Aniruddha") ;does not change the value of my-name
(print my-name) ;still prints “David”
"David"
"David"
(defvar a-variable 57)
57
a-variable
57
• In Scheme, define is used both for procedures and for
variables whose values aren't procedures.
• In Lisp (and Common Lisp), procedures are given
names by a mechanism separate from the general
variable mechanism; defun is only for procedures. To
define a variable, use defvar
19. Declaring new variables (defparameter)
• defparameter – also declares global dynamic variables similar
to defvar.
• defparameter always assigns a value (unlike defvar which
assigns the value only first time)
(defparameter my-name "David")
"David"
my-name
"David"
(defparameter my-name "David")
(print my-name)
(defvar my-name “Aniruddha") ;does change the value of my-name
(print my-name)
"David"
“Aniruddha"
20. Mutate existing variables (setq)
• SETQ's first argument is a symbol. This is not evaluated. The second argument is
assigned as the variable's value.
(setq my-name "David")
"David"
my-name
"David"
(setq a-variable 57)
57
a-variable
57
• SETQ form can actually take any even number of arguments, which should be
alternating symbols and values.
• SETQ performs the assignments from left to right, and returns the rightmost
value.
(setq year 2014 month "September" day 20)
(print year)
(print month)
(print day)
Output: 2014
"September"
20
21. Declaring Constants (defconstant)
• Constants are variables that never change their values during program
execution.
• Constants are declared using the defconstant construct.
(defconstant PI 3.14)
(print PI)
3.14
(setq PI 6.54)
SETQ: PI is a constant, may not be used as a variable
22. Basic Printing - print, prin1, terpri
• print always precedes its output
with a newline.
• Syntax:
(print what_to_print/expression/form)
(print "Hello World")
Output: "Hello World"
(print 100.459)
Output: 100.459
(print (+ 10 5))
(print “Hello World”)
Output:
15
"Hello World"
• prin1 just like print except that it
does not do a new line before
printing
• Syntax:
(prin1 what_to_print/expression/form)
(prin1 (+ 10 5))
(prin1 “Hello World”)
Output: "" 15"Hello World“
(+ (prin1 1) (prin1 2))
Output:
“12”
3
• terpri produces a newline. Can be called without any argument.
(prin1 (+ 10 5)) (terpri)
(prin1 "Hello World") (terpri)
(prin1 "Hello World 2")
15
"Hello World"
"Hello World 2"
23. Basic Printing – write, write-*
• write-string: It writes the characters of the specified substring of string to
the output-stream.
• write-line: It works the same way as write-string, but outputs a newline
afterwards.
• write: typically used with an object or structure
• write-*: there are other write methods like write-char and write-byte
(write-string "Hello")
(write-string “World")
‘ output Hello World
(write-line "Hello")
(write-line “World")
‘ output Hello
‘ World
(write "Hello")
‘ output Hello
24. Advanced Printing - format
• Allows string interpolation
(setq city "Bangalore")
(format t
"I like ~s as I live there. Current temp is ~s C"
city
(+ 10 20))
Output: I like "Bangalore" as I live there. Current temp is 30 C
25. Decision making (if)
• Has if condition (no else then keyword)
( if ‹condition expr›
‹if expr›
‹else or oterwise expr› )
> (if (> 2 3)
"bigger"
"smaller")
Output - "smaller"
(setq x 10)
(if (< x 10)
"x is less than 10" ;if x < 10 then returns this expression
"x is equal to or greater than 10") ;this is the else expression
Output - "x is equal to or greater than 10"
26. and
(define x 10)
(define y 20)
(if (and
(= x 10)
(= y 20))
"both conditions are true"
"false")
Output - "both conditions are true"
;next program
(define x 10)
(define y 20)
(define z 50)
(if (and
(= x 10)
(= y 20)
(= z 30))
"all conditions are true"
"all conditions are not true")
Output - "both conditions are not true"
27. or
(define x 10)
(define y 20)
(if (or
(= x 10)
(= y 10))
“one of the conditions is true"
“none of the conditions is true")
Output - "one of the condition is true"
;next program
(define x 10)
(define y 20)
(define z 50)
(if (or
(= x 15)
(= y 15)
(= z 15))
"one of the conditions is true"
"none of the conditions is true")
Output - " none of the conditions is true"
28. cond
• Allows multiple conditions
• Similar to switch case or select case
(define (check x)
(cond ((< x 0) "x is less than 0")
((= x 0) "x is equal to 0")
((> x 0) "x is greater 0")))
(check 10)
(check 0)
(check -10)
Output -
"x is greater 0"
"x is equal to 0"
"x is less than 0"
29. Data Structures - List
• List - core Lisp data structure (Lisp gets it’s name from List Processing)
Empty list: ()
> '(1 2 3 4)
(list 1 2 3 4)
> (cons 1 empty)
(1)
> (cons 1 (cons 2 empty))
(1 2)
> (list 1 2 3 4 5)
(list 1 2 3 4 5)
• A list can contain any data type
> (define lst (list 1 3 4 "Hello" 5 6 "Bangalore"))
> lst
(list 1 3 4 "Hello" 5 6 "Bangalore")
> (cons 1 (cons 2 (cons 3 (cons "Hello" (cons "World" (cons 4
empty))))))
(1 2 3 "Hello" "World" 4)
30. Data Structures - List
> (length lst) ; count the elements
7
> (list-ref lst 0) ; extract by position
1
> (list-ref lst 1)
3
> (list-ref lst 3)
"Hello"
> (list-ref lst 6)
"Bangalore"
> (reverse lst) ; reverse order
("Bangalore" 6 5 "Hello" 4 3 1)
> (append lst (list 7 8 9 "Kolkata")) ; combine lists
(1 3 4 "Hello" 5 6 "Bangalore" 7 8 9 "Kolkata")
> (member "Delhi" lst) ;check for an element
#f
> (member "Bangalore" lst)
("Bangalore")
31. List operations (car, cdr)
• car (pronounced kar) – returns the first element of the list
• cdr (pronounced kuder) – returns rest of the list without the first element.
• Alternatively called first and rest. In other languages typically called head
and tail
(define lst (list 1 3 4 "Hello" 5 6 "Bangalore"))
(car lst)
Output: 1
(cdr lst)
Output: (3 4 "Hello" 5 6 "Bangalore")
Lisp was originally implemented on the IBM 704 computer, in the late 1950s. The 704 hardware had special support
for splitting a 36-bit machine word into four parts, an "address part" and "decrement part" of 15 bits each and a
"prefix part" and "tag part" of three bits each.
- car (short for "Contents of the Address part of Register number")
- cdr ("Contents of the Decrement part of Register number")
http://en.wikipedia.org/wiki/CAR_and_CDR
1 3 4 Hello 5 6 Bangalore
car (head/first) cdr (tail/rest)
32. Moe List operations (cadr, cddr, caddr, caddr, …)
To get the second element from list – use cadr
(print (car (cdr lst)))
Alternately - (print (cadr lst))
Output: 3
All elements but first and second – use cddr
(print (cddr lst))
Output: (4 "Hello" 5 6 "Bangalore")
Third element , Forth Element -
(print (caddr lst))
Output: 4
(print (cadddr lst))
Output: "Hello"
1 3 4 Hello 5 6 Bangalore
car (head/first) cdr (tail/rest)
33. Moe List operations (cadr, cddr, caddr, caddr, …)
To get the first element from list – use first
(print (first lst)
Output: 1
To get the second element from list – use second
(print (second lst)
Output: 3
To get the third element from list – use third
(print (third lst)
Output: 4
To get the last element from list – use third
(print (last lst)
Output: “Bangalore”
1 3 4 Hello 5 6 Bangalore
first second third last
35. Associate List or alist (aka Object)
• Allows to keep key, value pairs.
• Very similar to Object
• Syntax is very similar to JavaScript object
(setf person '((first-name "Aniruddha")
(last-name "Chakrabarti")
(age 40)
(salary 123.456)))
(print person)
Output: ((FIRST-NAME "Aniruddha") (LAST-NAME "Chakrabarti") (AGE
40) (SALARY 123.456))
• Lisp provides a function, assoc, to retrieve information easily from
association lists given a retrieval key.
(print (assoc 'age person))
Output: (AGE 40)
(print (assoc 'first-name person))
Output: (FIRST-NAME "Aniruddha")
first-name Aniruddha
last-name Chakrabarti
age 40
salary 123.456
Person
36. Associate List (Cont’d)
(setf person '((first-name "Aniruddha")
(last-name "Chakrabarti")
(age 40)
(salary 123.456)))
(print person)
Output: ((FIRST-NAME "Aniruddha") (LAST-NAME "Chakrabarti") (AGE
40) (SALARY 123.456))
• rassoc, reverse assoc starts the matching from reverse direction
• copy-alist: returns a two-level deep copy of alist: it creates a new copy of
each association, so that you can alter the associations of the new alist
without changing the old one.
first-name Aniruddha
last-name Chakrabarti
age 40
salary 123.456
Person
37. Function Basics
• Functions are defined using defun statement
(defun <function name>(arg1 arg2 ... argN)
(statements))
(defun double (x) (* x 2))
(print (double 4))
8
(print (double 9.87))
19.74
(print (double "hello world"))
*** - *: "hello world" is not a number
(print (double (+ 3 5)))
16
(print (double (* 3 5)))
30
(defun printmessage (msg) (print msg))
(printmessage "Hello World")
"Hello World"
Parameter-less Function
(defun display_name ()
(print "Hello")
)
(display_name)
"Hello"
38. Function Basics
(defun add (a b)
(+ a b))
(add 10 20)
(add 10.345 20.456)
Output:
30
30.801000000000002
> (add 20 "hello")
. . +: contract violation
expected: number?
given: "hello"
argument position: 2nd
other arguments...:
20
39. Multiline Functions
(defun add (a b)
(setq res (+ a b))
(print res)
)
(add 20 30)
(add 10.345 20.456)
Output:
50
30.800999
40. Lambda Expression
• Lambda defines anonymous functions
• Function name is not declared while defining the method
((lambda (arg1 arg2 ... argN)
(statements)) value1 value2 ... valueN)
((lambda (x) (* x 2))10)
20
((lambda (x) (* x x))10)
100
((lambda (x y) (+ x y)) 10 20)
30
((lambda (x y) (* x y)) 10 20)
200
41. Structure
• Structures are one of the user-defined data type, which allows you to
combine data items of different kinds.
• Structures are used to represent a record.
• defstruct macro in LISP allows you to define an abstract record structure.
defstruct statement defines a new data type, with more than one member
for your program.
(defstruct employee
name
age
designation
salary
is-name
)
• An implicit function named make-employee is created, which is a
constructor - when invoked will create a data structure with four
components
name String
age Integer
designation String
salary Float
is-male Boolean