Reverse words in a string: Difference between revisions

Added Easylang
m (syntax highlighting fixup automation)
(Added Easylang)
 
(9 intermediate revisions by 8 users not shown)
Line 656:
 
----------------------- Robert Frost</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Split ← +`∘<⟜»⊸×⊸-⟜¬∘>⟜' '⊸⊔
Join ← (⊣∾' '∾⊢)´⍟(1<≡)
 
text ← ⍉≍⟨
"---------- Ice and Fire ------------"
""
"fire, in end will world the say Some"
"ice. in say Some "
"desire of tasted I've what From "
"fire. favor who those with hold I "
""
"... elided paragraph last ..."
""
"Frost Robert -----------------------"⟩
 
Join∘⌽∘Split¨ text</syntaxhighlight>
Alternative based on the approach described in [https://saltysylvi.github.io/blog/flat1.html this blog post]:
<syntaxhighlight lang="bqn">{(⍒+`∨⟜»' '=𝕩)⊏𝕩}¨ text</syntaxhighlight>
{{out}}
<pre>┌─
╵ "------------ Fire and Ice ----------"
⟨⟩
"Some say the world will end in fire,"
"Some say in ice."
"From what I've tasted of desire"
"I hold with those who favor fire."
⟨⟩
"... last paragraph elided ..."
⟨⟩
"----------------------- Robert Frost"
┘</pre>
 
=={{header|Bracmat}}==
Line 1,099 ⟶ 1,132:
end.</syntaxhighlight>
The output is the same as the Pascal entry.
 
=={{header|EasyLang}}==
<syntaxhighlight>
repeat
s$ = input
until error = 1
s$[] = strsplit s$ " "
for i = len s$[] downto 1
write s$[i] & " "
.
print ""
.
input_data
--------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 1,135 ⟶ 1,192:
 
=={{header|Elena}}==
ELENA 56.0x:
<syntaxhighlight lang="elena">import extensions;
import system'routines;
Line 1,152 ⟶ 1,209:
"Frost Robert -----------------------"};
text.forEach::(line)
{
line.splitBy:(" ").sequenceReverse().forEach::(word)
{
console.print(word," ")
Line 1,714 ⟶ 1,771:
->
</pre>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(var poem
"---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------")
 
(function split-join by then x
(-> x (split by) then (join by)))
 
(split-join "\n" (map @(split-join " " reverse)) poem)</syntaxhighlight>
 
=={{header|J}}==
Line 2,823 ⟶ 2,898:
 
----------------------- Robert Frost</pre>
 
Another version (tested with FPC 3.2.2)
<syntaxhighlight lang="pascal">
program reverse_words;
{$mode objfpc}{$h+}
uses
SysUtils;
 
function Reverse(a: TStringArray): TStringArray;
var
I, J: SizeInt;
t: Pointer;
begin
I := 0;
J := High(a);
while I < J do begin
t := Pointer(a[I]);
Pointer(a[I]) := Pointer(a[J]);
Pointer(a[J]) := t;
Inc(I);
Dec(J);
end;
Result := a;
end;
 
const
Input =
'---------- Ice and Fire -----------' + LineEnding +
'' + LineEnding +
'fire, in end will world the say Some' + LineEnding +
'ice. in say Some' + LineEnding +
'desire of tasted I''ve what From' + LineEnding +
'fire. favor who those with hold I' + LineEnding +
'' + LineEnding +
'... elided paragraph last ...' + LineEnding +
'' + LineEnding +
'Frost Robert -----------------------' + LineEnding;
var
Line: string;
 
begin
for Line in Input.Split([LineEnding], TStringSplitOptions.ExcludeLastEmpty) do
WriteLn(string.Join(' ', Reverse(Line.Split([' ']))));
end.
</syntaxhighlight>
 
=={{header|Perl}}==
Line 3,406 ⟶ 3,526:
----------------------- Robert Frost
</syntaxhighlight>
 
=={{header|RPL}}==
« { }
'''WHILE''' OVER " " POS '''REPEAT'''
LASTARG → sep
« OVER 1 sep SUB +
SWAP sep 1 + OVER SIZE SUB SWAP
»
'''END'''
SWAP + REVLIST
'''IFERR''' ∑LIST '''THEN''' 1 GET '''END'''
» '<span style="color:blue">REVWORDS</span>' STO
{ "---------- Ice and Fire ------------" "" "fire, in end will world the say Some" "ice. in say Some" "desire of tasted I've what From" "fire. favor who those with hold I" "" "... elided paragraph last ..." "" "Frost Robert -----------------------" }
1 « <span style="color:blue">REVWORDS</span> » DOLIST
 
{{out}}
<pre>
1: { "------------ Fire and Ice ----------"
""
"Some say the world will end in fire,"
"Some say in ice."
"From what I've tasted of desire"
"I hold with those who favor fire."
""
"... last paragraph elided ..."
""
"----------------------- Robert Frost" }
</pre>
 
=={{header|Ruby}}==
Line 4,004 ⟶ 4,153:
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
mut n := [
"---------- Ice and Fire ------------",
Line 4,070 ⟶ 4,219:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var lines = [
"---------- Ice and Fire ------------",
" ",
2,046

edits