Function Programming Paradigm
Function Programming Paradigm
项目类别:数学

Lab 5 Functional Programming 2, the Term Project

Function Programming Paradigm

This project must be completed using the Function Programming paradigm:

1.No global variables are allowed; local variables in general are discouraged

2.If you have local variables; they must be immutable

3.No for loops, while loops, or other loops

4.In general, assignment statements are discouraged and should be limited.

Making code easier to read is OK

5.You are encouraged to use lambda functions and higher order functions

6.Function features such as composition, closure, and currying are good

7.Functions should be small. Succinctness and readability are good

8.Recursive programming is good

The Line Editor Project

The project involves coding a simple line editor in Python using FP. If you have taken my CSCI 40 class, this editor is even simpler than that one. However, the design rules are precise - you must create the features exactly as described - do not add, change or delete features. If you don't follow these design guidelines, your program may not perform project test scripts correctly

This is a very primitive editor. This is like an old fashion DOS editor where the user enters a simple command that changes the text file that he is editing. Each command starts with a keyword that indicates the type of operation to perform


Some commands act on one line at a time; others act on the entire file. You can't enter content into a line until the empty blank line is created first. To keep the project simple, there are no command abbreviations so you must type the entire keyword to process it. The editor is very simple; for instance, there is no save command back to a disk file


You can, however, process a series of commands from a "batch” command file. As part of this project, your instructor will provide a command file for you to test your software. If the program has any discrepancies, that should be detected in the output. Thus, for Canvas, please submit your Jupyter file. This an individual project, so please don't share your code or your work..

Line numbers

Each line in the document has an implicit line number.

●The first line is line number is 1; the next one is 2. Line numbers are incremented by 1 sequentially to the end of the document

●Line numbers are not permanently attached to their line content. The line number for a line can move up or down as you dynamically insert or delete lines from the user data

●When you first start the program, there are no lines. The first insert command creates an empty blank line at line 1. The first typeover command on line 1 enters content to that line

The Editor commands

These are the commands of the editor as shown through sample lines. If the command requires a line number, the sample line will be shown a line number along with other options  

1.insert 5 - inserts an empty blank line at at line position 5; old #5 becomes new #6, old #6 becomes new #7, and so forth to the end of the document. If line #4 does not yet exist, the new line is created with the first available line number beyond the end-of-document. For instance, If the document is empty, the line is created at #1 regardless of the number requested in the command. The user can not get an error with this command


2.delete 5 - deletes line 5; old line #6 is promoted to become new #5, old #7 becomes new #6, and so forth. If line 5 doesn't exist, the command is ignored. No error messages are generated by this program. Again, any input errors are silently ignored


3.typeover 5 <line content> - the contents of line 5 is replaced by the content in <line content>.  If line 5 doesn't exist, the command is ignored. An empty blank line first must be created first before content can be typed into that line position

4.fix 5 '<old text>' '<new text>' - changes line 5 by replacing the <old text> with the <new text>. It updates all occurrences in the line. The delimiter is a single quote. Nothing happens if <old text> is not found


5.printall - prints the contents of your document as a series of lines from the beginning to the end of the document. The output is thus a sequence of lines with each line exhibiting this format <line #>: <line content>

6.replace '<old text>' '<new text>' - searches every line of the document and replaces any <old text> with <new text>. The delimiter is a single quote


7.copy 5 to 10 - copies line 5 to line position 10; old #10 becomes new #11, old #11 becomes new #12, etc… If there is no line 5, the command is silently ignored. If the document doesn't reach line 10, the new line is placed at the end of the document at the next available number


8.execute <filename> - executes a test script of editor commands from the indicated file. Control returns to the console when the file ends. To keep things simple, the execute command can not be issued from inside a batch script; if issued, it is silently ignored like other user input error


An end-of-input from the file will return control back to the user in interactive mode. An end-of-input (a single carriage return by itself) in interactive mode will end the program


9.# <comment> - allows a comment line in the script file. The documentation information is ignored by the editor. It's primary purpose is to document the instructor's test script file so you can see any comments or instructions


10.dropmeta - If there are lines of user data that begins with “## “ starting in the first column, this command will delete that line from his data. This is a shortcut way to delete all user data that is not pertinent to the contents. It is a single command that rids all extraneous metadata that was inserted by copyright editors throughout the file


11.makenarrow - this command takes long lines of user text and chops them down to successive multiple lines that are 75 characters long with a dangling partial last line. To keep this simple, these shortened lines can be broken in the middle of the word to reach 75 characters exactly.  

Documenting your Program Statistics

Please track your program stats. Enter the following exact comment block of your statistics at the beginning of your program. This provides me an overview when I look at your program. My number counts are below and are probably typical (but not especially good or bad example of FP) - your mileage will vary, and that's OK


You don’t need to over-engineer this project.  I’ll just be looking at how well you do Functional Programming so you don’t have to worry about doing things like error checking, “try..catch” blocks, etc.. which we really didn’t cover in class

Instructor’s Program Statistics

●# of map functions2

●# of reduce functions1

●# of filter functions1

●# of lambda functions2

●# of recursive function calls2

●Total # of functions13

●# of global variables 0

●# of local variables 2

●# of mutable variables0

●Total # of variables2

●# of loops (for, while, etc..)0

●# of Python lines of code106

(not counting comment and blank lines)

Input Scripts, Testing and Evaluation


留学ICU™️ 留学生辅助指导品牌
在线客服 7*24 全天为您提供咨询服务
咨询电话(全球): +86 17530857517
客服QQ:2405269519
微信咨询:zz-x2580
关于我们
微信订阅号
© 2012-2021 ABC网站 站点地图:Google Sitemap | 服务条款 | 隐私政策
提示:ABC网站所开展服务及提供的文稿基于客户所提供资料,客户可用于研究目的等方面,本机构不鼓励、不提倡任何学术欺诈行为。