rebol——最近纪念日提醒

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

源码如下:

数据文件:special-date.dat

REBOL []	

	"janny's birthday"  [3 26] 
	"wedding" 	    [6 15] 
	"christmas"	    [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,就是说可以算出三个纪念日距离今天还有多少天,我们只需要比较出他们之间最小的那个,把它对应的纪念日输出来就可以了。好的,完成作业了,祝明天考试顺利!


你可能感兴趣的:(Rebol)