没志青年
发布于 2025-06-19 / 15 阅读
0

Cadence Skill

Skill 基础语法

表达式使用()

变量定义

(setq a 10)
(setq b 20)

相加

(add 2 3)

if 语句

(if (> a b)
    (println "a is greater than b")
    (println "a is less than or equal to b"))

函数

(defun add-two-numbers (x y)
  (+ x y))
​

内置函数

(println "Hello, Cadence Skill!")
(setq result (+ 10 5))  ; result = 15
(setq result (* 3 4))   ; result = 12
​
(setq my-list (list 1 2 3 4))
(car my-list)  ; 返回 1
(cdr my-list)  ; 返回 (2 3 4)
​

循环

(setq i 0)
(do ((i (+ i 1))) ((>= i 5)) (println i))  ; 输出 0, 1, 2, 3, 4
​

异常处理

(catch 'my-error
  (if (< 10 5)
      (throw 'my-error "An error occurred!")
      (println "No error")))
​

文件操作

(setq my-file (open "input.txt" "r"))
(setq line (read-line my-file))
(close my-file)
​

(setq my-file (open "output.txt" "w"))
(write-line "This is a test line." my-file)
(close my-file)
​

操作 Cadence