Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
Accelerator
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
qianfeiqianlan
/
RacketGuideInChinese
Public
forked from
OnRoadZy/RacketGuideInChinese
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
RacketGuideInChinese
/
02.4.3 列表和Racket的语法
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
27 lines (16 loc) · 1.58 KB
master
Breadcrumbs
RacketGuideInChinese
/
02.4.3 列表和Racket的语法
Copy path
Top
File metadata and controls
Code
Blame
27 lines (16 loc) · 1.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2.4.3 列表和Racket的语法
现在你已经知道了关于配对和列表的真相,而且现在你已经明白了quote,你已经准备好理解我们一直在简化Racket真实语法的主要方法。
Racket的语法并不是直接用字符流来定义的。相反,语法是由两层确定的:
1、读取器层,将字符序列转换成列表、符号和其他常量;
2、一个扩展层,它处理列表、符号和其他常量,将它们解析为表达式。
打印和阅读的规则是一致的。例如,一个列表用圆括号打印,读一对圆括号生成一个列表。类似地,一个非列表对用点表示法打印,输入的一个点有效地运行点标记规则从反向得到一个配对。
表达式读取层的一个结果是,可以在不引用的表达式中使用点标记:
> (+ 1 . (2))
3
这是因为(+ 1 . (2))只是(+ 1 2)的另一种法。用这种点表示法编写应用程序表达式实际上并不是一个好主意,它只是定义了Racket语法的一个结果。
通常,在括号序列里只有一个.是被读者允许的,并且只有在序列的最后一个元素。然而,一对.也可以出现在一个括号序列的单个元素周围,只要不是第一个或最后一个元素。这样的一对触发阅读器转换,将元素从.移动到列表的前面。转换可以使一种普遍的中缀表示法成为可能:
> (1 . < . 2)
#t
> '(1 . < . 2)
'(< 1 2)
这两个点约定是非传统的,它与非列表对的点记法基本上没有关系。Racket程序员使用中缀标记——多为非对称二元操作符如<和is-a?。
You can’t perform that action at this time.