Use a very small language rebol write calendar (Million almanac) printing program

Source: Internet
Author: User
Tags rebol

先上

由于课程设置,选修了一门非常非常小众的REBOL语言的程序设计概论,就自己观点来看,这门语言小众,语法晦涩,教材也不太好,书中作者试图一直把我们以门外汉这样灌输知识给我们,我觉得这点作者做的不是特别好,比如说流行语言中的变量,用书中作者的话就变成了单字。。。赋值就是设字。。。这看来非常的不专业,而且某种程度上貌似在拐弯,这是我对这本教材不能接受的地方。当然,对于初学者来说,这无可厚非。欸,怪我怪我,来了这么渣的专业,全机电学大物3,就我们班学大物2(2比3难),你说一堆搞机器人的学的比一堆学影视动画广告特技的还简单,这课程设置真是呵呵哒。 
好了,吐槽完了,说正事吧。这个日历是课程大作业,占总成绩30分。由于本系不是每个人都喜欢程序设计,就像我讨厌画画一样,欸,所以,在家靠父母,出门靠朋友,能帮的尽量帮咯。作业要求是本程序中的第二种输出,我多做了几个功能,源码也贴上吧。看到博客的相信你们都有需求,能改的尽量改咯,全抄的后果是啥我没试过。。。欸,也考考你们的动手能力啦

