Reverse a string: Difference between revisions

m
→‎{{header|Oberon}}: Fixed language name
(→‎{{header|BASIC}}: Sort entries; add Commodore BASIC 3.5+ implementation)
m (→‎{{header|Oberon}}: Fixed language name)
 
(13 intermediate revisions by 9 users not shown)
Line 748:
 
<syntaxhighlight lang="befunge">55+~>:48>*#8\#4`#:!#<#~_$>:#,_@</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
This 9 byte program, featured on https://www.ioccc.org/2012/tromp/hint.html, reverses its input in byte-oriented BLC:
 
<pre>16 46 80 17 3e f0 b7 b0 40</pre>
 
=={{header|BQN}}==
Line 1,379 ⟶ 1,385:
 
=={{header|Elm}}==
<syntaxhighlight lang="elm">--module TheMain import on the next line provides the reverse stringexposing (main)
-- functionality satisfying the rosettacode.org task description.
import String exposing (reverse)
 
import Html exposing (Html, Attribute, text, div, inputp)
-- The rest is fairly boilerplate code demonstrating
import StringHtml.Attributes exposing (reversestyle)
-- interactively that the reverse function works.
import Html exposing (Html, Attribute, text, div, input)
import Html.Attributes exposing (placeholder, value, style)
import Html.Events exposing (on, targetValue)
import Html.App exposing (beginnerProgram)
 
main = beginnerProgram { model = "", view = view, update = update }
 
change myText =
update newStr oldStr = newStr
text ("reverse " ++ myText
++ " = " ++ String.reverse myText)
 
view : String -> Html String
view forward =
div []
([ input
[ placeholder "Enter a string to be reversed."
, value forward
, on "input" targetValue
, myStyle
]
[]
] ++
[ let backward = reverse forward
in div [ myStyle] [text backward]
])
 
main =
myStyle : Attribute msg
div [style "margin" "5%", style "font-size" "1.5em"]
myStyle =
[change "as⃝da"
style
, p [] ("width",[change "100%a⃝su-as⃝u")]
, ("height",p [] [change "20pxHello!")]
div [ ]
, ("padding", "5px 0 0 5px")
]</syntaxhighlight>
, ("font-size", "1em")
, ("text-align", "left")
]</syntaxhighlight>
 
Link to live demo: httphttps://dc25ellie-app.github.io/reverseStringElmcom/qdg6RP3DGCBa1
{{out}}
<pre>
reverse as⃝da = ad⃝sa
reverse a⃝su-as⃝u = u⃝sa-us⃝a
reverse Hello! = !olleH
</pre>
 
=={{header|Emacs Lisp}}==
Line 1,724 ⟶ 1,715:
<syntaxhighlight lang="clojure">
!dlrow olleH
</syntaxhighlight>
 
=={{header|Fennel}}==
Uses the same methods (and suffers from the same limitations) as [[#Lua|the Lua example]].
<syntaxhighlight lang="fennel">
(let [example :asdf]
(string.reverse example) ; fdsa
(example:reverse) ; fdsa
nil)
</syntaxhighlight>
 
Line 2,382:
 
=={{header|langur}}==
ThisThe accountsreverse() forfunction codewill points,reverse buta notstring foraccording to graphemes.
<syntaxhighlight lang="langur">writeln cp2s reverse s2cp q("don't you know)"</syntaxhighlight>
 
{{out}}
Line 3,026:
60 PRINT REVERSED$</syntaxhighlight>
 
=={{header|Oberon-2}}==
Tested with [https://miasap.se/obnc OBNC].
<syntaxhighlight lang="oberon">MODULE reverse;
Line 3,849:
<syntaxhighlight lang="red">>> reverse "asdf"
== "fdsa"</syntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Reverse 'asdf'>>;
};
 
Reverse {
(e.X) = e.X;
(e.X) s.C e.Y = <Reverse (s.C e.X) e.Y>;
e.X = <Reverse () e.X>;
};</syntaxhighlight>
{{out}}
<pre>fdsa</pre>
 
=={{header|ReScript}}==
Line 3,963 ⟶ 3,976:
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
→ str""
"" strOVER SIZE 1 '''FOR''' j str j DUP SUB + -1 '''STEP'''
OVER j DUP SUB +
≫ ≫ 'RVSTR' STO
-1 '''STEP''' SWAP DROP
≫ '<span style="color:blue">RVSTR</span>' STO
"ABC" <span style="color:blue">RVSTR</span>
{{out}}
<pre>1: "CBA"</pre>
Line 4,310 ⟶ 4,325:
. di ustrreverse(s)
νῆγ νὴτ ὶακ νὸναρὐο νὸτ ςὸεθ ὁ νεσηίοπἐ ῇχρἀ νἘ</syntaxhighlight>
 
=={{header|Stringle}}==
This inputs a string from the user and outputs its reverse. The <code>\</code> ''reverse'' operator reverses any string.
 
<syntaxhighlight lang="stringle">$ \$</syntaxhighlight>
 
=={{header|Swift}}==
Line 4,725 ⟶ 4,745:
{{libheader|Wren-str}}
{{libheader|Wren-upc}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
import "./upc" for Graphemes
 
for (word in ["asdf", "josé", "møøse", "was it a car or a cat I saw", "😀🚂🦊"]) {
3,026

edits