Append
Encyclopedia
|
| Tutorials | Encyclopedia | Dictionary | Directory |
|
Append
In general, to In computer programming,
Lisp
(append '(1 2 3) '(a b) '() '(6)) ;Output: (1 2 3 a b 6) Since the The Implementation
(define append
(lambda (ls1 ls2)
(if (null? ls1)
ls2
(cons (car ls1) (append (cdr ls1) ls2)))))
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 append([],Ys,Ys).
append([X|Xs],Ys,[X|Zs]) :-
append(Xs,Ys,Zs).
This predicate can be used for appending, but also for picking lists apart. Calling ?- append(L,R,[1,2,3]). 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. append a b = reduce cons b a 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: append :: [a] -> [a] -> [a] append xs ys = foldr (:) ys xs This is essentially a reimplementation of Haskell's 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
Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article
|
|
top
©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement