LISP基本语法

LISP基本语法 首页 / LISP入门教程 / LISP基本语法

基本构建块

LISP程序由三个基本构建块组成-

  • atom 原子

  • list 列表

  • string 字符串

原子Atom是连续字符的数字或字符串, 它包括数字和特殊字符。

hello-from-Learnfk-point
name
123008907
*hello*
Block#221
abc123

以下是一些有效列表list的示例-

( i am a list)
(a ( a b c) d e fgh)
(father tom ( susan bill joe))
(sun mon tue wed thur fri sat)
( )

字符串string是用双引号引起来的一组字符。

" I am a string"
"a ba c d efg #$%^&!"
"Please enter the following details :"
"Hello from 'Learnfk Point'! "

注释

分号(;)用于指示注释行。

无涯教程网

(write-line "Hello Learnfk") ; greet the Learnfk

; tell them your whereabouts

(write-line "I am at 'Learnfk Point'! Learning LISP")

当您单击执行按钮或键入Ctrl + E时,LISP立即执行它,返回的输出是-

链接:https://www.learnfk.comhttps://www.learnfk.com/lisp/lisp-basic-syntax.html

来源:LearnFk无涯教程网

Hello Learnfk

I am at 'Learnfk Point'! Learning LISP

命名约定

名称或符号可以由任意数量的字母数字字符组成,除了空格,左括号和右括号,双引号和单引号,反斜杠,逗号,冒号,分号和竖线之外,要在名称中使用这些字符,您需要使用转义符(\)。

名称可以有数字,但不能完全由数字组成,因为这样它将被读为数字。同样,名称可以有句点,但不能完全由句点组成。

单引号

为此,我们需要在原子或列表之前加单引号。

创建一个名为main.lisp的文件,然后在其中键入以下代码。

(write-line "single quote used, it inhibits evaluation")
(write '(* 2 3))
(write-line " ")
(write-line "single quote not used, so expression evaluated")
(write (* 2 3))

当您单击执行按钮或键入Ctrl + E时,LISP立即执行它,返回的输出是-

链接:https://www.learnfk.comhttps://www.learnfk.com/lisp/lisp-basic-syntax.html

来源:LearnFk无涯教程网

single quote used, it inhibits evaluation
(* 2 3) 
single quote not used, so expression evaluated
6

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

教程推荐

手把手带你写一个 MiniTomcat -〔郭屹〕

AI 应用实战课 -〔黄佳〕

说透低代码 -〔陈旭〕

超级访谈:对话张雪峰 -〔张雪峰〕

爆款文案修炼手册 -〔乐剑峰〕

成为AI产品经理 -〔刘海丰〕

趣谈Linux操作系统 -〔刘超〕

TensorFlow快速入门与实战 -〔彭靖田〕

Go语言核心36讲 -〔郝林〕

好记忆不如烂笔头。留下您的足迹吧 :)