Shift list elements to left by 3: Difference between revisions

Added PL/0
(Elixir)
(Added PL/0)
Line 1,395:
<syntaxhighlight lang="picolisp">(let L (range 1 9)
(println (conc (tail -3 L) (head 3 L))) )</syntaxhighlight>
 
=={{header|PL/0}}==
PL/0 has no data structures, not even arrays. This sample simulates an array using separate variables for each element. The simulated array is then used to represent the list.
<br>
The output shows the original list (one element per line) and the shifted list, separated by -111.
<syntaxhighlight lang="pascal">
const maxlist = 8;
var sub, v, l1, l2, l3, l4, l5, l6, l7, l8;
procedure getelement;
begin
if sub = 1 then v := l1;
if sub = 2 then v := l2;
if sub = 3 then v := l3;
if sub = 4 then v := l4;
if sub = 5 then v := l5;
if sub = 6 then v := l6;
if sub = 7 then v := l7;
if sub = 8 then v := l8;
end;
procedure setelement;
begin
if sub = 1 then l1 := v;
if sub = 2 then l2 := v;
if sub = 3 then l3 := v;
if sub = 4 then l4 := v;
if sub = 5 then l5 := v;
if sub = 6 then l6 := v;
if sub = 7 then l7 := v;
if sub = 8 then l8 := v;
end;
procedure shiftleft;
var first;
begin
sub := 1;
call getelement;
first := v;
sub := 0;
while sub < maxlist do begin
sub := sub + 2;
call getelement;
sub := sub - 1;
call setelement
end;
sub := maxlist;
v := first;
call setelement
end;
begin
sub := 0;
while sub < maxlist do begin
sub := sub + 1;
v := sub;
call setelement;
! v
end;
call shiftleft;
call shiftleft;
call shiftleft;
! -111;
sub := 0;
while sub < maxlist do begin
sub := sub + 1;
call getelement;
! v
end
end.
</syntaxhighlight>
{{out}}
<pre>
1
2
3
4
5
6
7
8
-111
4
5
6
7
8
1
2
3
</pre>
 
=={{header|Python}}==
3,038

edits