Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hylang - A Python powered Lisp AND a Lisp powered Python

Hylang - A Python powered Lisp AND a Lisp powered Python

Hylang is a lisp that is written in python that compiles down to python itself. This is a talk given during the Chennaipy February meetup 2015.

Shrayas Rajagopal

February 28, 2015
Tweet

More Decks by Shrayas Rajagopal

Other Decks in Programming

Transcript

  1. (
    Chennaipy
    Feb 2015

    View full-size slide

  2. Shrayas
    Logic Soft

    View full-size slide

  3. A
    Lisp powered
    Python

    View full-size slide

  4. A
    Python powered
    Lisp

    View full-size slide

  5. John McCarthy
    1958

    View full-size slide

  6. Polish
    Notation

    View full-size slide

  7. (+ 1 1)
    S-EXPRESSIONS

    View full-size slide

  8. (+ 1 1)
    S-EXPRESSIONS
    Function

    View full-size slide

  9. (+ 1 1)
    S-EXPRESSIONS
    Arguments

    View full-size slide

  10. Variable
    Arity!

    View full-size slide

  11. 1 + 2 + 3 + 4 + 5
    Infix

    View full-size slide

  12. (+ 1 2 3 4 5)
    1 + 2 + 3 + 4 + 5
    Infix
    S-Expressions

    View full-size slide

  13. Dialects
    Arc, AutoLISP, Clojure, Common Lisp, Emacs Lisp,
    EuLisp, Franz Lisp, Interlisp, ISLISP, LeLisp, LFE,
    Maclisp, MDL, Newlisp, NIL, Picolisp, Portable
    Standard Lisp, Racket, Scheme, SKILL, Spice Lisp, T,
    XLISP, Zetalisp

    View full-size slide

  14. Dialects
    Arc, AutoLISP, Clojure, Common Lisp, Emacs Lisp,
    EuLisp, Franz Lisp, Interlisp, ISLISP, LeLisp, LFE,
    Maclisp, MDL, Newlisp, NIL, Picolisp, Portable
    Standard Lisp, Racket, Scheme, SKILL, Spice Lisp, T,
    XLISP, Zetalisp

    View full-size slide

  15. hylang.org
    @paultag et al.

    View full-size slide

  16. Getting & Running
    $ pip install hy
    $ hy

    View full-size slide

  17. Lisp
    in Python

    View full-size slide

  18. Pythonic
    Lisp
    1

    View full-size slide

  19. Absurd
    Powers!!!!1
    2

    View full-size slide

  20. Great Py
    Interop
    4

    View full-size slide

  21. def say_hello(name):
    print "Hello", name
    if __name__ == "__main__":
    say_hello("Python")
    python
    Hello, python

    View full-size slide

  22. def say_hello(name):
    print "Hello", name
    if __name__ == "__main__":
    say_hello("Python")
    (defn say_hello [name]
    (print "Hello" name))
    (if (= __name__ "__main__")
    (say_hello "python"))
    python
    hylang
    Hello, python

    View full-size slide

  23. python
    Data Structures
    >>> [1,2,3]
    >>> {"foo": 1, "bar": 2, "baz": 3}
    >>> (1,2,3)

    View full-size slide

  24. python
    hylang
    Data Structures
    >>> [1,2,3]
    >>> {"foo": 1, "bar": 2, "baz": 3}
    >>> (1,2,3)
    => [1 2 3]
    => {"foo" 1 "bar" 2 "baz" 3}
    => (, 1 2 3)

    View full-size slide

  25. python
    Fn on Objects
    >>> "Hello World".upper()
    ”HELLO WORLD"

    View full-size slide

  26. python
    hylang
    Fn on Objects
    >>> "Hello World".upper()
    ”HELLO WORLD"
    ⇒ (.upper "Hello world")
    "HELLO WORLD"

    View full-size slide

  27. python
    Conditionals
    if (foo > 5):
    print "foo more than 5!"
    else:
    print "foo less than 5!"

    View full-size slide

  28. python
    hylang
    Conditionals
    if (foo > 5):
    print "foo more than 5!"
    else:
    print "foo less than 5!"
    (if (> foo 5)
    (print "foo more than 5!")
    (print "foo less than 5!"))

    View full-size slide

  29. python
    Conditionals (more)
    if (foo > 7):
    print "Too much"
    elif (foo < 7):
    print "Too less"
    else:
    print "ok :)"

    View full-size slide

  30. hylang
    Conditionals (more)
    (cond
    [(> foo 7)
    (print "Too much")]
    [(< foo 7)
    (print "Too less")]
    [true
    (print "ok :)")])

    View full-size slide

  31. python
    Loops
    for i in xrange(10):
    print i

    View full-size slide

  32. python
    hylang
    Loops
    for i in xrange(10):
    print i
    (for [i (xrange 10)]
    (print i))

    View full-size slide

  33. hylang
    Hy import Py
    (import os)
    (if (not (os.path.isdir "/foo/bar"))
    (os.mkdir "/foo/bar"))

    View full-size slide

  34. hylang
    (hymath.hy)
    Interop!
    (defn square [x]
    "returns square of x"
    (* x x))

    View full-size slide

  35. python
    (usemath.py)
    hylang
    (hymath.hy)
    Interop!
    (defn square [x]
    "returns square of x"
    (* x x))
    import hy
    import hymath
    print hymath.square(8)

    View full-size slide

  36. hylang is a pythonic lisp
    1
    Recap

    View full-size slide

  37. hylang is a pythonic lisp
    1
    Has great interop with python
    2
    Recap

    View full-size slide

  38. hylang is a pythonic lisp
    1
    Has great interop with python
    2
    Great excuse to learn Lisp
    3
    Recap

    View full-size slide

  39. hylang is a pythonic lisp
    1
    Has great interop with python
    2
    Great excuse to learn Lisp
    3
    A new language
    4
    Recap

    View full-size slide

  40. Fin
    @shrayasr

    View full-size slide