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 }}
OnRoadZy
/
RacketGuideInChinese
Public
Notifications
You must be signed in to change notification settings
Fork
20
Star
172
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
RacketGuideInChinese
/
02.2.2 代码缩进
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
12 lines (7 loc) · 1.33 KB
master
Breadcrumbs
RacketGuideInChinese
/
02.2.2 代码缩进
Copy path
Top
File metadata and controls
Code
Blame
12 lines (7 loc) · 1.33 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
2.2.2 代码缩进
换行和缩进对于解析Racket程序来说并不重要,但大多数Racket程序员使用一套标准的约定来使代码更易读。例如,定义的主体通常在定义的第一行下缩进。标识符是在一个没有额外空格的括号内立即写出来的,而闭括号则从不自己独立一行。
DrRacket会根据标准风格自动缩进,当你输入一个程序或REPL表达式。例如,如果你点击进入后输入(define (greet name),那么DrRacket自动为下一行插入两个空格。如果你改变了代码区域,你可以在DrRacket打Tab选择它,并且DrRacket将重新缩进代码(没有插入任何换行)。象Emacs这样的编辑器提供Racket或Scheme类似的缩进模式。
重新缩进不仅使代码更易于阅读,它还会以你希望的方式给你更多的反馈,象你的括号是否匹配等等。例如,如果在函数的最后一个参数之后省略一个结束括号,则自动缩进在第一个参数下开始下一行,而不是在define关键字下:
(define (halfbake flavor
(string-append flavor " creme brulee")))
在这种情况下,缩进有助于突出错误。在其他情况下,在缩进可能是正常的,一个开括号没有匹配的闭括号,racket和DrRacket都在源程序的缩进中提示括号丢失。
You can’t perform that action at this time.