Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #20422 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2013-03-08 01:37 +0000 |
| Last post | 2013-07-07 03:20 +0000 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.forth
Rotate sequence "WJ" <w_a_x_man@yahoo.com> - 2013-03-08 01:37 +0000
Re: Rotate sequence "WJ" <w_a_x_man@yahoo.com> - 2013-07-07 03:20 +0000
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2013-03-08 01:37 +0000 |
| Subject | Rotate sequence |
| Message-ID | <khbfcu0gki@enews4.newsguy.com> |
P19 (**) Rotate a list N places to the left.
Examples:
* (rotate '(a b c d e f g h) 3)
(D E F G H A B C)
* (rotate '(a b c d e f g h) -2)
(G H A B C D E F)
Factor:
: rotate ( seq n -- seq )
dup 0 < [ abs cut* ] [ cut ] if
swap append
;
{ "a" "b" "c" "d" "e" } 2 rotate .
{ "c" "d" "e" "a" "b" }
{ "a" "b" "c" "d" "e" } -2 rotate .
{ "d" "e" "a" "b" "c" }
[toc] | [next] | [standalone]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2013-07-07 03:20 +0000 |
| Message-ID | <krampi$ocr$1@dont-email.me> |
| In reply to | #20422 |
WJ wrote:
> P19 (**) Rotate a list N places to the left.
> Examples:
> * (rotate '(a b c d e f g h) 3)
> (D E F G H A B C)
>
> * (rotate '(a b c d e f g h) -2)
> (G H A B C D E F)
>
> Factor:
>
> : rotate ( seq n -- seq )
> dup 0 < [ abs cut* ] [ cut ] if
> swap append
> ;
>
> { "a" "b" "c" "d" "e" } 2 rotate .
> { "c" "d" "e" "a" "b" }
> { "a" "b" "c" "d" "e" } -2 rotate .
> { "d" "e" "a" "b" "c" }
Julia:
julia> circshift( [2,3,4], 1)
3-element Int32 Array:
4
2
3
julia> circshift( [2,3,4], -1)
3-element Int32 Array:
3
4
2
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web