SlideShare a Scribd company logo
Lisp for Python Developers

       Vsevolod Dyomkin
           @vseloved
          2013-01-26
Topics

* A short intro
* Some myths and facts
* What Lisp offers
Hello World
CL-USER> "Hello world"
"Hello world"

CL-USER> (print "Hello world")

"Hello world"
"Hello world"
Horner's Rule
         (Is Lisp a functional language?)

(defun horner (coeffs x)
  (reduce (lambda (coef acc)
            (+ (* acc x) coef))
          coeffs
          :from-end t
          :initial-value 0))

From Rosetta Code:
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation
Horner's Rule
           (Python version)


def horner(coeffs, x):
  return reduce(lambda acc, c: 
                     acc * x + c,
                reversed(coeffs),
                0)
Lisp Tools

1. Implementations - multiple
2. IDEs - SLIME, SLIMV
3. quicklisp
Myths
*   The   syntax myth
*   The   libraries myth
*   The   community myth
*   The   slowness myth
*   The   outdatedness myth
*   The   myth of too much choice
*   The   myth of academic language
Myth              |        Fact
LISP = Lost In           )))))))])))))])]) —
Stupid Parenthesis       the joy of debugging
                         ASTs
Your eyes are gonna
                         -- Armin Ronacher
bleed!!!!                (https://twitter.com/mitsuhi
                         ko/status/88527153158815744)
Lisp in 1 slide
Myth             |       Fact
There are no Lisp       1961 libraries in
libraries               Quicklisp
Myth             |       Fact
There are no Lisp       1961 libraries in
libraries               Quicklisp

                        27413 libraries in
                        PyPI
