Hy (lisp)

55次阅读

共计 1041 个字符,预计需要花费 3 分钟才能阅读完成。

https://www.tutorialspoint.co…
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 linecase-insensitivethree types of elements are constants and always return their own valueNumbers; 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)

正文完
 0