词条 | Append |
释义 |
In general, to append is to join or add on to the end of something. For example, an appendix is a section appended (added to the end) of a document. In computer programming, Lisp
Since the The Implementation
Append can also be implemented using fold-right: Other languagesFollowing Lisp, other high-level languages which feature linked lists as primitive data structures have adopted an Other languages use the PrologThe logic programming language Prolog features a built-in This predicate can be used for appending, but also for picking lists apart. Calling yields the solutions: L = [], R = [1, 2, 3] ; L = [1], R = [2, 3] ; L = [1, 2], R = [3] ; L = [1, 2, 3], R = [] MirandaThis right-fold, from Hughes (1989:5-6), has the same semantics (by example) as the Scheme implementation above, for two arguments. Where reduce is Miranda's name for fold, and cons constructs a list from two values or lists. For example, append [1,2] [3,4] = reduce cons [3,4] [1,2] = (reduce cons [3,4]) (cons 1 (cons 2 nil)) = cons 1 (cons 2 [3,4])) (replacing cons by cons and nil by [3,4]) = [1,2,3,4] HaskellThis right-fold has the same effect as the Scheme implementation above: This is essentially a reimplementation of Haskell's PerlIn Perl, the push function is equivalent to the append method, and can be used in the following way. The end result is a list containing [1, 2, 3] The unshift function appends to the front of a list, rather than the end The end result is a list containing [2, 3, 1] When opening a file, use the ">>" mode to append rather than over write. Note that when opening and closing file handles, one should always check the return value. PythonIn Python, use the list method "extend" or the infix operators + and += to append lists. After executing this code, l is a list containing [1, 2, 3, 4, 5], while the output generated is the list [1, 2, 3, 4, 5, 6, 7]. Do not confuse with the list method "append", which adds a single element to a list: Here, the result is a list containing [1, 2, 3]. BashIn Bash the append redirect is the usage of ">>" for adding a stream to something, like in the following series of shell commands: The stream "Goodbye world!" is added to the text file written in the first command. The ";" implies the execution of the given commands in order not simultaneously. So, the final content of the text file is: Hello world! Goodbye world! DOS commandappend is a DOS command that allows programs to open data files in specified directories as if they were in the current directory. It appends the directories to the search path list. References
5 : Functional programming|Lisp (programming language)|Programming constructs|Articles with example code|DOS on IBM PC compatibles |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。