Skip to content

Overview

In this section, I'll give a pair of LisPy code and corresponding Python code for each AST node. Checkout the Python AST documentation for more information about each node.

Corresponding python code is generated by l2py command in usage section.

example

LisPy Version

(print "Hello, World!")
Python version
print("Hello, World!")

Lexical syntax

  • ; starts a comment that runs to the end of the line. It ends any token, so a comment may follow with no space: (print "a"); comment.
  • Hyphens in a name become underscores in Python: my-var is my_var.
  • :kw value inside a call is the keyword argument kw=value: (f a :kw 1 :other-kw 2) is f(a, kw=1, other_kw=2).
  • *x and **x unpack a sequence or mapping in a call: (f *xs **kw) is f(*xs, **kw). The * or ** is glued to the form.
  • ^type is a type annotation; it follows the name it annotates: (def f [a ^int b] ^int ...) is def f(a: int, b) -> int, and (= a ^int 1) is a: int = 1.
  • ', `, ~ and ~@ (quote, syntax-quote, unquote, unquote-splicing) are glued to the form they apply to; ' x is an error.
  • A string may span lines: the line break is part of the string.