(defun graylog (message &key level backtrace file line-no)
 (let (sock)
   (unwind-protect
        (let ((msg (salza2:compress-data
                    (babel:string-to-octets
                     (json:encode-json-to-string
                      #{:version "1.0" :facility "lisp"
                        :host (get-hostname)
                        :|short_message| message
                        :|full_message| backtrace
                        :timestamp (local-time:timestamp-to-unix
                                    (local-time:now))
                        :level level :file file :line line-no
                       })
                     :encoding :utf-8)
                    'salza2:zlib-compressor)))
          (setf sock (usocket:socket-connect *graylog-host*
                                             *graylog-port*
                                             :protocol :datagram
                                             :element-type 'ub8))
          (usocket:socket-send sock msg (length msg))))
     (usocket:socket-close sock)))
Myth                   |            Fact
There's no Lisp                  SBCL – more than 10
programmers                      people contribute to
                                 each release, ABCL –
There's no Lisp                  more than 5, etc.
jobs
                                 This year: 2 Lisp
Lisp community is                conferences in Europe
full of trolls                   for up to 100 people
                                 (ECLM & ECLS) &
Lisp hasn't been                 numerous Lisp user
developed for years              groups meetings

 http://lisp-univ-etc.blogspot.com/search/label/lisp-hackers
Myth        |       Fact
Lisp is slow       Lisp is the fastest
                   of popular dynamic
                   languages

                   Lisp can be faster
                   than Java

                   … or even C

                   http://benchmarksgame.
                   alioth.debian.org/u32q
                   /lisp.php
Cool Lisp Features
1.   Macros
2.   All the functional stuff
3.   CLOS multimethods
4.   Special variables
5.   Condition system
6.   Read macros
7.   The richest calling convention
8.   Etc.
Macros

This page is intentionally left blank
Condition system
Jedis redis = Redis.getClient(Redis.SOME_DB);
try {
    while (!Thread.interrupted())
         try {
             // do some useful work
             break;
         } catch (JedisException e) {
             Redis.returnBrokenClient(redis);
             redis = Redis.getClient(Redis.SOME_DB);
         }
    // do some other stuff
} finally {
      Redis.returnClient(redis);
}
Condition system
Jedis redis = Redis.getClient(Redis.SOME_DB);
try {
    while (!Thread.interrupted())
         try {
             // do some useful work
             break;
         } catch (JedisException e) {
             Redis.returnBrokenClient(redis);
             redis = Redis.getClient(Redis.SOME_DB);
         }
    // do some other stuff
} finally {
      Redis.returnClient(redis);
}
Condition system
(with-persistent-connection (host port)
  ;; do useful stuff
  )
Condition system
(with-persistent-connection (host port)
  ;; do useful stuff
  )

(defmacro with-persistent-connection
    ((&key (host #(127 0 0 1)) (port 6379))
     &body body)
  `(with-connection (:host ,host :port ,port)
     (handler-bind ((redis-connection-error
                     (lambda (e)
                       (warn "Reconnecting.")
                       (invoke-restart :reconnect))))
       ,@body)))
Condition system
(defmacro with-reconnect-restart (&body body)
  `(handler-case (progn ,@body)
     (usocket:connection-refused-error (e)
       (reconnect-restart-case
         (:error e :comment "Can't connect”)
         ,@body))
     ((or usocket:socket-error
          stream-error end-of-file) (e)
        (reconnect-restart-case (:error e)
          ,@body)))))
Condition system
(defmacro reconnect-restart-case
     ((&key error comment) &body body)
  `(if *pipelined*
       (progn ,@body)
       (restart-case (error 'redis-connection-error
                            :error ,error
                            :comment ,comment)
         (:reconnect ()
           :report "Trying to reconnect"
           (reconnect)
           ,@body))))

http://lisp-univ-etc.blogspot.com/2012/11/cl-redis-separation-
of-concerns-in.html
Read macros
{ x ! x <- (loop :for i :upto 10 :collect i) }
'(0 1 2 3 4 5 6 7 8 9 10 )

{x ! x <- '(1 nil 2) ! x}
'(1 2)

{x y ! x <- '(1 2 3) y <- '(5 6 7) ! (oddp x) (> y 5)}
'((3 7))

{ (+ x y) ! x <- '(1 2 3) y <- '(5 6 7) ! (oddp x) (> y 5) }
'(10)

(set-macro-character #{ #'read-listcomp)
(set-macro-character #} (get-macro-character #)))
(defun read-listcomp (stream char)
  "Read list comprehension { vars ! generators [! conditions]? }"
  (declare (ignore char))
  (let (rezs srcs conds state)
    (dolist (item (read-delimited-list #} stream))
      (if (eql '! item)
          (setf state (if state :cond :src))
          (case state
            (:src       (push item srcs))
            (:cond      (push item conds))
            (otherwise (push item rezs)))))
    (setf rezs (reverse rezs)
          srcs (reverse srcs)
          conds (reverse conds))
    (let ((binds (mapcar #`(cons (first %) (third %))
                          (group 3 srcs))))
      `(mapcan (lambda ,(mapcar #'car binds)
                  (when (and ,@conds)
                    (list ,(if (rest rezs)
                               (cons 'list rezs)
                               (first rezs)))))
               ,@(mapcar #'cdr binds)))))
Lisp is Python on
     steroids

     but w/o
  batteries :)
Lisp in My View
1.   Rich, non-exclusive culture
2.   Consistency & simplicity
3.   Mature interactive environment
4.   Multi-paradigm language
5.   Unique features
6.   Cool non-unique features
7.   Performant grown-up runtimes
Lisp Resources
1. Hyperspec -
http://clhs.lisp.se/Front/Contents.htm
2. Cookbook -
http://cl-cookbook.sourceforge.net/
3. Cliki – http://cliki.net
4. lispdoc - http://lispdoc.com/
5. Google Styleguide -
http://google-styleguide.googlecode.com/svn/trunk/lispguide.xml

6. L1sp.org - http://l1sp.org/
7. Lisp books -
http://pinterest.com/vseloved/lisp-books/

More Related Content

What's hot (20)

2016 bioinformatics i_python_part_1_wim_vancriekinge
2016 bioinformatics i_python_part_1_wim_vancriekinge
Prof. Wim Van Criekinge
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF files
Rubén Izquierdo Beviá
 
Python made easy
Python made easy
Abhishek kumar
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
The Sincerest Form of Flattery
The Sincerest Form of Flattery
José Paumard
 
Python to scala
Python to scala
kao kuo-tung
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?
Alex Payne
 
JDK8 Functional API
JDK8 Functional API
Justin Lin
 
DevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programming
Henri Tremblay
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Python Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdb
Wei-Bo Chen
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
Max Klymyshyn
 
Introduction to Scala
Introduction to Scala
Rahul Jain
 
Performance and predictability (1)
Performance and predictability (1)
RichardWarburton
 
Seattle useR Group - R + Scala
Seattle useR Group - R + Scala
Shouheng Yi
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
José Paumard
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
Introduction To Scala
Introduction To Scala
Peter Maas
 
2016 bioinformatics i_python_part_1_wim_vancriekinge
2016 bioinformatics i_python_part_1_wim_vancriekinge
Prof. Wim Van Criekinge
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF files
Rubén Izquierdo Beviá
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
The Sincerest Form of Flattery
The Sincerest Form of Flattery
José Paumard
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?
Alex Payne
 
JDK8 Functional API
JDK8 Functional API
Justin Lin
 
DevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programming
Henri Tremblay
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Python Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdb
Wei-Bo Chen
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
Max Klymyshyn
 
Introduction to Scala
Introduction to Scala
Rahul Jain
 
Performance and predictability (1)
Performance and predictability (1)
RichardWarburton
 
Seattle useR Group - R + Scala
Seattle useR Group - R + Scala
Shouheng Yi
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
José Paumard
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
Introduction To Scala
Introduction To Scala
Peter Maas
 

Viewers also liked (18)

Aspects of NLP Practice
Aspects of NLP Practice
Vsevolod Dyomkin
 
NLP in the WILD or Building a System for Text Language Identification
NLP in the WILD or Building a System for Text Language Identification
Vsevolod Dyomkin
 
Practical NLP with Lisp
Practical NLP with Lisp
Vsevolod Dyomkin
 
NLP Project Full Cycle
NLP Project Full Cycle
Vsevolod Dyomkin
 
Crash-course in Natural Language Processing
Crash-course in Natural Language Processing
Vsevolod Dyomkin
 
Lisp Machine Prunciples
Lisp Machine Prunciples
Vsevolod Dyomkin
 
Tedxkyiv communication guidelines
Tedxkyiv communication guidelines
Vsevolod Dyomkin
 
Новые нереляционные системы хранения данных
Новые нереляционные системы хранения данных
Vsevolod Dyomkin
 
Чему мы можем научиться у Lisp'а?
Чему мы можем научиться у Lisp'а?
Vsevolod Dyomkin
 
Lisp как универсальная обертка
Lisp как универсальная обертка
Vsevolod Dyomkin
 
Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?
Vsevolod Dyomkin
 
CL-NLP
CL-NLP
Vsevolod Dyomkin
 
Экосистема Common Lisp
Экосистема Common Lisp
Vsevolod Dyomkin
 
Crash Course in Natural Language Processing (2016)
Crash Course in Natural Language Processing (2016)
Vsevolod Dyomkin
 
Natural Language Processing in Practice
Natural Language Processing in Practice
Vsevolod Dyomkin
 
Redis for the Everyday Developer
Redis for the Everyday Developer
Ross Tuck
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
rjsmelo
 
Redis in Practice
Redis in Practice
Noah Davis
 
NLP in the WILD or Building a System for Text Language Identification
NLP in the WILD or Building a System for Text Language Identification
Vsevolod Dyomkin
 
Crash-course in Natural Language Processing
Crash-course in Natural Language Processing
Vsevolod Dyomkin
 
Tedxkyiv communication guidelines
Tedxkyiv communication guidelines
Vsevolod Dyomkin
 
Новые нереляционные системы хранения данных
Новые нереляционные системы хранения данных
Vsevolod Dyomkin
 
Чему мы можем научиться у Lisp'а?
Чему мы можем научиться у Lisp'а?
Vsevolod Dyomkin
 
Lisp как универсальная обертка
Lisp как универсальная обертка
Vsevolod Dyomkin
 
Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?
Vsevolod Dyomkin
 
Экосистема Common Lisp
Экосистема Common Lisp
Vsevolod Dyomkin
 
Crash Course in Natural Language Processing (2016)
Crash Course in Natural Language Processing (2016)
Vsevolod Dyomkin
 
Natural Language Processing in Practice
Natural Language Processing in Practice
Vsevolod Dyomkin
 
Redis for the Everyday Developer
Redis for the Everyday Developer
Ross Tuck
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
rjsmelo
 
Redis in Practice
Redis in Practice
Noah Davis
 
Ad

Similar to Lisp for Python Programmers (20)

Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
Hajime Tazaki
 
Lisp Primer Key
Lisp Primer Key
Yuumi Yoshida
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
GangSeok Lee
 
A brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Perl at SkyCon'12
Perl at SkyCon'12
Tim Bunce
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
Moabi.com
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
Sigma Software
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
Tim Bunce
 
ClojureScript for the web
ClojureScript for the web
Michiel Borkent
 
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
Saurabh Nanda
 
Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon Kickoff
Itamar Haber
 
Extend Redis with Modules
Extend Redis with Modules
Itamar Haber
 
Redis Lua Scripts
Redis Lua Scripts
Itamar Haber
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
Profiling Ruby
Profiling Ruby
Ian Pointer
 
Server side JavaScript: going all the way
Server side JavaScript: going all the way
Oleg Podsechin
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"
Hyuk Hur
 
Ruby is an Acceptable Lisp
Ruby is an Acceptable Lisp
Astrails
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
Hajime Tazaki
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
GangSeok Lee
 
A brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Perl at SkyCon'12
Perl at SkyCon'12
Tim Bunce
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
Moabi.com
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
Sigma Software
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
Tim Bunce
 
ClojureScript for the web
ClojureScript for the web
Michiel Borkent
 
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
ABRIDGED VERSION - Joys & frustrations of putting 34,000 lines of Haskell in...
Saurabh Nanda
 
Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon Kickoff
Itamar Haber
 
Extend Redis with Modules
Extend Redis with Modules
Itamar Haber
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
Server side JavaScript: going all the way
Server side JavaScript: going all the way
Oleg Podsechin
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"
Hyuk Hur
 
Ruby is an Acceptable Lisp
Ruby is an Acceptable Lisp
Astrails
 
Ad

Recently uploaded (20)

Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 

Lisp for Python Programmers

  • 1. Lisp for Python Developers Vsevolod Dyomkin @vseloved 2013-01-26
  • 2. Topics * A short intro * Some myths and facts * What Lisp offers
  • 3. Hello World CL-USER> "Hello world" "Hello world" CL-USER> (print "Hello world") "Hello world" "Hello world"
  • 4. Horner's Rule (Is Lisp a functional language?) (defun horner (coeffs x) (reduce (lambda (coef acc) (+ (* acc x) coef)) coeffs :from-end t :initial-value 0)) From Rosetta Code: http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation
  • 5. Horner's Rule (Python version) def horner(coeffs, x): return reduce(lambda acc, c: acc * x + c, reversed(coeffs), 0)
  • 6. Lisp Tools 1. Implementations - multiple 2. IDEs - SLIME, SLIMV 3. quicklisp
  • 7. Myths * The syntax myth * The libraries myth * The community myth * The slowness myth * The outdatedness myth * The myth of too much choice * The myth of academic language
  • 8. Myth | Fact LISP = Lost In )))))))])))))])]) — Stupid Parenthesis the joy of debugging ASTs Your eyes are gonna -- Armin Ronacher bleed!!!! (https://twitter.com/mitsuhi ko/status/88527153158815744)
  • 9. Lisp in 1 slide
  • 10. Myth | Fact There are no Lisp 1961 libraries in libraries Quicklisp
  • 11. Myth | Fact There are no Lisp 1961 libraries in libraries Quicklisp 27413 libraries in PyPI
  • 12. (defun graylog (message &key level backtrace file line-no) (let (sock) (unwind-protect (let ((msg (salza2:compress-data (babel:string-to-octets (json:encode-json-to-string #{:version "1.0" :facility "lisp" :host (get-hostname) :|short_message| message :|full_message| backtrace :timestamp (local-time:timestamp-to-unix (local-time:now)) :level level :file file :line line-no }) :encoding :utf-8) 'salza2:zlib-compressor))) (setf sock (usocket:socket-connect *graylog-host* *graylog-port* :protocol :datagram :element-type 'ub8)) (usocket:socket-send sock msg (length msg)))) (usocket:socket-close sock)))
  • 13. Myth | Fact There's no Lisp SBCL – more than 10 programmers people contribute to each release, ABCL – There's no Lisp more than 5, etc. jobs This year: 2 Lisp Lisp community is conferences in Europe full of trolls for up to 100 people (ECLM & ECLS) & Lisp hasn't been numerous Lisp user developed for years groups meetings http://lisp-univ-etc.blogspot.com/search/label/lisp-hackers
  • 14. Myth | Fact Lisp is slow Lisp is the fastest of popular dynamic languages Lisp can be faster than Java … or even C http://benchmarksgame. alioth.debian.org/u32q /lisp.php
  • 15. Cool Lisp Features 1. Macros 2. All the functional stuff 3. CLOS multimethods 4. Special variables 5. Condition system 6. Read macros 7. The richest calling convention 8. Etc.
  • 16. Macros This page is intentionally left blank
  • 17. Condition system Jedis redis = Redis.getClient(Redis.SOME_DB); try { while (!Thread.interrupted()) try { // do some useful work break; } catch (JedisException e) { Redis.returnBrokenClient(redis); redis = Redis.getClient(Redis.SOME_DB); } // do some other stuff } finally { Redis.returnClient(redis); }
  • 18. Condition system Jedis redis = Redis.getClient(Redis.SOME_DB); try { while (!Thread.interrupted()) try { // do some useful work break; } catch (JedisException e) { Redis.returnBrokenClient(redis); redis = Redis.getClient(Redis.SOME_DB); } // do some other stuff } finally { Redis.returnClient(redis); }
  • 20. Condition system (with-persistent-connection (host port) ;; do useful stuff ) (defmacro with-persistent-connection ((&key (host #(127 0 0 1)) (port 6379)) &body body) `(with-connection (:host ,host :port ,port) (handler-bind ((redis-connection-error (lambda (e) (warn "Reconnecting.") (invoke-restart :reconnect)))) ,@body)))
  • 21. Condition system (defmacro with-reconnect-restart (&body body) `(handler-case (progn ,@body) (usocket:connection-refused-error (e) (reconnect-restart-case (:error e :comment "Can't connect”) ,@body)) ((or usocket:socket-error stream-error end-of-file) (e) (reconnect-restart-case (:error e) ,@body)))))
  • 22. Condition system (defmacro reconnect-restart-case ((&key error comment) &body body) `(if *pipelined* (progn ,@body) (restart-case (error 'redis-connection-error :error ,error :comment ,comment) (:reconnect () :report "Trying to reconnect" (reconnect) ,@body)))) http://lisp-univ-etc.blogspot.com/2012/11/cl-redis-separation- of-concerns-in.html
  • 23. Read macros { x ! x <- (loop :for i :upto 10 :collect i) } '(0 1 2 3 4 5 6 7 8 9 10 ) {x ! x <- '(1 nil 2) ! x} '(1 2) {x y ! x <- '(1 2 3) y <- '(5 6 7) ! (oddp x) (> y 5)} '((3 7)) { (+ x y) ! x <- '(1 2 3) y <- '(5 6 7) ! (oddp x) (> y 5) } '(10) (set-macro-character #{ #'read-listcomp) (set-macro-character #} (get-macro-character #)))
  • 24. (defun read-listcomp (stream char) "Read list comprehension { vars ! generators [! conditions]? }" (declare (ignore char)) (let (rezs srcs conds state) (dolist (item (read-delimited-list #} stream)) (if (eql '! item) (setf state (if state :cond :src)) (case state (:src (push item srcs)) (:cond (push item conds)) (otherwise (push item rezs))))) (setf rezs (reverse rezs) srcs (reverse srcs) conds (reverse conds)) (let ((binds (mapcar #`(cons (first %) (third %)) (group 3 srcs)))) `(mapcan (lambda ,(mapcar #'car binds) (when (and ,@conds) (list ,(if (rest rezs) (cons 'list rezs) (first rezs))))) ,@(mapcar #'cdr binds)))))
  • 25. Lisp is Python on steroids but w/o batteries :)
  • 26. Lisp in My View 1. Rich, non-exclusive culture 2. Consistency & simplicity 3. Mature interactive environment 4. Multi-paradigm language 5. Unique features 6. Cool non-unique features 7. Performant grown-up runtimes
  • 27. Lisp Resources 1. Hyperspec - http://clhs.lisp.se/Front/Contents.htm 2. Cookbook - http://cl-cookbook.sourceforge.net/ 3. Cliki – http://cliki.net 4. lispdoc - http://lispdoc.com/ 5. Google Styleguide - http://google-styleguide.googlecode.com/svn/trunk/lispguide.xml 6. L1sp.org - http://l1sp.org/ 7. Lisp books - http://pinterest.com/vseloved/lisp-books/