Jump to content

Reverse words in a string: Difference between revisions

no edit summary
No edit summary
Line 560:
 
IO.puts RC.reverse_words(txt)</lang>
 
=={{header|Emacs Lisp}}==
 
{{works with|GNU Emacs|24.5.1}}
 
<lang Emacs Lisp>
(defun reverse-words (line)
(insert
(format "%s\n"
(mapconcat 'identity (reverse (split-string line)) " "))))
 
(defun reverse-lines (lines)
(mapcar 'reverse-words lines))
 
(reverse-lines
'("---------- 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 ----------------------- "))
</lang>
'''Output''':
<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|Gema}}==
678

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.