Hy (programming language)

Last updated
Hy
Hy Cuddles.png
Hy logo – Cuddles the cuttlefish
Paradigm Multi-paradigm: procedural, functional, object-oriented, meta, reflective, generic
Family Lisp
Designed by Paul Tagliamonte
Developers Core team
First appeared2013;11 years ago (2013)
Stable release
1.0.0 [1]   OOjs UI icon edit-ltr-progressive.svg / 22 September 2024;1 day ago (22 September 2024)
Scope lexical, optionally dynamic[ citation needed ]
Platform IA-32, x86-64
OS Cross-platform
License MIT-style
Filename extensions .hy
Website hylang.org
Influenced by
Kawa, Clojure, Common Lisp

Hy is a dialect of the Lisp programming language designed to interact with Python by translating s-expressions into Python's abstract syntax tree (AST). [2] [3] Hy was introduced at Python Conference (PyCon) 2013 by Paul Tagliamonte. [4] Lisp allows operating on code as data (metaprogramming), thus Hy can be used to write domain-specific languages. [5]

Contents

Similar to Kawa's and Clojure's mappings onto the Java virtual machine (JVM), [6] [7] Hy is meant to operate as a transparent Lisp front-end for Python. [8] It allows Python libraries, including the standard library, to be imported and accessed alongside Hy code with a compiling [note 1] step where both languages are converted into Python's AST. [note 2] [9] [10] [11]

Example code

From the language documentation: [12]

=>(print"Hy!")Hy!=>(defn salutationsnm[name](print(+"Hy "name"!")))=>(salutationsnm"YourName")HyYourName!

See also

Notes

  1. The term "compiled" may apply to expressing Hy code in Python's AST or converting that AST into bytecode, the latter being dependent on the specific Python interpreter used and not Hy.
  2. Hy is tested on Python 2.7, 3.4 through 3.6, and PyPy.

Related Research Articles

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

<span class="mw-page-title-main">Lisp (programming language)</span> Programming language family

Lisp is a family of programming languages with a long history and a distinctive, fully parenthesized prefix notation. Originally specified in the late 1950s, it is the second-oldest high-level programming language still in common use, after Fortran. Lisp has changed since its early days, and many dialects have existed over its history. Today, the best-known general-purpose Lisp dialects are Common Lisp, Scheme, Racket, and Clojure.

<span class="mw-page-title-main">Python (programming language)</span> General-purpose programming language

Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.

Programming languages can be grouped by the number and types of paradigms supported.

Metaprogramming is a computer programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyse, or transform other programs, and even modify itself, while running. In some cases, this allows programmers to minimize the number of lines of code to express a solution, in turn reducing development time. It also allows programs more flexibility to efficiently handle new situations with no recompiling.

In some programming languages, eval, short for the English evaluate, is a function which evaluates a string as though it were an expression in the language, and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval. The input to eval is not necessarily a string; it may be structured representation of code, such as an abstract syntax tree, or of special type such as code. The analog for a statement is exec, which executes a string as if it were a statement; in some languages, such as Python, both are present, while in other languages only one of either eval or exec is.

<span class="mw-page-title-main">PyPy</span> Alternative implementation of the Python programming language

PyPy is an implementation of the Python programming language. PyPy often runs faster than the standard implementation CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPython extensions, which either does not work or incurs some overhead when run in PyPy.

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into a binary dynamic-link library.

In programming, a docstring is a string literal specified in source code that is used, like a comment, to document a specific segment of code. Unlike conventional source code comments, or even specifically formatted comments like docblocks, docstrings are not stripped from the source tree when it is parsed and are retained throughout the runtime of the program. This allows the programmer to inspect these comments at run time, for instance as an interactive help system, or as metadata.

In functional programming, filter is a higher-order function that processes a data structure in some order to produce a new data structure containing exactly those elements of the original data structure for which a given predicate returns the boolean value true.

libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.

<span class="mw-page-title-main">Clojure</span> Dialect of the Lisp programming language on the Java platform

Clojure is a dynamic and functional dialect of the Lisp programming language on the Java platform.

Elixir is a functional, concurrent, high-level general-purpose programming language that runs on the BEAM virtual machine, which is also used to implement the Erlang programming language. Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides tooling and an extensible design. The latter is supported by compile-time metaprogramming with macros and polymorphism via protocols.

<span class="mw-page-title-main">Julia (programming language)</span> Dynamic programming language

Julia is a high-level, general-purpose dynamic programming language, most commonly used for numerical analysis and computational science. Distinctive aspects of Julia's design include a type system with parametric polymorphism and the use of multiple dispatch as a core programming paradigm, efficient garbage collection, and a just-in-time (JIT) compiler. Notably Julia does not support classes with encapsulated methods and instead it relies on structs with separate functions.

In computer science, the expression code as data refers to the idea that source code written in a programming language can be manipulated as data, such as a sequence of characters or an abstract syntax tree (AST), and it has an execution semantics only in the context of a given compiler or interpreter. The notion is often used in the context of Lisp-like languages that use S-expressions as their main syntax, as writing programs using nested lists of symbols makes the interpretation of the program as an AST quite transparent.

In computer programming, self-hosting is the use of a program as part of the toolchain or operating system that produces new versions of that same program—for example, a compiler that can compile its own source code. Self-hosting software is commonplace on personal computers and larger systems. Other programs that are typically self-hosting include kernels, assemblers, command-line interpreters and revision control software.

In computer science, interning is re-using objects of equal value on-demand instead of creating new objects. This creational pattern is frequently used for numbers and strings in different programming languages. In many object-oriented languages such as Python, even primitive types such as integer numbers are objects. To avoid the overhead of constructing a large number of integer objects, these objects get reused through interning.

References

  1. "Hy 1.0.0, the Lisp dialect for Python, has been released · hylang hy · Discussion #2608" . Retrieved 23 September 2024.
  2. Jaworski, Michał; Ziadé, Tarek (2019). Expert Python programming (Third ed.). Birmingham, U.K.: Packt Publishing. p. 173. ISBN   978-1-78980-677-9. OCLC   1125343555.
  3. Danjou, Julien (2018). Serious Python: black-belt advice on deployment, scalability, testing, and more. San Francisco, CA: No Starch Press. pp. 145–149. ISBN   9781593278793. OCLC   1057729260.
  4. Tagliamonte, Paul (2 April 2013). PyCon lightning talk (Speech). Python Conference (PyCon). Santa Clara. Retrieved 2 September 2014.
  5. Tagliamonte, Paul (11 April 2014). Getting Hy on Python: How to implement a Lisp front-end to Python (Speech). PyCon. Montreal. Retrieved 2 September 2014.
  6. Turto, Tuukka (14 February 2014). "Programming Can Be Fun with Hy". Open Source For You . Retrieved 2 September 2014.
  7. Watson, Mark (2020). A Lisp Programmer Living in Python-Land: The Hy Programming Language (PDF). LeanBooks.
  8. Edge, Jake (30 April 2014). "Getting Hy on Python". LWN.net . Retrieved 2 September 2014.
  9. "Hy Documentation". hylang.org. Retrieved 3 September 2014.
  10. Danjou, Julien (26 March 2014). "The AST". The Hacker's Guide to Python. pp. 165–172.
  11. Kitchin, John (31 March 2016). "More on Hy and why I think it is a big deal". The Kitchin Research Group. Carnegie Mellon University . Retrieved 19 September 2018.
  12. "Quickstart". Hylang.org. 15 May 2018. Retrieved 19 September 2018.
19581960196519701975198019851990199520002005201020152020
 LISP 1, 1.5, LISP 2(abandoned)
  Maclisp
  Interlisp
  MDL
  Lisp Machine Lisp
  Scheme  R5RS R6RS R7RS small
  NIL
  ZIL (Zork Implementation Language)
  Franz Lisp
  Common Lisp  ANSI standard
  Le Lisp
  MIT Scheme
  XLISP
  T
  Chez Scheme
  Emacs Lisp
  AutoLISP
  PicoLisp
  Gambit
  EuLisp
  ISLISP
  OpenLisp
  PLT Scheme   Racket
  newLISP
  GNU Guile
  Visual LISP
  Clojure
  Arc
  LFE
  Hy
  Chialisp