Hy (lisp)

本文从1958年的Lisp语言出发,介绍了一种现代的、能够与Python交互的语言Hy。Hy通过将表达式转换为Python的抽象语法树(AST),实现了与Python的无缝对接。文章深入探讨了Lisp的基本构建块,包括原子、列表、字符串等概念,并讲解了宏定义、变量声明和数据类型等关键特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

www.tutorialspoint.com/lisp/index.…

1958 (Lisp) -> 2020 (Hy)
Hy designed to interact with Python by translating expressions into Python's abstract syntax tree (AST)
(write-line "Hello World")
(write (+ 7 9 11))   # 7 + 9 + 11
(write (+ (* (/ 9 5) 60) 32))  # ((9/5)*60)+32
复制代码

basic building blocks

atom: numbers and special characters
123008907  abc123
复制代码
list: a sequence of atoms and/or other lists enclosed in parentheses
(a ( a b c) d e fgh)
复制代码
string: a group of characters enclosed in double quotation marks
" I am a string"
复制代码

semicolon symbol (;) is used for indicating a comment line case-insensitive three types of elements are constants and always return their own value Numbers; letter t, logical true; value nil, logical false, empty list

data types can be categorized as
Scalar types - for example, number types, characters, symbols etc
Data structures - for example, lists, vectors, bit-vectors, and strings
复制代码
macro is a function
(defmacro setTo10(num)
(setq num 10)(print num))
(setq x 25)
(print x)
(setTo10 x)
复制代码
Global variables are generally declared using the defvar construct.
(defvar x 234)
(write x)
复制代码
let and prog for creating local variables.
(prog ((x '(a b c))(y '(1 2 3))(z '(p q 10)))
(format t "x = ~a y = ~a z = ~a" x y z))  # x = (A B C) y = (1 2 3) z = (P Q 10)
复制代码

转载于:https://juejin.im/post/5c4f04c8e51d4551c8805ef2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值