rebol——最近纪念日提醒

本文介绍了一个使用Rebol语言实现的纪念日提醒程序。该程序通过比较当前日期与预设的特殊日期(如婚礼、圣诞节等),计算出距离这些日期的时间,并输出最近的纪念日名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

rebol的一个大作业,完善蔡学镛《编程ING人人都能学会程序设计》的架构实现提醒最近纪念日的功能。我在课本的基础上,增加了一点内容。

源码如下:

数据文件:special-date.dat

REBOL []	

	"janny's birthday"  [3 26] 
	"wedding" <span style="white-space:pre">	</span>    [6 15] 
	"christmas"<span style="white-space:pre">	</span>    [12 24] 


可复用功能模块:date-util.reb

REBOL [
	title: "date-util"
	name: 'date-util
	type: 'module
	version: 1.0.0
	file: %date-util.reb
	exports: [ before-date]
]
	before-date: func [
		{countdown to the next particular date }
		m [integer! none! ] "month" 	
		d [integer! none! ] "day"	 /local year ]
	[	
		unless all [ m d ] [ return none ]
		year: now/year
		if any [ now/month > m	all [ now/month = m now/day > d ] ]
		[
			year: year + 1
		]
		( to-date reduce [ year m d ] ) - now
	]

主程序:

REBOL [
	title: "special-date"
	version: 1.0.1
	author: huming
	needs: [ date-util 1.0.0 ]
]
	data: load %special-date.dat
	
	special-date: func [  s-day [string!] /local m-d m d ] [
		m-d: select data s-day
		set [ m d ] m-d
		before-date m d
	]

	a: special-date "wedding"
	b: special-date "christmas"
	c: special-date "janny's birthday"
	
	either a < b 
		[ 
			either a < c [ print "     wedding" ]
			[ print "     janny's birthday" ]
		]
		[ 
			either b < c [ print "     christmas" ]
			[ print "     janny's birthday" ]
		]


运行如下:



因为课本已经得到了special-date,就是说可以算出三个纪念日距离今天还有多少天,我们只需要比较出他们之间最小的那个,把它对应的纪念日输出来就可以了。好的,完成作业了,祝明天考试顺利!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值