Skip to content

Commit

Permalink
Add concat
Browse files Browse the repository at this point in the history
  • Loading branch information
Edd12321 committed Jun 19, 2023
1 parent f395fd7 commit 2f024ea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions doc/man1/concat.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.TH CONCAT 1
.SH NAME
CONCAT \- "Flatten" (concatenate) lists
.SH SYNOPSIS
.BI "concat [" "<w1> <w2>...<wn>" ]
.SH DESCRIPTION
The
.I concat
utility joins together its arguments with spaces. If the args are lists (see
.BI stdlib/lists ),
then it has the same effect as merging the lists together.
4 changes: 4 additions & 0 deletions doc/man1/zrc.1
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ Change directory.
.br
Get a char's ASCII code.
.HP
.BI concat
.br
Concatenate lists
.HP
.BI continue
.br
Skip a step in a loop.
Expand Down
12 changes: 8 additions & 4 deletions examples/quicksort.zrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!../bin/zrc
###########################################
# Trivial quicksort implementation in Zrc.#
###########################################
%include list

fn quicksort {
Expand Down Expand Up @@ -26,10 +29,11 @@ fn quicksort {
}
set $vn = '$$vn $x'
}
return "
[quicksort $less]
$equal
[quicksort $greater]"
return [concat \
[quicksort $less] \
$equal \
[quicksort $greater]
];
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Command(eval) { return eval(combine(argc, argv, 1)); }
/** Variable type commands **/
Command(array) { return array(argc, argv); }
Command(string) { return string(argc, argv); }
/** Merge lists **/
Command(concat) { return combine(argc, argv, 1); }

/** Evaluates an arithmetic expression **/
Command(expr) {
Expand Down Expand Up @@ -802,7 +804,8 @@ const DispatchTable<std::string, std::function<std::string(int, char**)>> dispat
de(source) , de(string) , de(switch),
de(unalias) , de(unless) , de(unset),
de(until) , de(wait) , de(while),
de(subst) , de(break) , de(continue)
de(subst) , de(break) , de(continue),
de(concat)
};

/** Show a list of all BuiltIns **/
Expand Down

0 comments on commit 2f024ea

Please sign in to comment.