rebol[title: "Calendar" version:1.0.0 Author:wizchen]; Determine whether data is legitimate validata:func["judging data is legitimate" year [integer!]    month [integer!] Day [integer!]] [If (< 1) or (Year > 9999) or (month < 1) or (month > +)) [Return FALSE] if (day < 0) [return FALSE] if (day = =) [Return (month = = 2) and (Isleapyear year) or (month!) = 2)] if (day = =) [Return (month = = 1 or month = = 3 or month = = 5 or month = = 7 or Month = = 8 or Mon th = = Ten or month = =)] (if (Day >) [return FALSE] return TRUE]; If you enter a certain month of the year, the ' 1 ' operation is processed setday s:func["If you enter a certain day of the year, do ' 1 ' Operation processing"] [weekday:0 year:str2int Ask {Please input the yearly:} month:str2int Ask {plea SE input the Month:} day:str2int Ask {Please input the day:} while[! validata Year Month Day] [year: Str2Int Ask {input the year:} month:str2int ask {input the month:} day:str2int ASK {Please input the day:}] Weekday:remainder (getalldays Year Month day) 7 Switch/default WeekDay [         0 [Print [year]/' month '/' Day '/' "Today is Sunday"] outthreelines] 1            [Print [year]/' month '/' Day '/' "Today is Monday"] outthreelines] 2 [            Print [year '/' Month '/' Day '/' "Today is Tuesday"] outthreelines] 3 [            Print [year '/' Month '/' Day '/' "Today is Wednesday"] outthreelines] 4 [ Print [year '/' Month '/' Day '/' "Today is Thursday"] outthreelines] 5 [Print [Year '/' Month '/' Day '/' Today is Friday '] outthreelines] 6 [print [Year]/ ' Month '/' Day '/' Today is Saturday '] outthreelines]][print "data is illegal!"]; If you choose to enter the month of the year, do ' 2 ' Operation processing setmonth:func["If you choose to enter a yearOne month, do ' 2 ' Operation processing ' [weekday:0 year:str2int Ask {the year:} Month:str2int ask {The Mont H:} day:1 while[! Validata Year Month Day] [year:str2int Ask {Please input the Year:} Month:  Str2Int Ask {input the month:}] WeekDay: (Remainder (getalldays year month) 7 + 1) outprint year Month]; If you enter a year, do ' 3 ' Operation processing setyear:func["If you enter a year, do ' 3 ' Operation processing"] [m:1 year:str2int Ask {Please input the yearly:} month  : 1 day:1 while[! Validata Year Month Day] [year:str2int Ask {Please input the year:}] while[ M <= [Outprint year M m:m + 1]]; Function function: Prompts the user to enter, the operation chooses Inputdata:func ["Prompts the user to enter, carries on the Operation Choice"] [fl        Ag:true While[flag] [print] Welcome to my calendar,please input the selections below "print" Print "1:input the Year,month and day,showing what's it Today" print "" Print "2:input the year and M Onth,showing the Month CAlendar "Print" "Print" 3:input the year,showing the year calendar "print" "Print" 4:exit " Print "" Choose:str2int ask {Please input a number:} Switch/default Choose [1 [ Setdays] 2 [setmonth] 3 [setyear] 4 [quit]] [print] Wro            ng input,please Input again! "    Inputdata]]; Get this day distance from A.D. January 1, 1 How many days Getalldays:func ["Get This day away from A.D. January 1, 1 How many days" year [integer!]    month [integer!] Day [integer!]]    [I:1 j:1 monthdays:0 yeardays:0 sumdays:0 meverymonth: [31 28 31 30 31 30 31 31 30 31 30 31]        While loop self-added calculation of the number of years to the number of days while[i < year] [either Isleapyear I [Yeardays:yeardays + 366 ] [yeardays:yeardays + 365] i:i + 1]; the effect of the while loop self-added calculation of the number of months on the number of days while[J &L T Month] [Monthdays:monthdays + (pick Meverymonth j) if (isleapyearyear) [Monthdays:monthdays + 1] j:j + 1] sumdays:yeardays + monthdays + Day return sumdays]; determine if a leap year isleapyear:func["Determine if it is a leap year" year [integer!] [; take the remainder operator remainder arg1 arg2 return ((remainder year 4) = = 0) and ((remainder year)! = 0) or ((Remainder y Ear) = = 0)];string type to Integer type str2int:func["string type to Integer type" str [string!] [Return (To-integer str)]; month translation conversion monthtrans:func["month translation conversion" month [integer!]]  [Switch/default Month [1] [return "January"] 2 [Return "February"] 3 [Return "March"] 4        [Return "April"] 5 [Return "may"] 6 [Return "June"] 7 [Return "July"] 8 [return "August"]    9 [return "September"] [return "October"] one [return "November"] [return "December"]]    [Print "Data is illegal!"    ]]; formatted output outprint:func["formatted output" year [integer!]    month [integer!] [Weekday:0 day:1 N:1    Isfisrtline:true print ["" Year "A.D" (Monthtrans month)] print "SUN MON TUE WES THU FRI SAT "WeekDay: (Remainder (getalldays year month) 7) Switch/default WeekDay [0                       [Prin "] 1 [prin" "] 2 [Prin"                                          "] 3 [Prin" "] 4 [Prin"                                                  "] 5 [Prin] "] 6 [prin"] [    Print "Data is illegal!"] Meverymonth: [from £ º] while[n <= (pick meverymonth month)] [Weekday:rem Ainder WeekDay 7 either WeekDay = = 0 [either Isfisrtline [Prin]"] [print" "] isfisrtline:false prin" "            Outchar n] [either Isfisrtline [Prin ""]  [Prin "] Isfisrtline:false Outchar N] WeekDay: WeekDay + 1 n + 1] outthreelines]; format output string outchar:func["format output string" daynum[integer!]] [Either Daynum < [Prin ["" Daynum]] [prin["" daynum]]]; output three line null character Outthreelines:func ["Output three line null character"] [i:0 while[i <= 2] [print "" I:I + 1]]; Execute script inputdata

  

This same function of the calendar in C + + when written more than 200 lines, in this language used to write 300 lines. Well, C + + is already heavy enough, the scripting language looks really bad, better than his grasp a lot, personally think that learning Python is better than learning this. At least the number of people using Python more than rebol ... Hey, spit groove in the groove, and then what eggs to use it.

The last few built-in rebol functions to explain, lest you look at the foggy (you can also go to the official document to view the usage, or directly in the Rebol input?). FunctionName can see the function of functions, here functionname refers to the function of the name, for example, you want to check the function of the exit function, input? Exit, it returns the function's function):
1.remainder function function: Take out the remainder
2.pick function: Simply to remove the corresponding subscript data from a block
It's like there's nothing else to talk about, that's all.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Original Bo published in Csdn, address: http://blog.csdn.net/wiz_Chen/article/details/46780533

 

Use a very small language rebol write calendar (Million almanac) printing program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.