Interactive programming (repl): Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|Wren}}: Version change.)
 
(43 intermediate revisions by 21 users not shown)
Line 74: Line 74:
ACL2 !>(good-bye)
ACL2 !>(good-bye)
</pre>
</pre>

=={{header|Arturo}}==
=={{header|Arturo}}==
<pre>➜ $ arturo
In Arturo's REPL:
<lang arturo>$ :001> f: @(a b sep) -> a + 2*sep + b
= <function>
$ :002> f "Rosetta" "Code" ":"
= "Rosetta::Code"</lang>


Arturo
=={{header|AWK}}==
(c) 2019-2021 Yanis Zafirópulos
<lang AWK>

# syntax: GAWK -f CON GNU
# v/0.9.6.5 b/1097 @ 2021-02-09T16:40:43+01:00
# syntax: TAWK Thompson Automation
# arch: amd64/macosx
</lang>

<p>Command, program, output:</p>
# Type info 'symbol for info about a specific symbol or built-in function
<pre>
# Type help to get a list of all available functions with a short description
GAWK -f CON
# For multi-line input, just add a blank space at the end of a line
BEGIN {

x = f("Rosetta","Code",":")
# Launching interactive console - rock on! 🤘
print(x)

}
$> f: function [x y sep]-> x ++ (repeat sep 2) ++ y
function f(s1,s2,s3) { return(s1 s3 s3 s2) }

^Z <-- CTRL-Z
Rosetta::Code
$> f "Rosetta" "Code" ":"
=> Rosetta::Code
</pre>

<p>Command (followed by welcome banner), program, output:</p>
<pre>
$></pre>
TAWK
TAWK Version 5.0c (for Windows/NT)
Copyright 1996 Thompson Automation, Inc. All Rights Reserved.
Enter AWK Program followed by a blank line:
BEGIN {
x = f("Rosetta","Code",":")
print(x)
}
function f(s1,s2,s3) { return(s1 s3 s3 s2) }
<-- blank line
Enter program arguments, if any:
<-- blank line
Rosetta::Code
</pre>


=={{header|BASIC}}==
=={{header|BASIC}}==
Line 120: Line 101:


A Basic interpreter is in command mode by default. Enter the following in command mode:
A Basic interpreter is in command mode by default. Enter the following in command mode:
<lang qbasic>10 DEF FN f$(a$, b$, s$) = a$+s$+s$+b$
<syntaxhighlight lang="qbasic">10 DEF FN f$(a$, b$, s$) = a$+s$+s$+b$
PRINT FN f$("Rosetta", "Code", ":")</lang>
PRINT FN f$("Rosetta", "Code", ":")</syntaxhighlight>

==={{header|Applesoft BASIC}}===
The Apple II comes with BASIC in Read Only Memory (ROM.) When the Apple II plus and later models are powered on with no disk drives attached, the Applesoft BASIC prompt appears.
<pre>
]
</pre>
If a drive is attached, press RESET or Ctrl+RESET before the disk boots to get to the Applesoft BASIC prompt.

The original Apple II comes with Integer BASIC in ROM.
<pre>
>
</pre>
With an Applesoft ROM card, or a 16K RAM "Language" card in slot 0, you can boot from the DOS 3.3 System Master to load DOS and if needed it will load Applesoft into the Language card. Type the DOS 3.3 command FP "Floating Point" to get to the Applesoft BASIC prompt. There is also an older cassette tape version of Applesoft BASIC.

You can also get to Applesoft Basic from the Monitor.
<pre>
*
</pre>
Type E000G to cold start Applesoft which clears the program and variables. Or, type E003G to warm start Applesoft.

The two modes are RUN mode, and the default "DIRECT" mode. In direct mode, spaces are ignored except within strings. Entering ? is shorthand for the PRINT keyword. Using GET, INPUT, or DEF FN will result in an ?ILLEGAL DIRECT ERROR. The DATA statement is ignored.
<syntaxhighlight lang="gwbasic">] 0 IF F$ = "F" THEN RESULT$ = P1$ + P3$ + P3$ + P2$: END

] F$ = "F":P1$ = "ROSETTA":P2$ = "CODE":P3$ = ":": GOTO


] ?RESULT$
ROSETTA::CODE</syntaxhighlight>
=={{header|Batch File}}==
=={{header|Batch File}}==
CMD.EXE is the CLI for Batch Files. Batch Files do not have traditional functions and doing the [http://rosettacode.org/wiki/Call_a_function#Batch_File alternative] will not work in interactive mode. So this example uses blocks of code.
CMD.EXE is the CLI for Batch Files. Batch Files do not have traditional functions and doing the [http://rosettacode.org/wiki/Call_a_function#Batch_File alternative] will not work in interactive mode. So this example uses blocks of code.
{{trans|BBC BASIC}}
{{trans|BBC BASIC}}
<lang dos>>set r=Rosetta
<syntaxhighlight lang="dos">>set r=Rosetta


>set c=Code
>set c=Code
Line 135: Line 142:
Rosetta::Code
Rosetta::Code


></lang>
></syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
Line 193: Line 200:
'''&raquo;quit'''
'''&raquo;quit'''
$
$

=={{header|BQN}}==

All BQN implementations start in interactive mode, when called from the command line with no arguments (using Node.js for [[mlochbaum/BQN]]). It is recommended to use <code>rlwrap</code> with the executable for a better REPL experience.
<syntaxhighlight lang="bqn"> Join ← {a 𝕊 b‿c: b∾a∾a∾c}
(function block)
":" Join "Rosetta"‿"Code"
"Rosetta::Code"</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
Line 220: Line 235:


=={{header|Brat}}==
=={{header|Brat}}==
<lang brat>$ brat
<syntaxhighlight lang="brat">$ brat
# Interactive Brat
# Interactive Brat
brat:1> f = { a, b, s | a + s + s + b }
brat:1> f = { a, b, s | a + s + s + b }
Line 227: Line 242:
#=> Rosetta::Code
#=> Rosetta::Code
brat:3> quit
brat:3> quit
Exiting</lang>
Exiting</syntaxhighlight>


=={{header|Burlesque}}==
=={{header|Burlesque}}==


<lang burlesque>
<syntaxhighlight lang="burlesque">
C:\Burlesque>Burlesque.exe --shell
C:\Burlesque>Burlesque.exe --shell
blsq ) {+]?+}hd"Rosetta""Code"':!a
blsq ) {+]?+}hd"Rosetta""Code"':!a
"Rosetta:Code"
"Rosetta:Code"
blsq )
blsq )
</syntaxhighlight>
</lang>


=={{header|C sharp}}==
=={{header|C sharp}}==
Line 280: Line 295:
=={{header|Clojure}}==
=={{header|Clojure}}==
With ''clojure.jar'' on the Java classpath, the Clojure REPL is invoked with ''java clojure.main''.
With ''clojure.jar'' on the Java classpath, the Clojure REPL is invoked with ''java clojure.main''.
<lang lisp>
<syntaxhighlight lang="lisp">
Clojure 1.1.0
Clojure 1.1.0
user=> (defn f [s1 s2 sep] (str s1 sep sep s2))
user=> (defn f [s1 s2 sep] (str s1 sep sep s2))
Line 287: Line 302:
"Rosetta::Code"
"Rosetta::Code"
user=>
user=>
</syntaxhighlight>
</lang>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
With the [https://www.npmjs.com/package/coffee-script coffee-script] package for [https://www.npmjs.org/ NPM] on [http://nodejs.org/ Node.js]. The ''-n'' flag is '--node'.
With the [https://www.npmjs.com/package/coffee-script coffee-script] package for [https://www.npmjs.org/ NPM] on [http://nodejs.org/ Node.js]. The ''-n'' flag is '--node'.
<syntaxhighlight lang="coffeescript">
<lang CoffeeScript>
$ coffee -n
$ coffee -n
coffee> f = (a, b, c) -> a + c + c + b
coffee> f = (a, b, c) -> a + c + c + b
Line 297: Line 312:
coffee> f "Rosetta", "Code", ":"
coffee> f "Rosetta", "Code", ":"
"Rosetta::Code"
"Rosetta::Code"
</syntaxhighlight>
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==


The details of interactive use vary widely between implementations; this example is from [[SBCL]]. <code>*</code> is the prompt. By default, SBCL compiles (not interprets) all code, unless <code>[http://www.sbcl.org/manual/Interpreter.html sb-ext:*evaluator-mode*]</code> is changed.
The details of interactive use vary widely between implementations; this example is from [[SBCL]]. <code>*</code> is the prompt. By default, SBCL compiles (not interprets) all code, unless <code>[http://www.sbcl.org/manual/Interpreter.html sb-ext:*evaluator-mode*]</code> is changed.
<lang lisp>$ rlwrap sbcl
<syntaxhighlight lang="lisp">$ rlwrap sbcl
This is SBCL 1.0.25, an implementation of ANSI Common Lisp.
This is SBCL 1.0.25, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
More information about SBCL is available at <http://www.sbcl.org/>.
Line 313: Line 328:


"Rosetta::Code"
"Rosetta::Code"
*</lang>
*</syntaxhighlight>


=={{header|Déjà Vu}}==
=={{header|Déjà Vu}}==
Line 319: Line 334:
The interactive interpreter provides <code>.</code> as a shortcut for <code>!.</code> and <code>;</code> as a shortcut for <code>!(print-stack)</code>.
The interactive interpreter provides <code>.</code> as a shortcut for <code>!.</code> and <code>;</code> as a shortcut for <code>!(print-stack)</code>.


<lang dejavu>$ vu
<syntaxhighlight lang="dejavu">$ vu
<1:1> f str1 str2 sep:
<1:1> f str1 str2 sep:
<1:2> join sep [ str2 "" str1 ]
<1:2> join sep [ str2 "" str1 ]
<1:3>
<1:3>
<2:1> . f "Rosetta" "Code" ":"
<2:1> . f "Rosetta" "Code" ":"
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==


<lang e>$ rune # from an OS shell. On Windows there is also a desktop shortcut.</lang>
<syntaxhighlight lang="e">$ rune # from an OS shell. On Windows there is also a desktop shortcut.</syntaxhighlight>


"<code>?</code>" and "<code>&gt;</code>" are prompts for input; "<code>#</code>" marks output.
"<code>?</code>" and "<code>&gt;</code>" are prompts for input; "<code>#</code>" marks output.


<lang e>? def f(string1 :String, string2 :String, separator :String) {
<syntaxhighlight lang="e">? def f(string1 :String, string2 :String, separator :String) {
> return separator.rjoin(string1, "", string2)
> return separator.rjoin(string1, "", string2)
> }
> }
Line 338: Line 353:


? f("Rosetta", "Code", ":")
? f("Rosetta", "Code", ":")
# value: "Rosetta::Code"</lang>
# value: "Rosetta::Code"</syntaxhighlight>


If you type a definitely incomplete expression, such as "<code>def f() {</code>", then it gives an "<code>&gt;</code>" prompt and takes additional lines. If the expression is not necessarily incomplete, you can continue anyway by ending a line with "<code>\</code>".
If you type a definitely incomplete expression, such as "<code>def f() {</code>", then it gives an "<code>&gt;</code>" prompt and takes additional lines. If the expression is not necessarily incomplete, you can continue anyway by ending a line with "<code>\</code>".
Line 344: Line 359:
=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
EchoLisp runs in a browser window, and is -par essence - interactive. To start the REPL mode, type http://www.echolalie.org/echolisp in the browser URL address field.
EchoLisp runs in a browser window, and is -par essence - interactive. To start the REPL mode, type http://www.echolalie.org/echolisp in the browser URL address field.
<lang scheme>
<syntaxhighlight lang="scheme">
;; screen copy of the REPL
;; screen copy of the REPL
;; note that the &i variables remember expression evaluation, and may be used in other expressions
;; note that the &i variables remember expression evaluation, and may be used in other expressions
Line 364: Line 379:


;; etc.
;; etc.
</syntaxhighlight>
</lang>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA Script is a subset of the general language. ELT (Virtual machine terminal) can work in REPL mode
ELENA Script is a subset of the general language. ELT (Virtual machine terminal) can work in REPL mode
<lang elena>
<syntaxhighlight lang="elena">
c:\Alex\ELENA\bin>elt
c:\Alex\ELENA\bin>elt-cli
ELENA command line VM terminal 5.1.13 (C)2011-2020 by Alexei Rakov
ELENA command line VM terminal 6.0.7 (C)2021-23 by Aleksey Rakov
ELENA VM 5.1.17 (C)2005-2020 by Alex Rakov
ELENA VM 6.0.25 (C)2022-2023 by Aleksey Rakov
Initializing...
Initializing...
-q - quit
Done...
-c - clear
-h - help
-l <path> - execute a script from file
-p<script>; - prepend the prefix code
{ <script>; }*
<script> - execute script


>f(s1,s2,sep){^ s1 + sep + sep + s2 };
>-pf(s1,s2,sep){^ s1 + sep + sep + s2 }


>f("Rosetta","Code",":")
>f("Rosetta","Code",":")
Rosetta::Code
Rosetta::Code
>
>
</syntaxhighlight>
</lang>


=={{header|Elixir}}==
=={{header|Elixir}}==
Elixir's Interactive REPL is IEx, Interactive Elixir. To open IEx, open a shell and type: iex<br>
Elixir's Interactive REPL is IEx, Interactive Elixir. To open IEx, open a shell and type: iex<br>
The 'def' keyword isn't allowed outside of modules in Elixir, so the easiest way to write a function in iex is usually by writing an anonymous function.
The 'def' keyword isn't allowed outside of modules in Elixir, so the easiest way to write a function in iex is usually by writing an anonymous function.
<lang Elixir>iex(1)> f = fn str1,str2,sep -> [str1,"",str2] |> Enum.join(sep) end # Join list on separator
<syntaxhighlight lang="elixir">iex(1)> f = fn str1,str2,sep -> [str1,"",str2] |> Enum.join(sep) end # Join list on separator
iex(2)> g = fn str1,str2,sep -> str1 <> sep <> sep <> str2 end # Or concatenate strings
iex(2)> g = fn str1,str2,sep -> str1 <> sep <> sep <> str2 end # Or concatenate strings


Line 391: Line 412:
...(3)> def f(str1,str2,sep), do: [str1,"",str2] |> Enum.join(sep)
...(3)> def f(str1,str2,sep), do: [str1,"",str2] |> Enum.join(sep)
...(3)> def g(str1,str2,sep), do: str1 <> sep <> sep <> str2
...(3)> def g(str1,str2,sep), do: str1 <> sep <> sep <> str2
...(3)> end</lang>
...(3)> end</syntaxhighlight>


'''Example:'''
'''Example:'''
<lang Elixir>iex(4)> f.("Rosetta","Code",":")
<syntaxhighlight lang="elixir">iex(4)> f.("Rosetta","Code",":")
"Rosetta::Code"
"Rosetta::Code"
iex(5)> JoinStrings.f("Rosetta","Code",":")
iex(5)> JoinStrings.f("Rosetta","Code",":")
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
Line 404: Line 425:
Switch to the buffer (<code>C-x b *scratch*</code>, or use the Buffers menu), type some Lisp expressions, and press <code>C-j</code> after each expression.
Switch to the buffer (<code>C-x b *scratch*</code>, or use the Buffers menu), type some Lisp expressions, and press <code>C-j</code> after each expression.


<lang lisp>(defun my-join (str1 str2 sep)
<syntaxhighlight lang="lisp">(defun my-join (str1 str2 sep)
(concat str1 sep sep str2))
(concat str1 sep sep str2))
my-join
my-join
(my-join "Rosetta" "Code" ":")
(my-join "Rosetta" "Code" ":")
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


Emacs also provides ''ielm'', the interactive Emacs Lisp mode. Start it with <code>M-x ielm</code>, type some expressions and press <code>RET</code>.
Emacs also provides ''ielm'', the interactive Emacs Lisp mode. Start it with <code>M-x ielm</code>, type some expressions and press <code>RET</code>.


<lang lisp>*** Welcome to IELM *** Type (describe-mode) for help.
<syntaxhighlight lang="lisp">*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (defun my-join (str1 str2 sep)
ELISP> (defun my-join (str1 str2 sep)
(concat str1 sep sep str2))
(concat str1 sep sep str2))
Line 418: Line 439:
ELISP> (my-join "Rosetta" "Code" ":")
ELISP> (my-join "Rosetta" "Code" ":")
"Rosetta::Code"
"Rosetta::Code"
ELISP> </lang>
ELISP> </syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>$erl
<syntaxhighlight lang="erlang">$erl
1> F = fun(X,Y,Z) -> string:concat(string:concat(X,Z),string:concat(Z,Y)) end.
1> F = fun(X,Y,Z) -> string:concat(string:concat(X,Z),string:concat(Z,Y)) end.
#Fun<erl_eval.18.105910772>
#Fun<erl_eval.18.105910772>
2> F("Rosetta", "Code", ":").
2> F("Rosetta", "Code", ":").
"Rosetta::Code"
"Rosetta::Code"
</syntaxhighlight>
</lang>


=={{header|ERRE}}==
=={{header|ERRE}}==
Line 447: Line 468:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
The F# interpreter is called '''fsi'''. As F# accepts multi-line input it will not evaluate the input until you enter two semi-colons together.
The F# interpreter is called '''fsi'''. As F# accepts multi-line input it will not evaluate the input until you enter two semi-colons together.
<lang fsharp>Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
<syntaxhighlight lang="fsharp">Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727
F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727


Line 458: Line 479:


> f "Rosetta" "Code" ":" ;;
> f "Rosetta" "Code" ":" ;;
val it : string = "Rosetta::Code"</lang>
val it : string = "Rosetta::Code"</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
Factor comes with a graphical interpreter called the listener. The listener can also be run in a console with the following command:
Factor comes with a graphical interpreter called the listener. The listener can also be run in a console with the following command:
./factor -run=listener
./factor -run=listener
<lang factor>( scratchpad ) : cool-func ( w1 w2 sep -- res ) dup append glue ;
<syntaxhighlight lang="factor">( scratchpad ) : cool-func ( w1 w2 sep -- res ) dup append glue ;
( scratchpad ) "Rosetta" "Code" ":" cool-func .
( scratchpad ) "Rosetta" "Code" ":" cool-func .
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
Line 484: Line 505:


All Forth systems come with an interpreter. On embedded systems, the interpreter functions as a monitor or lightweight operating system.
All Forth systems come with an interpreter. On embedded systems, the interpreter functions as a monitor or lightweight operating system.
<lang forth>$ gforth
<syntaxhighlight lang="forth">$ gforth
Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Line 497: Line 518:
ok
ok
s" :" s" Code" s" Rosetta" f cr type
s" :" s" Code" s" Rosetta" f cr type
Rosetta::Code ok</lang>
Rosetta::Code ok</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
Line 507: Line 528:
For example, the current task can be coded as follows and compiles/runs instantly :
For example, the current task can be coded as follows and compiles/runs instantly :


<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


Dim As String s1, s2, sep
Dim As String s1, s2, sep
Line 514: Line 535:
Input "Separator "; sep
Input "Separator "; sep
Print : Print s1 + sep + sep + s2
Print : Print s1 + sep + sep + s2
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 528: Line 549:
Frink is distributed as a single <CODE>.jar</CODE> file that will run in a Java Virtual Machine. On many operating systems, just double-clicking this <CODE>.jar</CODE> file will run Frink with a graphical interface in an interactive mode. By specifying a different main-class (<CODE>frink.parser.Frink</CODE>) when starting Frink, it can be run in a text-mode interactive mode as well. These options and sample starter scripts for various operating systems are provided in the [https://frinklang.org/#RunningFrink Running Frink] section of the documentation.
Frink is distributed as a single <CODE>.jar</CODE> file that will run in a Java Virtual Machine. On many operating systems, just double-clicking this <CODE>.jar</CODE> file will run Frink with a graphical interface in an interactive mode. By specifying a different main-class (<CODE>frink.parser.Frink</CODE>) when starting Frink, it can be run in a text-mode interactive mode as well. These options and sample starter scripts for various operating systems are provided in the [https://frinklang.org/#RunningFrink Running Frink] section of the documentation.


<lang frink>$ java -cp frink.jar frink.parser.Frink
<syntaxhighlight lang="frink">$ java -cp frink.jar frink.parser.Frink


f[a,b,s] := "$a$s$s$b"
f[a,b,s] := "$a$s$s$b"
f["Rosetta", "Code", ":"]</lang>
f["Rosetta", "Code", ":"]</syntaxhighlight>


{{out}}
{{out}}
Line 537: Line 558:
Rosetta::Code
Rosetta::Code
</pre>
</pre>

=={{header|Fōrmulæ}}==

The interactive mode (REPL) is the primary working mode in Fōrmulæ.

To use it, open the web address [https://formulae.org/ formulae.org] in your browser. it is preferable to use this environment in a desktop web browser.

It is not necessary to install anything else.

A page with information is shown. You can start a new script using the [[File:Fōrmulæ - Interactive programming 05.png|border]] tool (new document).

[[File:Fōrmulæ - Interactive programming 04.png|border]]


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>~% gap
<syntaxhighlight lang="gap">~% gap
######### ###### ########### ###
######### ###### ########### ###
Line 577: Line 610:
gap> join("Rosetta", "Code", ":");
gap> join("Rosetta", "Code", ":");
"Rosetta::Code"
"Rosetta::Code"
gap></lang>
gap></syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 585: Line 618:


The complete program satisfying the task is,
The complete program satisfying the task is,
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 595: Line 628:
func main() {
func main() {
fmt.Println(f("Rosetta", "Code", ":"))
fmt.Println(f("Rosetta", "Code", ":"))
}</lang>
}</syntaxhighlight>


It works well to enter the program, check "every keystroke" to see syntax errors from whatever silly oversights you made, then fix them one by one until your desired output appears.
It works well to enter the program, check "every keystroke" to see syntax errors from whatever silly oversights you made, then fix them one by one until your desired output appears.
Line 604: Line 637:
=={{header|Groovy}}==
=={{header|Groovy}}==
The '''groovysh''' interpreter requires a command-line interpreter (terminal) environment in which to run. This example was run under the CMD command-line interpreter on Microsoft Windows XP.
The '''groovysh''' interpreter requires a command-line interpreter (terminal) environment in which to run. This example was run under the CMD command-line interpreter on Microsoft Windows XP.
<lang groovy>C:\Apps\groovy>groovysh
<syntaxhighlight lang="groovy">C:\Apps\groovy>groovysh
Groovy Shell (1.6.2, JVM: 1.6.0_13)
Groovy Shell (1.6.2, JVM: 1.6.0_13)
Type 'help' or '\h' for help.
Type 'help' or '\h' for help.
Line 615: Line 648:
groovy:000> exit
groovy:000> exit


C:\Apps\groovy></lang>
C:\Apps\groovy></syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 621: Line 654:
The details of interactive use vary widely between implementations. This example is from [[GHC|GHCi]].
The details of interactive use vary widely between implementations. This example is from [[GHC|GHCi]].


<lang haskell>$ ghci
<syntaxhighlight lang="haskell">$ ghci
___ ___ _
___ ___ _
/ _ \ /\ /\/ __(_)
/ _ \ /\ /\/ __(_)
Line 631: Line 664:
Prelude> let f as bs sep = as ++ sep ++ sep ++ bs
Prelude> let f as bs sep = as ++ sep ++ sep ++ bs
Prelude> f "Rosetta" "Code" ":"
Prelude> f "Rosetta" "Code" ":"
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
Line 637: Line 670:
"c:\Program Files\HicEst\HicEst.exe E:\Rosetta\Interactive_programming.hic f('Rosetta', 'Code', ':')"
"c:\Program Files\HicEst\HicEst.exe E:\Rosetta\Interactive_programming.hic f('Rosetta', 'Code', ':')"
<br>Type the following script. Each line is executed (and incrementally compiled) when it is typed:
<br>Type the following script. Each line is executed (and incrementally compiled) when it is typed:
<lang HicEst>CHARACTER A*40, B*40, C*40
<syntaxhighlight lang="hicest">CHARACTER A*40, B*40, C*40


READ(Text=$CMD_LINE, Format="'','','',") A, B, C
READ(Text=$CMD_LINE, Format="'','','',") A, B, C
WRITE(ClipBoard, Name) A, B, C ! A=Rosetta; B=Code; C=:;
WRITE(ClipBoard, Name) A, B, C ! A=Rosetta; B=Code; C=:;


WRITE(ClipBoard) TRIM(A) // ':' // TRIM(C) // TRIM(B) ! Rosetta::Code</lang>
WRITE(ClipBoard) TRIM(A) // ':' // TRIM(C) // TRIM(B) ! Rosetta::Code</syntaxhighlight>


=={{header|Huginn}}==
=={{Header|Insitux}}==

[[File:huginn_interactive.gif]]
First is the system shell, when Insitux has been already been installed system-wide (<code>npm i -g insitux</code>).

<pre>
$ npx ix
Insitux 230728 REPL
❯ (function f s1 s2 sep (str s1 sep sep s2))
❯ (f "Rosetta" "Code" ":")
Rosetta::Code
</pre>


=={{header|Io}}==
=={{header|Io}}==
Line 669: Line 712:


This is a session log once the os specific stuff has been handled:
This is a session log once the os specific stuff has been handled:
<lang j> f=: [: ; 0 2 2 1&{
<syntaxhighlight lang="j"> f=: [: ; 0 2 2 1&{
f 'Rosetta';'Code';':'
f 'Rosetta';'Code';':'
Rosetta::Code</lang>
Rosetta::Code</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==


<lang java>
<syntaxhighlight lang="java">
public static void main(String[] args) {
public static void main(String[] args) {
System.out.println(concat("Rosetta", "Code", ":"));
System.out.println(concat("Rosetta", "Code", ":"));
Line 685: Line 728:


Rosetta::Code
Rosetta::Code
</syntaxhighlight>
</lang>
Alternatively
<syntaxhighlight lang="java">
Java has an interactive REPL (Read-Evaluate-Print-Loop) console, jshell, that is included with the JDK.
The REPL is started by invoking: $JAVA_HOME/bin/jshell
Here is a sample session to accomplish the task.
| Welcome to JShell -- Version 20
| For an introduction type: /help

jshell> String concat(String a, String b, String c) { return a + c + c + b; }
| created method concat(String, String, String)
jshell> concat("Rosetta", "Code", ":")
$2 ==> "Rosetta::Code"
jshell>
</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|Rhino}}
{{works with|Rhino}}
<lang javascript>$ java -cp js.jar org.mozilla.javascript.tools.shell.Main
<syntaxhighlight lang="javascript">$ java -cp js.jar org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 2 2009 03 22
Rhino 1.7 release 2 2009 03 22
js> function f(a,b,s) {return a + s + s + b;}
js> function f(a,b,s) {return a + s + s + b;}
Line 695: Line 755:
Rosetta::Code
Rosetta::Code
js> quit()
js> quit()
$</lang>
$</syntaxhighlight>


=={{header|Jsish}}==
=={{header|Jsish}}==
Line 734: Line 794:
=={{header|K}}==
=={{header|K}}==
{{works with|Kona}}
{{works with|Kona}}
<lang k>$ rlwrap k
<syntaxhighlight lang="k">$ rlwrap k
K Console - Enter \ for help
K Console - Enter \ for help
f:{x,z,z,y}
f:{x,z,z,y}
f["Rosetta";"Code";":"]
f["Rosetta";"Code";":"]
"Rosetta::Code"</lang>
"Rosetta::Code"</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Kotlin has an interactive shell for the JVM which can be started by simply typing 'kotlinc' at the command line. Here's a sample interactive session to accomplish the specified task on Windows 10:
Kotlin has an interactive shell for the JVM which can be started by simply typing 'kotlinc' at the command line. Here's a sample interactive session to accomplish the specified task on Windows 10:
<lang scala>c:\kotlin-compiler-1.0.6>kotlinc
<syntaxhighlight lang="scala">c:\kotlin-compiler-1.0.6>kotlinc
Welcome to Kotlin version 1.0.6-release-127 (JRE 1.8.0_31-b13)
Welcome to Kotlin version 1.0.6-release-127 (JRE 1.8.0_31-b13)
Type :help for help, :quit for quit
Type :help for help, :quit for quit
Line 748: Line 808:
>>> f("Rosetta", "Code", ":")
>>> f("Rosetta", "Code", ":")
Rosetta::Code
Rosetta::Code
>>> :quit</lang>
>>> :quit</syntaxhighlight>

=={{header|Lambdatalk}}==
Lambdatalk works in a small wiki, lambdatank. Evaluation is done in real time.
<syntaxhighlight lang="scheme">
{def F {lambda {:a :b :s} :a:s:s:b}}
-> F

{F Rosetta Code :}
-> Rosetta::Code
</syntaxhighlight>

=={{header|Lang}}==
This example works with the LangShell from the Standard Lang implementation.
The LangShell can be started with (The LangShell does not run in the OS's shell, it will open a separate window):
<syntaxhighlight lang="shell">
$ lang -startShell
</syntaxhighlight>
<syntaxhighlight lang="lang">
Lang-Shell - Press CTRL + C for cancelling execution or for exiting!
• Copy with (CTRL + SHIFT + C) and paste with (CTRL + SHIT + V)
• Press CTRL + S for saving all inputs to a .lang file (Save)
• Press CTRL + SHIFT + S for saving all inputs to a .lang file (Save As...)
• Press CTRL + I for opening the special char input window
• Press CTRL + SHIFT + F for opening a file chooser to insert file paths
• Press UP and DOWN for scrolling through the history
• Press TAB and SHIFT + TAB for scrolling trough auto complete texts
◦ Press ENTER for accepting the auto complete text
• Press CTRL + L to clear the screen
• Use func.printHelp() to get information about LangShell functions
> fp.f = ($a, $b, $s) -> return $a$s$s$b
==> <Normal FP>
> fp.f(Rosetta, Code, :)
==> Rosetta::Code
>
</syntaxhighlight>
Example with auto print mode set to NONE:
<syntaxhighlight lang="lang">
Lang-Shell - Press CTRL + C for cancelling execution or for exiting!
• Copy with (CTRL + SHIFT + C) and paste with (CTRL + SHIT + V)
• Press CTRL + S for saving all inputs to a .lang file (Save)
• Press CTRL + SHIFT + S for saving all inputs to a .lang file (Save As...)
• Press CTRL + I for opening the special char input window
• Press CTRL + SHIFT + F for opening a file chooser to insert file paths
• Press UP and DOWN for scrolling through the history
• Press TAB and SHIFT + TAB for scrolling trough auto complete texts
◦ Press ENTER for accepting the auto complete text
• Press CTRL + L to clear the screen
• Use func.printHelp() to get information about LangShell functions
> fn.setAutoPrintMode(NONE)
> fp.f = ($a, $b, $s) -> return $a$s$s$b
> fn.println(fp.f(Rosetta, Code, :))
Rosetta::Code
>
</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>#!/usr/bin/lasso9
<syntaxhighlight lang="lasso">#!/usr/bin/lasso9


// filename: interactive_demo
// filename: interactive_demo
Line 793: Line 907:


// deliver the result
// deliver the result
stdoutnl(concatenate_with_delimiter(#string1, #string2, #delimiter))</lang>
stdoutnl(concatenate_with_delimiter(#string1, #string2, #delimiter))</syntaxhighlight>


Called from the command line: ./interactive_demo
Called from the command line: ./interactive_demo


Result -> Rosetta::Code
Result -> Rosetta::Code

=={{header|Lambdatalk}}==
Lambdatalk works in a small wiki, lambdatank. Evaluation is done in real time.
<lang scheme>
{def F {lambda {:a :b :s} :a:s:s:b}}
-> F

{F Rosetta Code :}
-> Rosetta::Code
</lang>


=={{header|Lingo}}==
=={{header|Lingo}}==
Lingo/Director is usually started as GUI program and has no access to the standard system console (unless using a binary plugin). But it has its own interactive Lingo console called "Message Window", that can be activated/displayed by executing "_player.debugPlaybackEnabled=1". Using this Message Window, the task can be solved like this:
Lingo/Director is usually started as GUI program and has no access to the standard system console (unless using a binary plugin). But it has its own interactive Lingo console called "Message Window", that can be activated/displayed by executing "_player.debugPlaybackEnabled=1". Using this Message Window, the task can be solved like this:
<lang lingo>> m=new(#script)
<syntaxhighlight lang="lingo">> m=new(#script)
> m.scripttext="on conc(a,b,c)"&RETURN&"return a&c&c&b"&RETURN&"end"
> m.scripttext="on conc(a,b,c)"&RETURN&"return a&c&c&b"&RETURN&"end"
> put conc("Rosetta", "Code", ":")
> put conc("Rosetta", "Code", ":")
-- "Rosetta::Code"</lang>
-- "Rosetta::Code"</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
{{works with|UCB Logo}}
{{works with|UCB Logo}}
<lang logo>$ <i>logo</i>
<syntaxhighlight lang="logo">$ <i>logo</i>
Welcome to Berkeley Logo version 5.6
Welcome to Berkeley Logo version 5.6
? <i>to f :prefix :suffix :separator</i>
? <i>to f :prefix :suffix :separator</i>
Line 826: Line 930:
? <i>show f "Rosetta "Code ":</i>
? <i>show f "Rosetta "Code ":</i>
Rosetta::Code
Rosetta::Code
?</lang>
?</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>$ lua
<syntaxhighlight lang="lua">$ lua
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
> function conc(a, b, c)
> function conc(a, b, c)
Line 836: Line 940:
> print(conc("Rosetta", "Code", ":"))
> print(conc("Rosetta", "Code", ":"))
Rosetta::Code
Rosetta::Code
></lang>
></syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 852: Line 956:
</pre >
</pre >
(we see Function F$() at the header of editor)
(we see Function F$() at the header of editor)
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Read name1$, name2$, sep$
Read name1$, name2$, sep$
=name1$+sep$+sep$+name2$
=name1$+sep$+sep$+name2$
</syntaxhighlight>
</lang>
So now we press Esc and return to command line (editor open as a layer, so console has the last state). Using Clipboard we sen unicode string to clipboard
So now we press Esc and return to command line (editor open as a layer, so console has the last state). Using Clipboard we sen unicode string to clipboard
<pre >
<pre >
Line 881: Line 985:
=={{header|M4}}==
=={{header|M4}}==
Here is a terminal session with output lines marked by "==>":
Here is a terminal session with output lines marked by "==>":
<lang M4>$ m4
<syntaxhighlight lang="m4">$ m4
define(`f',`$1`'$3`'$3`'$2')
define(`f',`$1`'$3`'$3`'$2')
==>
==>
f(`Rosetta',`Code',`:')
f(`Rosetta',`Code',`:')
==>Rosetta::Code
==>Rosetta::Code
m4exit</lang>
m4exit</syntaxhighlight>


=={{header|Maple}}==
=={{header|Maple}}==
Line 892: Line 996:
<pre>$ maple</pre>
<pre>$ maple</pre>
Then enter the Maple commands.
Then enter the Maple commands.
<lang Maple>f := (a,b,c)->cat(a,c,c,b):
<syntaxhighlight lang="maple">f := (a,b,c)->cat(a,c,c,b):


f("Rosetta","Code",":");</lang>
f("Rosetta","Code",":");</syntaxhighlight>
Output:
Output:
<pre> "Rosetta::Code"</pre>
<pre> "Rosetta::Code"</pre>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>$ math</lang>
<syntaxhighlight lang="mathematica">$ math</syntaxhighlight>
<lang Mathematica>f[x_,y_,z_]:=Print[x,z,z,y]
<syntaxhighlight lang="mathematica">f[x_,y_,z_]:=Print[x,z,z,y]
->""
->""
f["Rosetta","Code",":"]
f["Rosetta","Code",":"]
->Rosetta::Code</lang>
->Rosetta::Code</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Line 909: Line 1,013:


Define an anonymous function in the Command Window
Define an anonymous function in the Command Window
<syntaxhighlight lang="matlab">
<lang Matlab>
>> f = @(str1, str2, delim) [str1, delim, delim, str2];
>> f = @(str1, str2, delim) [str1, delim, delim, str2];
</syntaxhighlight>
</lang>


Call of function and {{out}}
Call of function and {{out}}
Line 926: Line 1,030:
Simply run wxMaxima, xMaxima (or simply maxima in a Linux or Windows command line) to start a REPL.
Simply run wxMaxima, xMaxima (or simply maxima in a Linux or Windows command line) to start a REPL.


<lang maxima>(%i1) f(a, b, c) := sconcat(a, c, c, b)$
<syntaxhighlight lang="maxima">(%i1) f(a, b, c) := sconcat(a, c, c, b)$
(%i2) f("Rosetta", "Code", ":");
(%i2) f("Rosetta", "Code", ":");
(%o2) "Rosetta::Code"</lang>
(%o2) "Rosetta::Code"</syntaxhighlight>

=={{header|min}}==
Run the REPL with <code>min -i</code>, otherwise it'll expect a file to run as a script.
{{works with|min|0.27.1}}
<syntaxhighlight lang="min">$ (dup suffix swap suffix suffix) :glue
$ "Rosetta" "Code" ":" glue puts!
Rosetta::Code
$</syntaxhighlight>


=={{header|ML/I}}==
=={{header|ML/I}}==
Line 934: Line 1,046:
Start ML/I with (e.g.: $ ml1), then type:
Start ML/I with (e.g.: $ ml1), then type:


<lang ML/I>MCSKIP MT,<>
<syntaxhighlight lang="ml/i">MCSKIP MT,<>
MCINS %.
MCINS %.
MCDEF F WITHS (,,)
MCDEF F WITHS (,,)
AS <%WA1.%WA3.%WA2.%WA2.></lang>
AS <%WA1.%WA3.%WA2.%WA2.></syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
Line 949: Line 1,061:


=={{header|Nim}}==
=={{header|Nim}}==
Nim is not provided with a REPL but there is several available. Online, it is possible to use Nim playground at https://play.nim-lang.org/. And one can install “inim” with “nimble” (command <code>nimble install inim</code>).
Use <code>nimble</code> (Nim's package manager) to install a REPL ('''nrpl''' or '''tnim''')


Run the REPL and paste the following code
Run the REPL and paste the following code:


<syntaxhighlight lang="nim">proc f(x, y, z: string) = echo x, z, z, y
<pre>
f("Rosetta", "Code", ":")</syntaxhighlight>
proc f(x, y, z: string) = echo x & z & z & y
f("Rosetta", "Code", ":")
</pre>


which outputs
which outputs:


<pre>Rosetta::Code</pre>
<pre>Rosetta::Code</pre>


{{works with|Nim|0.20.0 or above}}
To get working arrow keys, compile nim with readline, like this: <code>./koch boot -d:release -d:useGnuReadline</code> or just run <code>rlwrap nim i</code> instead.
Since version 0.20.0 Nim also provides a REPL in its compiler API.

'''File: repl.nim'''
<syntaxhighlight lang="nim">import ../compiler/[nimeval, llstream]

runRepl(llStreamOpenStdIn().repl, [findNimStdLibCompileTime()], true)</syntaxhighlight>
'''Usage'''
<pre>nim c repl.nim
repl
.....>>> var a = 1
>>> var b = 2
>>> a + b

3</pre>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 968: Line 1,092:
The default interactive interpreter is called the toplevel. In the toplevel because we can enter expressions that span multiple lines, we have to type the double semicolon (";;") at the end of an expression so that it knows we are done.
The default interactive interpreter is called the toplevel. In the toplevel because we can enter expressions that span multiple lines, we have to type the double semicolon (";;") at the end of an expression so that it knows we are done.


<lang ocaml>$ ocaml
<syntaxhighlight lang="ocaml">$ ocaml
Objective Caml version 3.12.1
Objective Caml version 3.12.1


Line 975: Line 1,099:
# f "Rosetta" "Code" ":";;
# f "Rosetta" "Code" ":";;
- : string = "Rosetta::Code"
- : string = "Rosetta::Code"
#</lang>
#</syntaxhighlight>


Also a lot of OCaml users invoke the toplevel with rlwrap or ledit to gain readline capabilities:
Also a lot of OCaml users invoke the toplevel with rlwrap or ledit to gain readline capabilities:


<lang ocaml>$ rlwrap ocaml</lang>
<syntaxhighlight lang="ocaml">$ rlwrap ocaml</syntaxhighlight>


There is also [http://benediktmeurer.de/ocamlnat/ ocamlnat] that is a native toplevel. It permits interactive use of the OCaml system through a read-eval-print loop, similar to the standard OCaml toplevel, but up to 100 times faster.<BR>
There is also [http://benediktmeurer.de/ocamlnat/ ocamlnat] that is a native toplevel. It permits interactive use of the OCaml system through a read-eval-print loop, similar to the standard OCaml toplevel, but up to 100 times faster.<BR>
Line 985: Line 1,109:


=={{header|Octave}}==
=={{header|Octave}}==
<lang octave>$ octave
<syntaxhighlight lang="octave">$ octave
GNU Octave, version 3.0.2
GNU Octave, version 3.0.2
Copyright (C) 2008 John W. Eaton and others.
Copyright (C) 2008 John W. Eaton and others.
Line 1,009: Line 1,133:
octave:2> concat("Rosetta","Code",":");
octave:2> concat("Rosetta","Code",":");
Rosetta::Code
Rosetta::Code
octave:3></lang>
octave:3></syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==
Line 1,015: Line 1,139:
Oforth interpreter is started using --i command line parameter :
Oforth interpreter is started using --i command line parameter :


<lang Oforth>oforth --i</lang>
<syntaxhighlight lang="oforth">oforth --i</syntaxhighlight>


Into the interpreter, you can create functions :
Into the interpreter, you can create functions :


<lang Oforth>: x(a, b, sep) a sep + sep + b + ;
<syntaxhighlight lang="oforth">: x(a, b, sep) a sep + sep + b + ;
ok
ok
>x("Rosetta", "Code", ":")
>x("Rosetta", "Code", ":")
Line 1,026: Line 1,150:
[1] (String) Rosetta::Code
[1] (String) Rosetta::Code
ok
ok
></lang>
></syntaxhighlight>


Alternatively you don't need the local variables
Alternatively you don't need the local variables


<lang Oforth> > : x dup rot + + + ;
<syntaxhighlight lang="oforth"> > : x dup rot + + + ;
ok
ok
> "Rosetta" "Code" ";" x .s
> "Rosetta" "Code" ";" x .s
[1] (String) Rosetta::Code
[1] (String) Rosetta::Code
ok
ok
> </lang>
> </syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
Ol comes with builtin REPL. Interactive web-based example can be found at the Ol [https://yuriy-chumak.github.io/ol project page].
Ol comes with builtin REPL. Interactive web-based example can be found at the Ol [https://yuriy-chumak.github.io/ol project page].


<lang scheme>
<syntaxhighlight lang="scheme">
$ ol
$ ol
Welcome to Otus Lisp 2.1-2282-27a9b6c
Welcome to Otus Lisp 2.1-2282-27a9b6c
type ',help' to help, ',quit' to end session.
type ',help' to help, ',quit' to end session.
> (define (f head tail mid)
> (define (f head tail mid)
(fold string-append "" (list head mid mid tail)))
(string-append head mid mid tail))
;; Defined f
;; Defined f
> (f "Rosetta" "Code" ":")
> (f "Rosetta" "Code" ":")
Line 1,051: Line 1,175:
> ,quit
> ,quit
bye-bye :/
bye-bye :/
</syntaxhighlight>
</lang>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
Line 1,114: Line 1,238:
Mozart supports this style of programming with its Emacs interface.
Mozart supports this style of programming with its Emacs interface.
Go to the "Oz" buffer and enter
Go to the "Oz" buffer and enter
<lang oz>declare fun {F As Bs Sep} {Append As Sep|Sep|Bs} end</lang>
<syntaxhighlight lang="oz">declare fun {F As Bs Sep} {Append As Sep|Sep|Bs} end</syntaxhighlight>
Press C-. C-l to evaluate the line.
Press C-. C-l to evaluate the line.


Now enter
Now enter
<lang oz>{System.showInfo {F "Rosetta" "Code" &:}}</lang>
<syntaxhighlight lang="oz">{System.showInfo {F "Rosetta" "Code" &:}}</syntaxhighlight>
and again press C-. C-l to execute the code.
and again press C-. C-l to execute the code.
You will see the result in the "*Oz Emulator*" buffer.
You will see the result in the "*Oz Emulator*" buffer.
Line 1,125: Line 1,249:
gp *is* a REPL built on the PARI library. You can start it from the command line with <code>gp</code>, though you may wish to change to your Pari directory first so it can read your <code>.gprc</code> file. Alternatively, if you are using a GUI, double-click the shortcut.
gp *is* a REPL built on the PARI library. You can start it from the command line with <code>gp</code>, though you may wish to change to your Pari directory first so it can read your <code>.gprc</code> file. Alternatively, if you are using a GUI, double-click the shortcut.


<lang parigp>f(s1,s2,sep)=Str(s1, sep, sep, s2);</lang>
<syntaxhighlight lang="parigp">f(s1,s2,sep)=Str(s1, sep, sep, s2);</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Perl doesn't have an interpreter, but there is an interactive debugger:
Perl doesn't have an interpreter, but there is an interactive debugger:
<lang perl>$ perl -de1
<syntaxhighlight lang="perl">$ perl -de1


Loading DB routines from perl5db.pl version 1.3
Loading DB routines from perl5db.pl version 1.3
Line 1,141: Line 1,265:
DB<2> p f('Rosetta', 'Code', ':')
DB<2> p f('Rosetta', 'Code', ':')
Rosetta::Code
Rosetta::Code
DB<3> q</lang>
DB<3> q</syntaxhighlight>


Alternative way:
Alternative way:


<lang perl>$ perl
<syntaxhighlight lang="perl">$ perl
# Write the script here and press Ctrl+D plus ENTER when finished (^D means Ctrl+D):
# Write the script here and press Ctrl+D plus ENTER when finished (^D means Ctrl+D):
sub f {my ($s1, $s2, $sep) = @_; $s1 . $sep . $sep . $s2};
sub f {my ($s1, $s2, $sep) = @_; $s1 . $sep . $sep . $s2};
Line 1,151: Line 1,275:
^D
^D
Rosetta::Code
Rosetta::Code
$</lang>
$</syntaxhighlight>


Another:
Another:


<lang perl>$ perl -lpe '$_=eval||$@'
<syntaxhighlight lang="perl">$ perl -lpe '$_=eval||$@'
sub f { join '' => @_[0, 2, 2, 1] }
sub f { join '' => @_[0, 2, 2, 1] }


f qw/Rosetta Code :/
f qw/Rosetta Code :/
Rosetta::Code</lang>
Rosetta::Code</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
The repl has been significantly improved for version 0.8.4+ so it is now usable, although not thoroughly tested or widely used yet.
{{todo|Phix|Loads of stuff!}}
There is a barely adequate repl: Phix compiles/optimises things (even when "interpreting"), such as omitting
unused routines/code and unnecessary tests (usually via type inference), and generally assumes it can mangle
the symtab as part of generating executable machine code. It does not, therefore, fare very well (as yet) if
and when it is asked to compile "a few more lines" of code. Theoretically, however, it is just a relatively
simple matter of figuring out precisely what to save/restore and at exactly which points, and avoiding some
of the optimisations (/type inferences) when in repl mode.

<pre>
<pre>
C:\Program Files (x86)\Phix>p -repl
C:\Program Files (x86)\Phix>p -repl
Line 1,175: Line 1,292:
Enter a statement such as "?remainder(floor(250/8),8)" or "puts(1,"Hi")"
Enter a statement such as "?remainder(floor(250/8),8)" or "puts(1,"Hi")"


>function f(string a,b,c) return a&c&c&b end function ?f("Rosetta","Code",":")
>function f(string a,b,c) return a&c&c&b end function
"Rosetta::Code"
Warning: the repl is brand new, experimental, incomplete, and liable to crash!
Enter a statement such as "?remainder(floor(250/8),8)" or "puts(1,"Hi")"


>?f("Rosetta","Code",":")
>?f("Rosetta","Code",":")
"Rosetta::Code"


>quit
?f("Rosetta","Code",":")
C:\Program Files (x86)\Phix>
^ undefined identifier f

Press Enter, or d for diagnostics...
</pre>
</pre>

As you can see, it all-too-quickly "forgots" f, or rather does not save/restore the right things.<br>
=={{header|Picat}}==
Each time I come back to this, I usually make significant (but still small) headway, before getting stuck(/bored) yet again.
<code>cl</code> enters the interactive console mode. Exit with <code>Ctrl-d</code> on Unix and <code>Ctrl-z</code> on Windows.
<pre>Picat> cl
f(X,Y,Sep) = X ++ [Sep,Sep] ++ Y.
<Ctrl-D>
Picat> print(f("Rosetta","Code",':'))
Rosetta::Code
yes</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang bash>$ pil +</lang>
<syntaxhighlight lang="bash">$ pil +</syntaxhighlight>
<lang PicoLisp>: (de f (Str1 Str2 Sep)
<syntaxhighlight lang="picolisp">: (de f (Str1 Str2 Sep)
(pack Str1 Sep Sep Str2) )
(pack Str1 Sep Sep Str2) )
-> f
-> f


: (f "Rosetta" "Code" ":")
: (f "Rosetta" "Code" ":")
-> "Rosetta::Code"</lang>
-> "Rosetta::Code"</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>$ pike
<syntaxhighlight lang="pike">$ pike
Pike v7.8 release 352 running Hilfe v3.5 (Incremental Pike Frontend)
Pike v7.8 release 352 running Hilfe v3.5 (Incremental Pike Frontend)
> string f(string first, string second, string sep){
> string f(string first, string second, string sep){
Line 1,207: Line 1,327:
> f("Rosetta","Code",":");
> f("Rosetta","Code",":");
(1) Result: "Rosetta::Code"
(1) Result: "Rosetta::Code"
></lang>
></syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
PowerShell itself is already a shell and therefore an interactive environment is the default.
PowerShell itself is already a shell and therefore an interactive environment is the default.
<lang powershell>Windows PowerShell
<syntaxhighlight lang="powershell">Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
Copyright (C) 2009 Microsoft Corporation. All rights reserved.


Line 1,220: Line 1,340:
PS Home:\> f 'Rosetta' 'Code' ':'
PS Home:\> f 'Rosetta' 'Code' ':'
Rosetta::Code
Rosetta::Code
PS Home:\></lang>
PS Home:\></syntaxhighlight>


=={{header|Prolog}}==
=={{header|Prolog}}==
Line 1,226: Line 1,346:
Prolog works in its own environnment.<BR>
Prolog works in its own environnment.<BR>
Start the interpreter by typing pl at the command line (or by clicking on the exe).
Start the interpreter by typing pl at the command line (or by clicking on the exe).
<lang Prolog>% library(win_menu) compiled into win_menu 0.00 sec, 12,872 bytes
<syntaxhighlight lang="prolog">% library(win_menu) compiled into win_menu 0.00 sec, 12,872 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,404 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,404 bytes
% The graphical front-end will be used for subsequent tracing
% The graphical front-end will be used for subsequent tracing
Line 1,247: Line 1,367:


3 ?-
3 ?-
</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
Start the interpreter by typing python at the command line (or select it from a menu). You get a response showing the version of the interpreter being run before giving an input prompt of three greater-than characters and a space:
Start the interpreter by typing python at the command line (or select it from a menu). You get a response showing the version of the interpreter being run before giving an input prompt of three greater-than characters and a space:


<lang python>python
<syntaxhighlight lang="python">python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
win32
Line 1,261: Line 1,381:
>>> f('Rosetta', 'Code', ':')
>>> f('Rosetta', 'Code', ':')
'Rosetta::Code'
'Rosetta::Code'
>>></lang>
>>></syntaxhighlight>

=={{header|Quackery}}==

The Quackery shell (REPL) can be invoked from the command line by invoking <code>quackery</code> without specifying a Quackery source file. The shell can be invoked from within a Quackery source file with the Quackery word <code>shell</code>. As the shell is nestable it can also be invoked from within the shell.

{{out}}
Invoking the shell first from the command line and then within the shell, and leaving first the nested shell then the outer shell.

<pre> > quackery

Welcome to Quackery.

Enter "leave" to leave the shell.

/O> say " now entering a nested shell..."
... shell
...
now entering a nested shell...
/O> say " now leaving the nested shell"
... leave
...
now leaving the nested shell
Auf wiedersehen.


Stack empty.

/O> say " now leaving the shell invoked at the command line"
... leave
...
now leaving the shell invoked at the command line
Goodbye.


> echo " back at the command line"
back at the command line
></pre>

The task:

<syntaxhighlight lang="quackery">$ quackery

Welcome to Quackery.

Enter "leave" to leave the shell.

/O> [ dup join swap join join ] is f ( [ [ [ --> [ )
...

Stack empty.

/O> $ 'Rosetta' $ 'Code' $ ':' f
...

Stack: [ 82 111 115 101 116 116 97 58 58 67 111 100 101 ]

/O> echo$
...
Rosetta::Code
Stack empty.

/O></syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang r>$ R
<syntaxhighlight lang="r">$ R


R version 2.7.2 (2008-08-25)
R version 2.7.2 (2008-08-25)
Line 1,288: Line 1,470:
[1] "Rosetta::Code"
[1] "Rosetta::Code"
> q()
> q()
Save workspace image? [y/n/c]: n</lang>
Save workspace image? [y/n/c]: n</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,294: Line 1,476:
Much like Scheme, Racket features a full-featured REPL:
Much like Scheme, Racket features a full-featured REPL:


<lang Racket>oiseau:/tmp> racket
<syntaxhighlight lang="racket">oiseau:/tmp> racket
Welcome to Racket v5.3.3.5.
Welcome to Racket v5.3.3.5.
> (define (f string-1 string-2 separator)
> (define (f string-1 string-2 separator)
Line 1,301: Line 1,483:
"Rosetta::Code"
"Rosetta::Code"
> ^D
> ^D
oiseau:/tmp></lang>
oiseau:/tmp></syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
Using [[Rakudo]].
Using [[Rakudo]].
<lang perl6>$ rakudo/perl6
<syntaxhighlight lang="raku" line>$ rakudo/perl6
> sub f($str1,$str2,$sep) { $str1~$sep x 2~$str2 };
> sub f($str1,$str2,$sep) { $str1~$sep x 2~$str2 };
f
f
Line 1,312: Line 1,494:
Rosetta::Code
Rosetta::Code
>
>
</syntaxhighlight>
</lang>


=={{header|REBOL}}==
=={{header|REBOL}}==
Start the REBOL/Core interpreter in quiet mode with -q. q to quit.
Start the REBOL/Core interpreter in quiet mode with -q. q to quit.


<lang rebol>$ rebol -q
<syntaxhighlight lang="rebol">$ rebol -q
>> f: func [a b s] [print rejoin [a s s b]]
>> f: func [a b s] [print rejoin [a s s b]]
>> f "Rosetta" "Code" ":"
>> f "Rosetta" "Code" ":"
Rosetta::Code
Rosetta::Code
>> q</lang>
>> q</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
Retro's interpreter is started automatically. Once you see the "ok" prompt, you can proceed to enter code:
Retro's interpreter is started automatically. Once you see the "ok" prompt, you can proceed to enter code:


<lang Retro>:f (sss-s) [ s:prepend ] sip s:prepend s:append ;
<syntaxhighlight lang="retro">:f (sss-s) [ s:prepend ] sip s:prepend s:append ;
'Rosetta 'Code ': f</lang>
'Rosetta 'Code ': f</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===version 1===
<lang rexx>/*REXX*/ parse arg a b c
<syntaxhighlight lang="rexx">/*REXX*/ parse arg a b c
say f(a,b,c)
say f(a,b,c)
exit
exit
f:return arg(1)arg(3)arg(3)arg(2)</lang>
f:return arg(1)arg(3)arg(3)arg(2)</syntaxhighlight>


===version 2===
===version 2===
This REXX version allows blanks to be included in the three strings.
This REXX version allows blanks to be included in the three strings.
<lang rexx>/*REXX program demonstrates interactive programming by using a function [F]. */
<syntaxhighlight lang="rexx">/*REXX program demonstrates interactive programming by using a function [F]. */
say f('Rosetta', "Code", ':')
say f('Rosetta', "Code", ':')
say f('The definition of a trivial program is ', " one that has no bugs.", '───')
say f('The definition of a trivial program is ', " one that has no bugs.", '───')
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
f: return arg(1) || copies(arg(3),2) || arg(2) /*return the required string to invoker*/</lang>
f: return arg(1) || copies(arg(3),2) || arg(2) /*return the required string to invoker*/</syntaxhighlight>
'''output''' &nbsp; when using the (internal) default strings:
'''output''' &nbsp; when using the (internal) default strings:
<pre>
<pre>
Line 1,352: Line 1,534:
===version 3===
===version 3===
This REXX version is more to the keeping of the spirit of the task requirements.
This REXX version is more to the keeping of the spirit of the task requirements.
<lang rexx>/*REXX program demonstrates interactive programming by using a function [F]. */
<syntaxhighlight lang="rexx">/*REXX program demonstrates interactive programming by using a function [F]. */
say '══════════════════ enter the function F with three comma-separated arguments:'
say '══════════════════ enter the function F with three comma-separated arguments:'
parse pull funky
parse pull funky
Line 1,358: Line 1,540:
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
f: return arg(1) || copies(arg(3),2) || arg(2) /*return the required string to invoker*/</lang>
f: return arg(1) || copies(arg(3),2) || arg(2) /*return the required string to invoker*/</syntaxhighlight>
'''output''' (a screen scraping is shown)
'''output''' (a screen scraping is shown)
<br><br>'''int_act3''' is the name of the REXX program [INT_ACT3.REX)
<br><br>'''int_act3''' is the name of the REXX program [INT_ACT3.REX)
Line 1,375: Line 1,557:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
r = "Rosetta"
r = "Rosetta"
c = "Code"
c = "Code"
s = ":"
s = ":"
see r+s+s+c
see r+s+s+c
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 1,386: Line 1,568:
</pre>
</pre>


=={{header|Rust}}==
=={{header|RPL}}==
RPL command-line interpreter is permanently running. Each created function can be called by its name, the same way as built-in instructions, without any prefix.
<lang rust>
≪ "::" SWAP + + ≫ ‘FUNC’ STO
fn main() {
println!("{:?}", f("Rosetta", "Code", ":"));
"Rosetta" "Code" FUNC
{{out}}
}

fn f<'a>(s1: &'a str, s2: &'a str, sep :&'a str) -> String{
[s1,sep,sep,s2].iter().map(|x| *x).collect()
}
</lang>
Output:
<pre>
<pre>
Rosetta::Code
1: "Rosetta::Code"
</pre>
</pre>

=={{header|Ruby}}==
=={{header|Ruby}}==
The read-eval-print loop (REPL) for Ruby is ''irb'', the '''''i'''nteractive '''r'''u'''b'''y shell''.
The read-eval-print loop (REPL) for Ruby is ''irb'', the '''''i'''nteractive '''r'''u'''b'''y shell''.
Line 1,406: Line 1,581:
Start the interpreter by typing <code>irb</code> at the command line. You will see an input prompt, which by default is <code>name of this program(name of main object):line number:indent level> </code>:
Start the interpreter by typing <code>irb</code> at the command line. You will see an input prompt, which by default is <code>name of this program(name of main object):line number:indent level> </code>:


<lang ruby>$ irb
<syntaxhighlight lang="ruby">$ irb
irb(main):001:0> def f(string1, string2, separator)
irb(main):001:0> def f(string1, string2, separator)
irb(main):002:1> [string1, '', string2].join(separator)
irb(main):002:1> [string1, '', string2].join(separator)
Line 1,414: Line 1,589:
=> "Rosetta::Code"
=> "Rosetta::Code"
irb(main):005:0> exit
irb(main):005:0> exit
$</lang>
$</syntaxhighlight>

=={{header|Rust}}==
This method use the crate clap: '''clap''' is used to parse and validate the string of command line arguments provided by the user at runtime. You provide the list of valid possibilities, and clap handles the rest. This means you focus on your applications functionality, and less on the parsing and validating of arguments.
One of clap configurations is a mathod used a YAML file to build the CLI and keep the Rust source tidy or support multiple localized translations by having different YAML files for each localization.
- First, create the cli.yaml file to hold the CLI options, but it could be called anything we like:
<syntaxhighlight lang="yaml">
name: myapp
version: "1.0"
author: A Rust Developer <rustme@home.com>
about: Does awesome things
args:
- STRING1:
about: First string to use
required: true
index: 1
- STRING2:
about: Second string to use
required: true
index: 2
- SEPARATOR:
about: Separtor to use
required: true
index: 3
</syntaxhighlight>

- Then, simply add ''clap'' the ''yaml'' feature flag to your Cargo.toml.
<syntaxhighlight lang="yaml">
[dependencies]
clap = { version = "3.0.0-beta.2", features = ["yaml"] }
</syntaxhighlight>

- Enter this code in Rust source file
<syntaxhighlight lang="rust">
#[macro_use]
extern crate clap;
use clap::App;
fn main() {
let yaml = load_yaml!("cli.yaml");
let matches = App::from(yaml).get_matches();

let str1 = matches.value_of("STRING1").unwrap();
let str2 = matches.value_of("STRING2").unwrap();
let str3 = matches.value_of("SEPARATOR").unwrap();

println!("{:?}", f(&str1, &str2, &str3));
}

fn f<'a>(s1: &'a str, s2: &'a str, sep :&'a str) -> String{
[s1,sep,sep,s2].iter().map(|x| *x).collect()
}</syntaxhighlight>
Output:
<pre>
Rosetta::Code
</pre>


=={{header|S-lang}}==
=={{header|S-lang}}==
Line 1,423: Line 1,652:


Without any arguments it starts from the command-line in [REPL] command-mode:
Without any arguments it starts from the command-line in [REPL] command-mode:
<lang S-lang>> slsh<Enter>
<syntaxhighlight lang="s-lang">> slsh<Enter>
slsh version 0.9.1-2; S-Lang version: pre2.3.1-23
slsh version 0.9.1-2; S-Lang version: pre2.3.1-23
Copyright (C) 2005-2014 John E. Davis <jed@jedsoft.org>
Copyright (C) 2005-2014 John E. Davis <jed@jedsoft.org>
Line 1,434: Line 1,663:
Rosetta::Code
Rosetta::Code
slsh> quit<Enter>
slsh> quit<Enter>
> </lang>
> </syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Line 1,444: Line 1,673:
or a batch file depending on one's operating system:
or a batch file depending on one's operating system:


<lang scala>C:\>scala
<syntaxhighlight lang="scala">C:\>scala
Welcome to Scala version 2.8.0.r21356-b20100407020120 (Java HotSpot(TM) Client V
Welcome to Scala version 2.8.0.r21356-b20100407020120 (Java HotSpot(TM) Client V
M, Java 1.6.0_05).
M, Java 1.6.0_05).
Line 1,451: Line 1,680:


scala> "rosetta"
scala> "rosetta"
res0: java.lang.String = rosetta</lang>
res0: java.lang.String = rosetta</syntaxhighlight>
Scala's REPL, starting with version 2.8, offers both auto-completion and alternatives when typing TAB. For instance, to check what methods are available on a String, one
Scala's REPL, starting with version 2.8, offers both auto-completion and alternatives when typing TAB. For instance, to check what methods are available on a String, one
may do the following:
may do the following:
<lang scala>scala> "rosetta".
<syntaxhighlight lang="scala">scala> "rosetta".


!= ## $asInstanceOf
!= ## $asInstanceOf
Line 1,475: Line 1,704:


scala> "rosetta".+(":")
scala> "rosetta".+(":")
res1: java.lang.String = rosetta:</lang>
res1: java.lang.String = rosetta:</syntaxhighlight>
One can use `object`, `class`, `trait`, `case object`,
One can use `object`, `class`, `trait`, `case object`,
`case class`, `def`, `val` and `var` definitions at any point. However,
`case class`, `def`, `val` and `var` definitions at any point. However,
`package` and `package object` definitions are not allowed.
`package` and `package object` definitions are not allowed.
<lang scala>scala> val str1 = "rosetta"
<syntaxhighlight lang="scala">scala> val str1 = "rosetta"
str1: java.lang.String = rosetta</lang>
str1: java.lang.String = rosetta</syntaxhighlight>
Using these features, one can build the code for a method by testing it
Using these features, one can build the code for a method by testing it
part of it individually:
part of it individually:
<lang scala>scala> val str2 = "code"
<syntaxhighlight lang="scala">scala> val str2 = "code"
str2: java.lang.String = code
str2: java.lang.String = code


Line 1,490: Line 1,719:


scala> str1 + separator + str2
scala> str1 + separator + str2
res2: java.lang.String = rosetta:code</lang>
res2: java.lang.String = rosetta:code</syntaxhighlight>
If one makes a mistake, the REPL will print an error message, and display the
If one makes a mistake, the REPL will print an error message, and display the
point at which the mistake was made.
point at which the mistake was made.
<lang scala>scala> def (str1: String, str2: String, separator: String) =
<syntaxhighlight lang="scala">scala> def (str1: String, str2: String, separator: String) =
<console>:1: error: identifier expected but '(' found.
<console>:1: error: identifier expected but '(' found.
def (str1: String, str2: String, separator: String) =
def (str1: String, str2: String, separator: String) =
^</lang>
^</syntaxhighlight>
If a definition takes more than a line, the REPL will print an indented "|" sign, and
If a definition takes more than a line, the REPL will print an indented "|" sign, and
wait for more input. If one wishes to abort a definition, just enter two consecutive
wait for more input. If one wishes to abort a definition, just enter two consecutive
empty lines.
empty lines.
<lang scala>scala> def f(str1: String, str2: String, separator: String) =
<syntaxhighlight lang="scala">scala> def f(str1: String, str2: String, separator: String) =
| str1 + separator + str2
| str1 + separator + str2
f: (str1: String,str2: String,separator: String)java.lang.String
f: (str1: String,str2: String,separator: String)java.lang.String
Line 1,508: Line 1,737:


scala> f("code", "rosetta", ", ")
scala> f("code", "rosetta", ", ")
res4: java.lang.String = code, rosetta</lang>
res4: java.lang.String = code, rosetta</syntaxhighlight>
Also starting with version 2.8, a line starting with a dot will be interpreted
Also starting with version 2.8, a line starting with a dot will be interpreted
as a method call on the last result produced.
as a method call on the last result produced.
<lang scala>scala> .length
<syntaxhighlight lang="scala">scala> .length
res5: Int = 13
res5: Int = 13


scala></lang>
scala></syntaxhighlight>
The results are actually displayed with a special function, which pretty prints
The results are actually displayed with a special function, which pretty prints
some results, and avoid eagerly evaluating others, where that could cause problems
some results, and avoid eagerly evaluating others, where that could cause problems
(such as infinite collections).
(such as infinite collections).
<lang scala>scala> Array(1, 2, 3, 4)
<syntaxhighlight lang="scala">scala> Array(1, 2, 3, 4)
res8: Array[Int] = Array(1, 2, 3, 4)
res8: Array[Int] = Array(1, 2, 3, 4)


scala> println(res8)
scala> println(res8)
[I@383244</lang>
[I@383244</syntaxhighlight>
There are many other features, such as the ability to add new jars to
There are many other features, such as the ability to add new jars to
the class path, executing commands on the shell, retrieving the last
the class path, executing commands on the shell, retrieving the last
Line 1,529: Line 1,758:
=={{header|Scheme}}==
=={{header|Scheme}}==
Several interpreters exist for Scheme. These are just some examples.
Several interpreters exist for Scheme. These are just some examples.
<lang>> scheme
<syntaxhighlight lang="text">> scheme
Scheme Microcode Version 14.9
Scheme Microcode Version 14.9
MIT Scheme running under FreeBSD
MIT Scheme running under FreeBSD
Line 1,550: Line 1,779:
End of input stream reached
End of input stream reached
Happy Happy Joy Joy.
Happy Happy Joy Joy.
></lang>
></syntaxhighlight>
<lang>> scheme48
<syntaxhighlight lang="text">> scheme48
Welcome to Scheme 48 1.8 (made by root on Wed Sep 24 22:37:08 UTC 2008)
Welcome to Scheme 48 1.8 (made by root on Wed Sep 24 22:37:08 UTC 2008)
Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees.
Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees.
Line 1,568: Line 1,797:
I'll only ask another 99 times.
I'll only ask another 99 times.
Exit Scheme 48 (y/n)? y
Exit Scheme 48 (y/n)? y
></lang>
></syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>$ sidef -i
<syntaxhighlight lang="ruby">$ sidef -i
>>> func f(s1, s2, sep) { s1 + sep*2 + s2 };
>>> func f(s1, s2, sep) { s1 + sep*2 + s2 };
f
f
>>> f('Rosetta', 'Code', ':')
>>> f('Rosetta', 'Code', ':')
"Rosetta::Code"
"Rosetta::Code"
>>> </lang>
>>> </syntaxhighlight>


=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>slate[1]> s@(String traits) rosettaWith: s2@(String traits) and: s3@(String traits) [s ; s3 ; s3 ; s2].
<syntaxhighlight lang="slate">slate[1]> s@(String traits) rosettaWith: s2@(String traits) and: s3@(String traits) [s ; s3 ; s3 ; s2].
[rosettaWith:and:]
[rosettaWith:and:]
slate[2]> 'Rosetta' rosettaWith: 'Code' and: ':'.
slate[2]> 'Rosetta' rosettaWith: 'Code' and: ':'.
'Rosetta::Code'</lang>
'Rosetta::Code'</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
{{works with|GNU Smalltalk}}
<lang smalltalk>$ gst
<syntaxhighlight lang="smalltalk">$ gst
GNU Smalltalk ready
GNU Smalltalk ready


Line 1,596: Line 1,825:
Rosetta::Code
Rosetta::Code
'Rosetta::Code'
'Rosetta::Code'
st></lang>
st></syntaxhighlight>
{{works with|Smalltalk/X}}
{{works with|Smalltalk/X}}
<lang smalltalk>$ stx --repl
<syntaxhighlight lang="smalltalk">$ stx --repl
Welcome...
Welcome...


Line 1,606: Line 1,835:
Rosetta::Code
Rosetta::Code
-> (Answer): 'Rosetta::Code'
-> (Answer): 'Rosetta::Code'
STX></lang>
STX></syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 1,630: Line 1,859:
Because you can enter expressions that span multiple lines, you have to type the semicolon (";") at the end so that it knows you are done.
Because you can enter expressions that span multiple lines, you have to type the semicolon (";") at the end so that it knows you are done.


<lang sml>$ sml
<syntaxhighlight lang="sml">$ sml
Standard ML of New Jersey v110.67 [built: Fri Jul 4 09:00:58 2008]
Standard ML of New Jersey v110.67 [built: Fri Jul 4 09:00:58 2008]
- fun f (s1, s2, sep) = String.concatWith sep [s1, "", s2];
- fun f (s1, s2, sep) = String.concatWith sep [s1, "", s2];
Line 1,639: Line 1,868:
- f ("Rosetta", "Code", ":");
- f ("Rosetta", "Code", ":");
val it = "Rosetta::Code" : string
val it = "Rosetta::Code" : string
-</lang>
-</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>$ tclsh
<syntaxhighlight lang="tcl">$ tclsh
% proc f {s1 s2 sep} {
% proc f {s1 s2 sep} {
append result $s1 $sep $sep $s2
append result $s1 $sep $sep $s2
Line 1,648: Line 1,877:
% f Rosetta Code :
% f Rosetta Code :
Rosetta::Code
Rosetta::Code
% exit</lang>
% exit</syntaxhighlight>
A simple alternative (one-liners are most convenient in an interactive shell):
A simple alternative (one-liners are most convenient in an interactive shell):
<lang tcl>$ tclsh
<syntaxhighlight lang="tcl">$ tclsh
% proc f {a b s} {join [list $a "" $b] $s}
% proc f {a b s} {join [list $a "" $b] $s}
% f Rosetta Code :
% f Rosetta Code :
Rosetta::Code
Rosetta::Code
%</lang>
%</syntaxhighlight>


=={{header|TI-89 BASIC}}==
=={{header|TI-89 BASIC}}==
Line 1,669: Line 1,898:
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<lang bash>$ sh
<syntaxhighlight lang="bash">$ sh
sh-3.2$ concat() { echo "$1$3$3$2"; }
sh-3.2$ concat() { echo "$1$3$3$2"; }
sh-3.2$ concat Rosetta Code :
sh-3.2$ concat Rosetta Code :
Rosetta::Code
Rosetta::Code
sh-3.2$</lang>
sh-3.2$</syntaxhighlight>


==={{header|C Shell}}===
==={{header|C Shell}}===
<lang csh>$ csh -f
<syntaxhighlight lang="csh">$ csh -f
% alias concat 'echo "\!:1\!:3\!:3\!:2"'
% alias concat 'echo "\!:1\!:3\!:3\!:2"'
% concat Rosetta Code :
% concat Rosetta Code :
Rosetta::Code
Rosetta::Code
%</lang>
%</syntaxhighlight>


==={{header|es}}===
==={{header|es}}===
<lang es>$ es
<syntaxhighlight lang="es">$ es
; fn concat a b s { result $a$s$s$b }
; fn concat a b s { result $a$s$s$b }
; echo <={concat Rosetta Code :}
; echo <={concat Rosetta Code :}
Rosetta::Code
Rosetta::Code
;</lang>
;</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa>$ java -jar ursa.jar
<syntaxhighlight lang="ursa">$ java -jar ursa.jar
cygnus/x ursa v0.76 (default, release 1)
cygnus/x ursa v0.76 (default, release 1)
[Oracle Corporation JVM 1.8.0_91 on Linux 3.16.0-4-686-pae i386]
[Oracle Corporation JVM 1.8.0_91 on Linux 3.16.0-4-686-pae i386]
Line 1,698: Line 1,927:
> out (f "Rosetta" "Code" ":") endl console
> out (f "Rosetta" "Code" ":") endl console
Rosetta::Code
Rosetta::Code
> _</lang>
> _</syntaxhighlight>


=={{header|Vedit macro language}}==
=={{header|Vedit macro language}}==
Line 1,705: Line 1,934:


To define a macro in text register 100:
To define a macro in text register 100:
<lang vedit>RS(100, "RS(10, @1) RS(10, @3, APPEND) RS(10, @3, APPEND) RS(10, @2, APPEND)")</lang>
<syntaxhighlight lang="vedit">RS(100, "RS(10, @1) RS(10, @3, APPEND) RS(10, @3, APPEND) RS(10, @2, APPEND)")</syntaxhighlight>


To call the macro:
To call the macro:
<lang vedit>RS(1,"Rosetta") RS(2,"Code") RS(3,":") Call(100)
<syntaxhighlight lang="vedit">RS(1,"Rosetta") RS(2,"Code") RS(3,":") Call(100)
Message(@10)</lang>
Message(@10)</syntaxhighlight>


=={{header|XLISP}}==
=={{header|XLISP}}==
How to start a REPL depends on the operating system.
How to start a REPL depends on the operating system.
<lang lisp>XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz
<syntaxhighlight lang="lisp">XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz
[1] (defun f (a b sep)
[1] (defun f (a b sep)
(string-append a sep sep b))
(string-append a sep sep b))
Line 1,721: Line 1,950:


"Rosetta::Code"
"Rosetta::Code"
[3] </lang>
[3] </syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 1,728: Line 1,957:
$ ./wren
$ ./wren
\\/"-
\\/"-
\_/ wren v0.2.0
\_/ wren v0.4.0
> var f = Fn.new { |s1, s2, sep| s1 + sep + sep + s2 }
> var f = Fn.new { |s1, s2, sep| s1 + sep + sep + s2 }
> f.call("Rosetta", "Code", ":")
> f.call("Rosetta", "Code", ":")
Line 1,747: Line 1,976:
zkl:
zkl:
</pre>
</pre>
{{Omit From|6502 Assembly|You'd have to create your own}}

{{Omit From|68000 Assembly|You'd have to create your own}}
{{Omit From|ARM Assembly|You'd have to create your own}}
{{Omit From|AArch64 Assembly|You'd have to create your own}}
{{Omit From|MIPS Assembly|You'd have to create your own}}
{{Omit From|8080 Assembly|You'd have to create your own}}
{{Omit From|8086 Assembly|You'd have to create your own}}
{{Omit From|Z80 Assembly|You'd have to create your own}}
{{Omit From|Ada}}
{{Omit From|Ada}}
{{Omit From|ALGOL 68|might be possible, esp given that some A68 compilers are written in A68. Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et generaliter nullam in infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demonstrationem mirabilem sane detexi. Hanc rosettacode.org exiguitas non caperet.}}
{{Omit From|ALGOL 68|might be possible, esp given that some A68 compilers are written in A68. Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et generaliter nullam in infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demonstrationem mirabilem sane detexi. Hanc rosettacode.org exiguitas non caperet.}}

Latest revision as of 11:28, 11 December 2023

Task
Interactive programming (repl)
You are encouraged to solve this task according to the task description, using any language you may know.

Many language implementations come with an interactive mode.

This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.

An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell.


Task

Show how to start this mode.

Then, as a small example of its use, interactively create a function of two strings and a separator that returns the strings separated by two concatenated instances of the separator   (the 3rd argument).


Example
             f('Rosetta',  'Code',  ':')   

should return

             'Rosetta::Code'               


Note

This task is   not   about creating your own interactive mode.

8th

8th (like all Forth derivatives) has a built-in interpreter loop. All you need to do to access it is to start 8th:

 $ 8th
8th 1.0.2 Linux 64 (f1b7a8c2)
ok> 

At the "ok> " prompt type in what you want:

ok> : f 2 s:* swap s:+ s:+ ;
ok> "Rosetta" "Code" ":" f . cr
Rosetta::Code
ok>

ACL2

$ acl2
Welcome to Clozure Common Lisp Version 1.7-r14925M  (DarwinX8664)!

 ACL2 Version 4.3 built September 8, 2011  09:08:23.
 Copyright (C) 2011  University of Texas at Austin
 ACL2 comes with ABSOLUTELY NO WARRANTY.  This is free software and you
 are welcome to redistribute it under certain conditions.  For details,
 see the GNU General Public License.

 Initialized with (INITIALIZE-ACL2 'INCLUDE-BOOK *ACL2-PASS-2-FILES*).
 See the documentation topic note-4-3 for recent changes.
 Note: We have modified the prompt in some underlying Lisps to further
 distinguish it from the ACL2 prompt.

ACL2 Version 4.3.  Level 1.  Cbd "/Users/username/".
Distributed books directory "/Users/username/Code/acl2/books/".
Type :help for help.
Type (good-bye) to quit completely out of ACL2.

ACL2 !>(defun f (s1 s2 sep)
(concatenate 'string s1 sep sep s2))

Since F is non-recursive, its admission is trivial.  We observe that
the type of F is described by the theorem (STRINGP (F S1 S2 SEP)).
We used the :type-prescription rule STRING-APPEND-LST.

Summary
Form:  ( DEFUN F ...)
Rules: ((:TYPE-PRESCRIPTION STRING-APPEND-LST))
Time:  0.01 seconds (prove: 0.00, print: 0.00, other: 0.00)
 F
ACL2 !>(f "Rosetta" "Code" ":")
"Rosetta::Code"
ACL2 !>(good-bye)

Arturo

➜  $ arturo 

Arturo
(c) 2019-2021 Yanis Zafirópulos

# v/0.9.6.5 b/1097 @ 2021-02-09T16:40:43+01:00
# arch: amd64/macosx

# Type info 'symbol for info about a specific symbol or built-in function
# Type help to get a list of all available functions with a short description
# For multi-line input, just add a blank space at the end of a line

# Launching interactive console - rock on! 🤘

$> f: function [x y sep]-> x ++ (repeat sep 2) ++ y

$> f "Rosetta" "Code" ":"
=> Rosetta::Code

$>

BASIC

Works with: SAM BASIC

This was tested with SAM BASIC, but it should work with most Basic interpreters.

A Basic interpreter is in command mode by default. Enter the following in command mode:

10 DEF FN f$(a$, b$, s$) = a$+s$+s$+b$
PRINT FN f$("Rosetta", "Code", ":")

Applesoft BASIC

The Apple II comes with BASIC in Read Only Memory (ROM.) When the Apple II plus and later models are powered on with no disk drives attached, the Applesoft BASIC prompt appears.

]

If a drive is attached, press RESET or Ctrl+RESET before the disk boots to get to the Applesoft BASIC prompt.

The original Apple II comes with Integer BASIC in ROM.

>

With an Applesoft ROM card, or a 16K RAM "Language" card in slot 0, you can boot from the DOS 3.3 System Master to load DOS and if needed it will load Applesoft into the Language card. Type the DOS 3.3 command FP "Floating Point" to get to the Applesoft BASIC prompt. There is also an older cassette tape version of Applesoft BASIC.

You can also get to Applesoft Basic from the Monitor.

*

Type E000G to cold start Applesoft which clears the program and variables. Or, type E003G to warm start Applesoft.

The two modes are RUN mode, and the default "DIRECT" mode. In direct mode, spaces are ignored except within strings. Entering ? is shorthand for the PRINT keyword. Using GET, INPUT, or DEF FN will result in an ?ILLEGAL DIRECT ERROR. The DATA statement is ignored.

] 0  IF F$ = "F" THEN RESULT$ = P1$ + P3$ + P3$ + P2$: END

] F$ = "F":P1$ = "ROSETTA":P2$ = "CODE":P3$ = ":": GOTO

] ?RESULT$
ROSETTA::CODE

Batch File

CMD.EXE is the CLI for Batch Files. Batch Files do not have traditional functions and doing the alternative will not work in interactive mode. So this example uses blocks of code.

Translation of: BBC BASIC
>set r=Rosetta

>set c=Code

>set s=:

>echo %r%%s%%s%%c%
Rosetta::Code

>

BBC BASIC

Interactive mode is entered by clicking on the 'Immediate' toolbar button or selecting Immediate from the Run menu. Functions cannot be defined in immediate mode so the example below uses inline code:

>r$ = "Rosetta"
>c$ = "Code"
>s$ = ":"
>PRINT r$+s$+s$+c$
Rosetta::Code
>

bc

bc has no string operations, so I will instead show how to use hexadecimal numbers such that f(205E77A, C0DE, 1) returns 205E77A11C0DE.

Step 1. I start the interactive interpreter, switch from base 10 to base 16, and check that 1000 - 2 is FFE, not 998. My bc has no prompt, so I will use »bold text to show where I typed my input.

$ »bc
»obase = ibase = 16
»1000 - 2
FFE

Step 2. I define a helper function d() to count the number of digits in a number. I check that d() works for positive numbers.

»define d(a) {
»  auto r
»  r = 0
»  while (a != 0) {
»    r += 1
»    a /= 10
»  }
»  return (r)
»}
»d(4)
1
»d(5A)
2
»d(67B)
3

Step 3. I define f() and call it.

»define f(a, b, c) {
»  auto d, e, f       
»  d = d(b)
»  e = d + d(c)
»  f = e + d(c)
»  return (a * 10 ^ f + c * 10 ^ e + c * 10 ^ d + b)
»}
»f(205E77A, C0DE, 1)
205E77A11C0DE

Step 4. I quit. (Control-D also works.)

»quit
$

BQN

All BQN implementations start in interactive mode, when called from the command line with no arguments (using Node.js for mlochbaum/BQN). It is recommended to use rlwrap with the executable for a better REPL experience.

   Join  {a 𝕊 bc: baac}
(function block)
   ":" Join "Rosetta""Code"
"Rosetta::Code"

Bracmat

Running Bracmat without arguments starts the program in interactive mode. The prompt is {?}. After evaluation, Bracmat prints {!} followed by the result. Input can extend over multiple lines, but is terminated by a new line if all parentheses are balanced (() or {}) and any string introduced with " also is closed with ". The number of needed closing parentheses is indicated at the start of a new input line. Provided the file help is in the current working directory, the user can get interactive help by entering get$help. The program is closed by entering an extra closing parenthesis, followed by a confirming y.

D:\projects\Bracmat>bracmat
Bracmat version 5, build 105 (1 December 2011)
Copyright (C) 2002 Bart Jongejan
Bracmat comes with ABSOLUTELY NO WARRANTY; for details type `!w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `!c' for details.



{?} get$help { tutorial }
{?} )        { stop }
{?} (f=a b c.
{1}   !arg:(?a,?b,?c)
{1}   & str$(!a !c !b)
{1}   )
{!} f
    S   0,00 sec  (2156.2173.0)
{?} f$(Rosetta,Code,":")
{!} Rosetta:Code
    S   0,00 sec  (2156.2173.0)
{?}

Brat

$ brat
# Interactive Brat
brat:1> f = { a, b, s | a + s + s + b }
#=> function: 0xb737ac08
brat:2> f "Rosetta" "Code" ":"
#=> Rosetta::Code
brat:3> quit
Exiting

Burlesque

C:\Burlesque>Burlesque.exe --shell
blsq ) {+]?+}hd"Rosetta""Code"':!a
"Rosetta:Code"
blsq )

C#

Works with: Visual Studio version >= 2015 Update 1

Visual Studio 2015 and above come with a C# REPL (called the C# Interactive Compiler), which can be launched as csi from the Visual Studio developer command prompt.

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.14
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>csi /?
Microsoft (R) Visual C# Interactive Compiler version 2.10.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: csi [option] ... [script-file.csx] [script-argument] ...

Executes script-file.csx if specified, otherwise launches an interactive REPL (Read Eval Print Loop).

Options:
  /help                          Display this usage message (alternative form: /?)
  /version                       Display the version and exit
  /i                             Drop to REPL after executing the specified script.
  /r:<file>                      Reference metadata from the specified assembly file (alternative form: /reference)
  /r:<file list>                 Reference metadata from the specified assembly files (alternative form: /reference)
  /lib:<path list>               List of directories where to look for libraries specified by #r directive.
                                 (alternative forms: /libPath /libPaths)
  /u:<namespace>                 Define global namespace using (alternative forms: /using, /usings, /import, /imports)
  @<file>                        Read response file for more options
  --                             Indicates that the remaining arguments should not be treated as options.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>csi
Microsoft (R) Visual C# Interactive Compiler version 2.10.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

Type "#help" for more information.
> string f(string s1, string s2, char sep) => s1+sep+sep+s2;
> f("Rosetta", "Code", ':')
"Rosetta::Code"
>

Clojure

With clojure.jar on the Java classpath, the Clojure REPL is invoked with java clojure.main.

Clojure 1.1.0
user=> (defn f [s1 s2 sep] (str s1 sep sep s2))
#'user/f
user=> (f "Rosetta" "Code" ":")
"Rosetta::Code"
user=>

CoffeeScript

With the coffee-script package for NPM on Node.js. The -n flag is '--node'.

$ coffee -n
coffee> f = (a, b, c) -> a + c + c + b
[Function]
coffee> f "Rosetta", "Code", ":"
"Rosetta::Code"

Common Lisp

The details of interactive use vary widely between implementations; this example is from SBCL. * is the prompt. By default, SBCL compiles (not interprets) all code, unless sb-ext:*evaluator-mode* is changed.

$ rlwrap sbcl
This is SBCL 1.0.25, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
...
* (defun f (string-1 string-2 separator)
    (concatenate 'string string-1 separator separator string-2))

F
* (f "Rosetta" "Code" ":")

"Rosetta::Code"
*

Déjà Vu

The interactive interpreter provides . as a shortcut for !. and ; as a shortcut for !(print-stack).

$ vu
<1:1> f str1 str2 sep:
<1:2>     join sep [ str2 "" str1 ]
<1:3> 
<2:1> . f "Rosetta" "Code" ":"
"Rosetta::Code"

E

$ rune   # from an OS shell. On Windows there is also a desktop shortcut.

"?" and ">" are prompts for input; "#" marks output.

? def f(string1 :String, string2 :String, separator :String) {
>     return separator.rjoin(string1, "", string2)
> }
# value: <f>

? f("Rosetta", "Code", ":")
# value: "Rosetta::Code"

If you type a definitely incomplete expression, such as "def f() {", then it gives an ">" prompt and takes additional lines. If the expression is not necessarily incomplete, you can continue anyway by ending a line with "\".

EchoLisp

EchoLisp runs in a browser window, and is -par essence - interactive. To start the REPL mode, type http://www.echolalie.org/echolisp in the browser URL address field.

;; screen copy of the REPL
;; note that the &i variables remember expression evaluation, and may be used in other expressions

EchoLisp - 2.16.2
📗 local-db: db.version: 3
(define ( f s1 s2 s3) (string-append s1 s3 s3 s2))
[0] f
(f "Rosetta" "Code" ":")
[1] "Rosetta::Code"
(+ 4 8)
[2] 12
(* 4 8)
[3] 32
(* &2 &3)
[4] 384
(f &1 &1 ":")
[5] "Rosetta::Code::Rosetta::Code"

;; etc.

Elena

ELENA Script is a subset of the general language. ELT (Virtual machine terminal) can work in REPL mode

c:\Alex\ELENA\bin>elt-cli
ELENA command line VM terminal 6.0.7 (C)2021-23 by Aleksey Rakov
ELENA VM 6.0.25 (C)2022-2023 by Aleksey Rakov
Initializing...
-q                         - quit
-c                         - clear
-h                         - help
-l <path>                  - execute a script from file
-p<script>;                - prepend the prefix code
{ <script>; }*
 <script>                  - execute script

>-pf(s1,s2,sep){^ s1 + sep + sep + s2 }

>f("Rosetta","Code",":")
Rosetta::Code
>

Elixir

Elixir's Interactive REPL is IEx, Interactive Elixir. To open IEx, open a shell and type: iex
The 'def' keyword isn't allowed outside of modules in Elixir, so the easiest way to write a function in iex is usually by writing an anonymous function.

iex(1)> f = fn str1,str2,sep -> [str1,"",str2] |> Enum.join(sep) end # Join list on separator
iex(2)> g = fn str1,str2,sep -> str1 <> sep <> sep <> str2 end       # Or concatenate strings

iex(3)> defmodule JoinStrings do
...(3)>   def f(str1,str2,sep), do: [str1,"",str2] |> Enum.join(sep)
...(3)>   def g(str1,str2,sep), do: str1 <> sep <> sep <> str2
...(3)> end

Example:

iex(4)> f.("Rosetta","Code",":")
"Rosetta::Code"
iex(5)> JoinStrings.f("Rosetta","Code",":")
"Rosetta::Code"

Emacs Lisp

Emacs opens a *scratch* buffer by default. This buffer is in Lisp Interaction mode; C-j evaluates the Lisp expression before point, and prints the result.

Switch to the buffer (C-x b *scratch*, or use the Buffers menu), type some Lisp expressions, and press C-j after each expression.

(defun my-join (str1 str2 sep)
  (concat str1 sep sep str2))
my-join
(my-join "Rosetta" "Code" ":")
"Rosetta::Code"

Emacs also provides ielm, the interactive Emacs Lisp mode. Start it with M-x ielm, type some expressions and press RET.

*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (defun my-join (str1 str2 sep)
	 (concat str1 sep sep str2))
my-join
ELISP> (my-join "Rosetta" "Code" ":")
"Rosetta::Code"
ELISP>

Erlang

$erl
1> F = fun(X,Y,Z) -> string:concat(string:concat(X,Z),string:concat(Z,Y)) end.
#Fun<erl_eval.18.105910772>
2> F("Rosetta", "Code", ":").
"Rosetta::Code"

ERRE

ERRE hasn't no interactive mode. You can only execute the R-Code Interpreter in this way: from main menu do Utilità --> Dos Shell and then from command prompt RCODE <Enter> and then type this

 r$="Rosetta"
 Ok   <--- from interpreter
 c$="Code"
 Ok   <--- from interpreter
 s$="-"
 Ok   <--- from interpreter
 PRINT r$+s$+c$
 Rosetta-Code
 Ok   <--- from interpreter

Type

system 

to return to command prompt.

F#

The F# interpreter is called fsi. As F# accepts multi-line input it will not evaluate the input until you enter two semi-colons together.

Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727

Please send bug reports to fsbugs@microsoft.com
For help type #help;;

> let f a b sep = String.concat sep [a; ""; b] ;;

val f : string -> string -> string -> string

> f "Rosetta" "Code" ":" ;;
val it : string = "Rosetta::Code"

Factor

Factor comes with a graphical interpreter called the listener. The listener can also be run in a console with the following command:

./factor -run=listener
( scratchpad ) : cool-func ( w1 w2 sep -- res ) dup append glue ;
( scratchpad ) "Rosetta" "Code" ":" cool-func .
"Rosetta::Code"

Fantom

Fantom comes with a command-line interpreter called 'fansh'

$ fansh
Fantom Shell v1.0.57 ('?' for help)
fansh> f := |Str a, Str b, Str c -> Str| {"$a$c$c$b"}
|sys::Str,sys::Str,sys::Str->sys::Str|
fansh> f("Rosetta", "Code", ":")
Rosetta::Code

Forth

Works with: GNU Forth

All Forth systems come with an interpreter. On embedded systems, the interpreter functions as a monitor or lightweight operating system.

$ gforth
Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
  ok
: f ( separator suffix prefix -- )  compiled
   pad place  2swap 2dup   compiled
   pad +place    compiled
   pad +place    compiled
   pad +place  compiled
   pad count ;  ok
  ok
 s" :" s" Code" s" Rosetta" f cr type
Rosetta::Code ok

FreeBASIC

FreeBASIC is a compiler rather than an interpreter and doesn't have an interactive mode as such.

However, as simple programs can be written in a few lines and compile and execute very quickly, I think it's fair to say that the lack of an interpreter is not considered much of a drawback by most FB developers.

For example, the current task can be coded as follows and compiles/runs instantly :

' FB 1.05.0 Win64

Dim As String s1, s2, sep
Input "First string  "; s1
Input "Second string "; s2
Input "Separator     "; sep
Print : Print  s1 + sep + sep + s2
Sleep
Output:
First string  ? Rosetta
Second string ? Code
Separator     ? :

Rosetta::Code

Frink

Frink is distributed as a single .jar file that will run in a Java Virtual Machine. On many operating systems, just double-clicking this .jar file will run Frink with a graphical interface in an interactive mode. By specifying a different main-class (frink.parser.Frink) when starting Frink, it can be run in a text-mode interactive mode as well. These options and sample starter scripts for various operating systems are provided in the Running Frink section of the documentation.

$ java -cp frink.jar frink.parser.Frink

f[a,b,s] := "$a$s$s$b"
f["Rosetta", "Code", ":"]
Output:
Rosetta::Code

Fōrmulæ

The interactive mode (REPL) is the primary working mode in Fōrmulæ.

To use it, open the web address formulae.org in your browser. it is preferable to use this environment in a desktop web browser.

It is not necessary to install anything else.

A page with information is shown. You can start a new script using the tool (new document).

GAP

~% gap
    
            #########           ######         ###########           ###  
         #############          ######         ############         ####  
        ##############         ########        #############       #####  
       ###############         ########        #####   ######      #####  
      ######         #         #########       #####    #####     ######  
     ######                   ##########       #####    #####    #######  
     #####                    ##### ####       #####   ######   ########  
     ####                    #####  #####      #############   ###  ####  
     #####     #######       ####    ####      ###########    ####  ####  
     #####     #######      #####    #####     ######        ####   ####  
     #####     #######      #####    #####     #####         #############
      #####      #####     ################    #####         #############
      ######     #####     ################    #####         #############
      ################    ##################   #####                ####  
       ###############    #####        #####   #####                ####  
         #############    #####        #####   #####                ####  
          #########      #####          #####  #####                ####  
                                                                          
     Information at:  http://www.gap-system.org
     Try '?help' for help. See also  '?copyright' and  '?authors'
    
   Loading the library. Please be patient, this may take a while.
GAP4, Version: 4.4.12 of 17-Dec-2008, x86_64-unknown-linux-gnu-gcc
Components:  small 2.1, small2 2.0, small3 2.0, small4 1.0, small5 1.0, small6 1.0, small7 1.0, small8 1.0, 
             small9 1.0, small10 0.2, id2 3.0, id3 2.1, id4 1.0, id5 1.0, id6 1.0, id9 1.0, id10 0.1, trans 1.0, 
             prim 2.1  loaded.
Packages:    AClib 1.1, Polycyclic 2.6, Alnuth 2.2.5, AutPGrp 1.4, CrystCat 1.1.3, Cryst 4.1.6, CRISP 1.3.2, 
             CTblLib 1.1.3, TomLib 1.1.4, FactInt 1.5.2, GAPDoc 1.2, FGA 1.1.0.1, IRREDSOL 1.1.2, LAGUNA 3.5.0, 
             Sophus 1.23, Polenta 1.2.7, ResClasses 2.5.3  loaded.
gap> join := function(a, b, sep) 
>   return Concatenation(a, sep, sep, b);
> end;
function( a, b, sep ) ... end
gap> 
gap> join("Rosetta", "Code", ":");
"Rosetta::Code"
gap>

Go

To satisfy some of the desire for a REPL, Go includes a browser-based "playground" that compiles and executes directly from a browser edit box. You still have to type complete programs with all the usual boilerplate, but at least you don't have to create a source file, run the compiler, run the linker, and run the program. It has a convenient checkbox for "compile and run after each keystroke" that works quite well. You just type, and as soon as your program is valid, you see output.

Running goplay takes two steps. First, start the program with "goplay" on the command line, then visit http://localhost:3999/ with a browser.

The complete program satisfying the task is,

package main

import "fmt"

func f(s1, s2, sep string) string {
	return s1 + sep + sep + s2
}

func main() {
	fmt.Println(f("Rosetta", "Code", ":"))
}

It works well to enter the program, check "every keystroke" to see syntax errors from whatever silly oversights you made, then fix them one by one until your desired output appears.

Rosetta::Code

Groovy

The groovysh interpreter requires a command-line interpreter (terminal) environment in which to run. This example was run under the CMD command-line interpreter on Microsoft Windows XP.

C:\Apps\groovy>groovysh
Groovy Shell (1.6.2, JVM: 1.6.0_13)
Type 'help' or '\h' for help.
---------------------------------------------------------------------------------------------------
groovy:000> f = { a, b, sep -> a + sep + sep + b }
===> groovysh_evaluate$_run_closure1@5e8d7d
groovy:000> println f('Rosetta','Code',':')
Rosetta::Code
===> null
groovy:000> exit

C:\Apps\groovy>

Haskell

The details of interactive use vary widely between implementations. This example is from GHCi.

$ ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.4.2, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.
Prelude> let f as bs sep = as ++ sep ++ sep ++ bs
Prelude> f "Rosetta" "Code" ":"
"Rosetta::Code"

HicEst

Start HicEst e.g. with:
"c:\Program Files\HicEst\HicEst.exe E:\Rosetta\Interactive_programming.hic f('Rosetta', 'Code', ':')"
Type the following script. Each line is executed (and incrementally compiled) when it is typed:

CHARACTER A*40, B*40, C*40

READ(Text=$CMD_LINE, Format="'','','',") A, B, C
WRITE(ClipBoard, Name) A, B, C               ! A=Rosetta; B=Code; C=:;

WRITE(ClipBoard) TRIM(A) // ':' // TRIM(C) // TRIM(B)  ! Rosetta::Code

Insitux

First is the system shell, when Insitux has been already been installed system-wide (npm i -g insitux).

$ npx ix
Insitux 230728 REPL
❯ (function f s1 s2 sep (str s1 sep sep s2))
❯ (f "Rosetta" "Code" ":")
Rosetta::Code
❯

Io

$ io
Io 20110905
Io> f := method(str1,str2,sep,
... str1 .. sep .. sep .. str2)
==> method(str1, str2, sep, 
    str1 .. sep .. sep .. str2
)
Io> f("Rosetta","Code",":")
==> Rosetta::Code
Io> writeln("I am going to exit now")
I am going to exit now
==> nil
Io> exit
$ 

The function could have been written on one line but I wanted to show multi-line input with the continuation prompt .... The result of the expression that is entered appears after ==> and any output or error message appears before.

J

J runs in command mode by default. Starting J depends on your operating system and other factors, but typically would involve double clicking on an icon, or starting one of several programs from a command line (j, jwd, jconsole, jee, jhs -- though note that jhs would also require a web browser and visiting a localhost URL).

This is a session log once the os specific stuff has been handled:

   f=: [: ; 0 2 2 1&{
   f 'Rosetta';'Code';':'
Rosetta::Code

Java

public static void main(String[] args) {
    System.out.println(concat("Rosetta", "Code", ":"));
}

public static String concat(String a, String b, String c) {
   return a + c + c + b;
}

Rosetta::Code

Alternatively

Java has an interactive REPL (Read-Evaluate-Print-Loop) console, jshell, that is included with the JDK. 
The REPL is started by invoking: $JAVA_HOME/bin/jshell 
Here is a sample session to accomplish the task.
 
 | Welcome to JShell -- Version 20
 | For an introduction type: /help 

 jshell> String concat(String a, String b, String c) { return a + c + c + b; }
 |  created method concat(String, String, String)
   
 jshell> concat("Rosetta", "Code", ":")
 $2 ==> "Rosetta::Code"
  
 jshell>

JavaScript

Works with: Rhino
$ java -cp js.jar org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 2 2009 03 22
js> function f(a,b,s) {return a + s + s + b;}
js> f('Rosetta', 'Code', ':')
Rosetta::Code
js> quit()
$

Jsish

prompt$ jsish
Jsish interactive: see 'help [cmd]'
# function f(a:string, b:string, s:string):string { return a+s+s+b; }
# f('Rosetta', 'Code', 1)
warn: type mismatch for argument arg 3 's': expected "string" but got "number", in call to 'f' <1>.    (at or near "Code")

"Rosetta11Code"
# f('Rosetta', 'Code', ':')
"Rosetta::Code"

Julia

Julia has a fine REPL which is invoked by the command julia when no arguments are supplied.

usr@host:~/rosetta/julia$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.7 (2015-03-23 21:36 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
|__/                   |  x86_64-linux-gnu

julia> function strcat(a::String, b::String, sep::String)
                  a*(sep^2)*b
       end
strcat (generic function with 1 method)

julia> strcat("rosetta", "code", "_")
"rosetta__code"

julia>

K

Works with: Kona
$ rlwrap k
K Console - Enter \ for help
  f:{x,z,z,y}
  f["Rosetta";"Code";":"] 
"Rosetta::Code"

Kotlin

Kotlin has an interactive shell for the JVM which can be started by simply typing 'kotlinc' at the command line. Here's a sample interactive session to accomplish the specified task on Windows 10:

c:\kotlin-compiler-1.0.6>kotlinc
Welcome to Kotlin version 1.0.6-release-127 (JRE 1.8.0_31-b13)
Type :help for help, :quit for quit
>>> fun f(s1: String, s2: String, sep: String) = s1 + sep + sep + s2
>>> f("Rosetta", "Code", ":")
Rosetta::Code
>>> :quit

Lambdatalk

Lambdatalk works in a small wiki, lambdatank. Evaluation is done in real time.

{def F {lambda {:a :b :s} :a:s:s:b}}
-> F

{F Rosetta Code :}
-> Rosetta::Code

Lang

This example works with the LangShell from the Standard Lang implementation. The LangShell can be started with (The LangShell does not run in the OS's shell, it will open a separate window):

$ lang -startShell
Lang-Shell - Press CTRL + C for cancelling execution or for exiting!
• Copy with (CTRL + SHIFT + C) and paste with (CTRL + SHIT + V)
• Press CTRL + S for saving all inputs to a .lang file (Save)
• Press CTRL + SHIFT + S for saving all inputs to a .lang file (Save As...)
• Press CTRL + I for opening the special char input window
• Press CTRL + SHIFT + F for opening a file chooser to insert file paths
• Press UP and DOWN for scrolling through the history
• Press TAB and SHIFT + TAB for scrolling trough auto complete texts
    ◦ Press ENTER for accepting the auto complete text
• Press CTRL + L to clear the screen
• Use func.printHelp() to get information about LangShell functions
> fp.f = ($a, $b, $s) -> return $a$s$s$b
 ==> <Normal FP>
> fp.f(Rosetta, Code, :)
 ==> Rosetta::Code
>

Example with auto print mode set to NONE:

Lang-Shell - Press CTRL + C for cancelling execution or for exiting!
• Copy with (CTRL + SHIFT + C) and paste with (CTRL + SHIT + V)
• Press CTRL + S for saving all inputs to a .lang file (Save)
• Press CTRL + SHIFT + S for saving all inputs to a .lang file (Save As...)
• Press CTRL + I for opening the special char input window
• Press CTRL + SHIFT + F for opening a file chooser to insert file paths
• Press UP and DOWN for scrolling through the history
• Press TAB and SHIFT + TAB for scrolling trough auto complete texts
    ◦ Press ENTER for accepting the auto complete text
• Press CTRL + L to clear the screen
• Use func.printHelp() to get information about LangShell functions
> fn.setAutoPrintMode(NONE)
> fp.f = ($a, $b, $s) -> return $a$s$s$b
> fn.println(fp.f(Rosetta, Code, :))
Rosetta::Code
>

Lasso

#!/usr/bin/lasso9

// filename: interactive_demo

define concatenate_with_delimiter(
	string1::string,
	string2::string,
	delimiter::string

) => #string1 + (#delimiter*2) + #string2

define read_input(prompt::string) => {

	local(string)

	// display prompt
	stdout(#prompt)
	// the following bits wait until the terminal gives you back a line of input
	while(not #string or #string -> size == 0) => {
		#string = file_stdin -> readsomebytes(1024, 1000)
	}
	#string -> replace(bytes('\n'), bytes(''))

	return #string -> asstring
}

local(
	string1,
	string2,
	delimiter
)

// get first string
#string1 = read_input('Enter the first string: ')

// get second string
#string2 = read_input('Enter the second string: ')

// get delimiter
#delimiter = read_input('Enter the delimiter: ')

// deliver the result
stdoutnl(concatenate_with_delimiter(#string1, #string2, #delimiter))

Called from the command line: ./interactive_demo

Result -> Rosetta::Code

Lingo

Lingo/Director is usually started as GUI program and has no access to the standard system console (unless using a binary plugin). But it has its own interactive Lingo console called "Message Window", that can be activated/displayed by executing "_player.debugPlaybackEnabled=1". Using this Message Window, the task can be solved like this:

> m=new(#script)
> m.scripttext="on conc(a,b,c)"&RETURN&"return a&c&c&b"&RETURN&"end"
> put conc("Rosetta", "Code", ":")
-- "Rosetta::Code"

Works with: UCB Logo
$ <i>logo</i>
Welcome to Berkeley Logo version 5.6
? <i>to f :prefix :suffix :separator</i>
> <i>output (word :prefix :separator :separator :suffix)</i>
> <i>end</i>
f defined
? <i>show f "Rosetta "Code ":</i>
Rosetta::Code
?

Lua

$ lua
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> function conc(a, b, c)
>> return a..c..c..b
>> end
> print(conc("Rosetta", "Code", ":"))
Rosetta::Code
>

M2000 Interpreter

M2000 run through an environment (the M2000 Environment), and this can run a script by using command line arguments, or run in interactive mode, just opening the environment, in full screen.

To exit interactive mode just type END and press enter after prompt >, Old commands are back again using arrows up or down. We can open editor for these commands (internal editor has syntax color).

Command line has a some special commands (we need to use Set to send command to this line, from a program), to change many things. Type Help All to see help for all topics, or type Help Print to see help for Print.

We an use ? as a Print command. Any variable, array, module, function, group we make at command line is global.

We can make functions using edit, so edit f$() open editor and we write these

>edit f$()

(we see Function F$() at the header of editor)

Read name1$, name2$, sep$
=name1$+sep$+sep$+name2$

So now we press Esc and return to command line (editor open as a layer, so console has the last state). Using Clipboard we sen unicode string to clipboard

>? f$("Rosseta","Code",":")
Rosseta::Code
>clipboard f$("Rosseta","Code",":")
>New  ' now we clear any stored function/module
>function f$(a$,b$,c$) {=a$+c$+c$+b$}    'in one line function
>? f$("Rosseta","Code",":")
Rosseta::Code
>Save ros1
>New
>Load ros1
>? f$("Rosseta","Code",":")
Rosseta::Code
>New
>f$=Lambda$ (a$,b$,c$)->a$+c$+c$+b$
>? f$("Rosseta","Code",":")
Rosseta::Code
>B$=F$  ' lambda functions as variables.
>? B$("Rosseta","Code",":")
Rosseta::Code

M4

Here is a terminal session with output lines marked by "==>":

$ m4
define(`f',`$1`'$3`'$3`'$2')
==>
f(`Rosetta',`Code',`:')
==>Rosetta::Code
m4exit

Maple

Start Maple's commandline interface by issuing the command maple in a terminal shell. Ie,

$ maple

Then enter the Maple commands.

f := (a,b,c)->cat(a,c,c,b):

f("Rosetta","Code",":");

Output:

                        "Rosetta::Code"

Mathematica / Wolfram Language

$ math
f[x_,y_,z_]:=Print[x,z,z,y]
->""
f["Rosetta","Code",":"]
->Rosetta::Code

MATLAB / Octave

(Has been tested only with MATLAB)

Define an anonymous function in the Command Window

 
>> f = @(str1, str2, delim) [str1, delim, delim, str2];

Call of function and

Output:
>> f('Rosetta', 'Code', ':')

ans =

Rosetta::Code

Maxima

Simply run wxMaxima, xMaxima (or simply maxima in a Linux or Windows command line) to start a REPL.

(%i1) f(a, b, c) := sconcat(a, c, c, b)$
(%i2) f("Rosetta", "Code", ":");
(%o2) "Rosetta::Code"

min

Run the REPL with min -i, otherwise it'll expect a file to run as a script.

Works with: min version 0.27.1
$ (dup suffix swap suffix suffix) :glue
$ "Rosetta" "Code" ":" glue puts!
Rosetta::Code
$

ML/I

The following is exactly what should be fed to ML/I to start a suitable interactive session. Start ML/I with (e.g.: $ ml1), then type:

MCSKIP MT,<>
MCINS %.
MCDEF F WITHS (,,)
AS <%WA1.%WA3.%WA2.%WA2.>

Nanoquery

Unless a program file is provided to run at the command line, the Nanoquery interpreter starts interactively by default.

>nq
[no file | rec1 col1] % def f(a, b, sep)
                        ...     return a + sep + sep + b
                        ... end
[no file | rec1 col1] % println f("Rosetta", "Code", ":")
Rosetta::Code

Nim

Nim is not provided with a REPL but there is several available. Online, it is possible to use Nim playground at https://play.nim-lang.org/. And one can install “inim” with “nimble” (command nimble install inim).

Run the REPL and paste the following code:

proc f(x, y, z: string) = echo x, z, z, y
f("Rosetta", "Code", ":")

which outputs:

Rosetta::Code
Works with: Nim version 0.20.0 or above

Since version 0.20.0 Nim also provides a REPL in its compiler API.

File: repl.nim

import ../compiler/[nimeval, llstream]

runRepl(llStreamOpenStdIn().repl, [findNimStdLibCompileTime()], true)

Usage

nim c repl.nim
repl
.....>>> var a = 1
>>> var b = 2
>>> a + b

3

OCaml

The default interactive interpreter is called the toplevel. In the toplevel because we can enter expressions that span multiple lines, we have to type the double semicolon (";;") at the end of an expression so that it knows we are done.

$ ocaml
        Objective Caml version 3.12.1

# let f s1 s2 sep = String.concat sep [s1; ""; s2];;
val f : string -> string -> string -> string = <fun>
# f "Rosetta" "Code" ":";;
- : string = "Rosetta::Code"
#

Also a lot of OCaml users invoke the toplevel with rlwrap or ledit to gain readline capabilities:

$ rlwrap ocaml

There is also ocamlnat that is a native toplevel. It permits interactive use of the OCaml system through a read-eval-print loop, similar to the standard OCaml toplevel, but up to 100 times faster.
Using a module in the default toplevel is made with .cma files, with ocamlnat just use .cmxs files instead.

Octave

$ octave
GNU Octave, version 3.0.2
Copyright (C) 2008 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type `warranty'.

Octave was configured for "i586-mandriva-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/help-wanted.html

Report bugs to <bug@octave.org> (but first, please read
http://www.octave.org/bugs.html to learn how to write a helpful report).

For information about changes from previous versions, type `news'.

octave:1> function concat(a,b,c)
> disp(strcat(a,c,c,b));
> endfunction
octave:2> concat("Rosetta","Code",":");
Rosetta::Code
octave:3>

Oforth

Oforth interpreter is started using --i command line parameter :

oforth --i

Into the interpreter, you can create functions :

: x(a, b, sep)   a sep + sep + b + ;
ok
>x("Rosetta", "Code", ":")
ok
>.s
[1] (String) Rosetta::Code
ok
>

Alternatively you don't need the local variables

 > : x   dup rot + + + ;
ok
> "Rosetta" "Code" ";" x .s
[1] (String) Rosetta::Code
ok
>

Ol

Ol comes with builtin REPL. Interactive web-based example can be found at the Ol project page.

$ ol
Welcome to Otus Lisp 2.1-2282-27a9b6c
type ',help' to help, ',quit' to end session.
> (define (f head tail mid)
     (string-append head mid mid tail))
;; Defined f
> (f "Rosetta" "Code" ":")
"Rosetta::Code"
> ,quit
bye-bye :/

ooRexx

ooRexx ships a program rexxtry.rex which does exactly what this task asks for.

Output:
D:\>rexx rexxtry ?
 This procedure lets you interactively try REXX statements.
 If you run it with no parameter, or with a question mark
 as a parameter, it will briefly describe itself.
 You may also enter a REXX statement directly on the command line
 for immediate execution and exit.  Example:  rexxtry call show

 Enter 'call show' to see user variables provided by REXXTRY.
 Enter '=' to repeat your previous statement.
 Enter '?' to invoke system-provided online help for REXX.
 The subroutine named 'sub' can be CALLed or invoked as 'sub()'.
 REXXTRY can be run recursively with CALL.

 Except for the signal instructions after a syntax error, this
 procedure is an example of structured programming.

D:\>rexx rexxtry
REXX-ooRexx_4.2.0(MT)_64-bit 6.04 22 Feb 2014
  rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
  Go on - try a few...            Enter 'exit' to end.
x=3
  ........................................... rexxtry.rex on WindowsNT
y=x**2
  ........................................... rexxtry.rex on WindowsNT
say x y
3 9
  ........................................... rexxtry.rex on WindowsNT

  rexxtry.rex:  Enter 'exit' to end.       Or '?' for online REXX help.
say sigl
160
  ........................................... rexxtry.rex on WindowsNT
say sourceline(12)
/* Redistribution and use in source and binary forms, with or                 */
  ........................................... rexxtry.rex on WindowsNT  
exit

D:\>

For the specific test I need to create the function on my disk

H:\>rexx rexxtry
REXX-ooRexx_4.2.0(MT)_64-bit 6.04 22 Feb 2014
  rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
  Go on - try a few...            Enter 'exit' to end.
pgm='ff.rex'; Call lineout pgm,'return arg(1)||arg(3)||arg(3)||arg(2)';Call line
out pgm
  ........................................... rexxtry.rex on WindowsNT
say ff('AAA','BBB',':')
AAA::BBB
  ........................................... rexxtry.rex on WindowsNT
exit

Oz

Mozart supports this style of programming with its Emacs interface. Go to the "Oz" buffer and enter

declare fun {F As Bs Sep} {Append As Sep|Sep|Bs} end

Press C-. C-l to evaluate the line.

Now enter

{System.showInfo {F "Rosetta" "Code" &:}}

and again press C-. C-l to execute the code. You will see the result in the "*Oz Emulator*" buffer.

PARI/GP

gp *is* a REPL built on the PARI library. You can start it from the command line with gp, though you may wish to change to your Pari directory first so it can read your .gprc file. Alternatively, if you are using a GUI, double-click the shortcut.

f(s1,s2,sep)=Str(s1, sep, sep, s2);

Perl

Perl doesn't have an interpreter, but there is an interactive debugger:

$ perl -de1

Loading DB routines from perl5db.pl version 1.3
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1):   1
  DB<1> sub f {my ($s1, $s2, $sep) = @_; $s1 . $sep . $sep . $s2}

  DB<2> p f('Rosetta', 'Code', ':')
Rosetta::Code
  DB<3> q

Alternative way:

$ perl
# Write the script here and press Ctrl+D plus ENTER when finished (^D means Ctrl+D):
sub f {my ($s1, $s2, $sep) = @_; $s1 . $sep . $sep . $s2};
print f('Rosetta', 'Code', ':');
^D
Rosetta::Code
$

Another:

$ perl -lpe '$_=eval||$@'
sub f { join '' => @_[0, 2, 2, 1] }

f qw/Rosetta Code :/
Rosetta::Code

Phix

The repl has been significantly improved for version 0.8.4+ so it is now usable, although not thoroughly tested or widely used yet.

C:\Program Files (x86)\Phix>p -repl
Warning: the repl is brand new, experimental, incomplete, and liable to crash!
Enter a statement such as "?remainder(floor(250/8),8)" or "puts(1,"Hi")"

>function f(string a,b,c) return a&c&c&b end function

>?f("Rosetta","Code",":")
"Rosetta::Code"

>quit
C:\Program Files (x86)\Phix>

Picat

cl enters the interactive console mode. Exit with Ctrl-d on Unix and Ctrl-z on Windows.

Picat> cl
f(X,Y,Sep) = X ++ [Sep,Sep] ++ Y.
<Ctrl-D>
Picat> print(f("Rosetta","Code",':'))             
Rosetta::Code
yes

PicoLisp

$ pil +
: (de f (Str1 Str2 Sep)
   (pack Str1 Sep Sep Str2) )
-> f

: (f "Rosetta" "Code" ":")
-> "Rosetta::Code"

Pike

$ pike
Pike v7.8 release 352 running Hilfe v3.5 (Incremental Pike Frontend)
> string f(string first, string second, string sep){
>>   return(first + sep + sep + second);
>> }
> f("Rosetta","Code",":");
(1) Result: "Rosetta::Code"
>

PowerShell

PowerShell itself is already a shell and therefore an interactive environment is the default.

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS Home:\> function f ([string] $string1, [string] $string2, [string] $separator) {
>>     $string1 + $separator * 2 + $string2
>> }
>>
PS Home:\> f 'Rosetta' 'Code' ':'
Rosetta::Code
PS Home:\>

Prolog

Works with SWI-Prolog.
Prolog works in its own environnment.
Start the interpreter by typing pl at the command line (or by clicking on the exe).

% library(win_menu) compiled into win_menu 0.00 sec, 12,872 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,404 bytes
% The graphical front-end will be used for subsequent tracing
% c:/users/joel-seven/appdata/roaming/swi-prolog/pl.ini compiled 0.13 sec, 876,172 bytes
XPCE 6.6.66, July 2009 for Win32: NT,2000,XP
Copyright (C) 1993-2009 University of Amsterdam.
XPCE comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
The host-language is SWI-Prolog version 5.10.0

For HELP on prolog, please type help. or apropos(topic).
         on xpce, please type manpce.

1 ?- assert((f(A, B,C) :- format('~w~w~w~w~n', [A, C, C, B]))).
true.

2 ?- f('Rosetta', 'Code', ':').
Rosetta::Code
true.

3 ?-

Python

Start the interpreter by typing python at the command line (or select it from a menu). You get a response showing the version of the interpreter being run before giving an input prompt of three greater-than characters and a space:

python
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(string1, string2, separator):
	return separator.join([string1, '', string2])

>>> f('Rosetta', 'Code', ':')
'Rosetta::Code'
>>>

Quackery

The Quackery shell (REPL) can be invoked from the command line by invoking quackery without specifying a Quackery source file. The shell can be invoked from within a Quackery source file with the Quackery word shell. As the shell is nestable it can also be invoked from within the shell.

Output:

Invoking the shell first from the command line and then within the shell, and leaving first the nested shell then the outer shell.

 > quackery

Welcome to Quackery.

Enter "leave" to leave the shell.

/O> say " now entering a nested shell..."
... shell
... 
 now entering a nested shell...
/O> say " now leaving the nested shell"
... leave
... 
 now leaving the nested shell
Auf wiedersehen.


Stack empty.

/O> say " now leaving the shell invoked at the command line"
... leave
... 
 now leaving the shell invoked at the command line
Goodbye.


 > echo " back at the command line"
 back at the command line
 >

The task:

$ quackery

Welcome to Quackery.

Enter "leave" to leave the shell.

/O> [ dup join swap join join ] is f ( [ [ [ --> [ )
...

Stack empty.

/O> $ 'Rosetta' $ 'Code' $ ':' f
...

Stack: [ 82 111 115 101 116 116 97 58 58 67 111 100 101 ]

/O> echo$
...
Rosetta::Code
Stack empty.

/O>

R

$ R

R version 2.7.2 (2008-08-25)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> f <- function(a, b, s) paste(a, "", b, sep=s)
> f("Rosetta", "Code", ":")
[1] "Rosetta::Code"
> q()
Save workspace image? [y/n/c]: n

Racket

Much like Scheme, Racket features a full-featured REPL:

oiseau:/tmp> racket
Welcome to Racket v5.3.3.5.
> (define (f string-1 string-2 separator)
    (string-append string-1 separator separator string-2))
> (f "Rosetta" "Code" ":")
"Rosetta::Code"
> ^D
oiseau:/tmp>

Raku

(formerly Perl 6) Using Rakudo.

$ rakudo/perl6
> sub f($str1,$str2,$sep) { $str1~$sep x 2~$str2 };
f
> f("Rosetta","Code",":");
Rosetta::Code
>

REBOL

Start the REBOL/Core interpreter in quiet mode with -q. q to quit.

$ rebol -q
>> f: func [a b s] [print rejoin [a s s b]]
>> f "Rosetta" "Code" ":"
Rosetta::Code
>> q

Retro

Retro's interpreter is started automatically. Once you see the "ok" prompt, you can proceed to enter code:

:f (sss-s) [ s:prepend ] sip s:prepend s:append ;
'Rosetta 'Code ': f

REXX

version 1

/*REXX*/  parse arg a b c
say f(a,b,c)
exit
f:return arg(1)arg(3)arg(3)arg(2)

version 2

This REXX version allows blanks to be included in the three strings.

/*REXX program demonstrates  interactive programming  by using a  function [F].         */
say f('Rosetta',  "Code",  ':')
say f('The definition of a trivial program is ',  " one that has no bugs.",  '───')
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
f:  return arg(1) || copies(arg(3),2) || arg(2)  /*return the required string to invoker*/

output   when using the (internal) default strings:

Rosetta::Code
The definition of a trivial program is ────── one that has no bugs.

version 3

This REXX version is more to the keeping of the spirit of the task requirements.

/*REXX program demonstrates  interactive programming  by using a  function [F].         */
say '══════════════════ enter the function  F  with three comma-separated arguments:'
parse pull funky
interpret  'SAY'  funky
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
f:  return arg(1) || copies(arg(3),2) || arg(2)  /*return the required string to invoker*/

output (a screen scraping is shown)

int_act3 is the name of the REXX program [INT_ACT3.REX)

─────────────────────────────────────────────────────────Thu 10/18/2012 15:00:01
C:\►int_act3
══════════════════ enter the function  F  with three comma-separated arguments:
f("what the",  "hey",  "--")             ◄■■■■■■■■■■■■ this is what the user entered.
what the----hey

─────────────────────────────────────────────────────────Thu 10/18/2012 15:00:38
C:\►

Note that the timestamp and the C:\► text is part of my (wrapped) two-line prompt message.

Ring

r = "Rosetta"
c = "Code"
s = ":"
see r+s+s+c

Output:

Rosetta::Code

RPL

RPL command-line interpreter is permanently running. Each created function can be called by its name, the same way as built-in instructions, without any prefix.

≪ "::" SWAP + + ≫ ‘FUNC’ STO
"Rosetta" "Code" FUNC
Output:
1: "Rosetta::Code"

Ruby

The read-eval-print loop (REPL) for Ruby is irb, the interactive ruby shell.

Start the interpreter by typing irb at the command line. You will see an input prompt, which by default is name of this program(name of main object):line number:indent level> :

$ irb
irb(main):001:0> def f(string1, string2, separator)
irb(main):002:1>     [string1, '', string2].join(separator)
irb(main):003:1> end
=> :f
irb(main):004:0> f('Rosetta', 'Code', ':')
=> "Rosetta::Code"
irb(main):005:0> exit
$

Rust

This method use the crate clap: clap is used to parse and validate the string of command line arguments provided by the user at runtime. You provide the list of valid possibilities, and clap handles the rest. This means you focus on your applications functionality, and less on the parsing and validating of arguments. One of clap configurations is a mathod used a YAML file to build the CLI and keep the Rust source tidy or support multiple localized translations by having different YAML files for each localization. - First, create the cli.yaml file to hold the CLI options, but it could be called anything we like:

name: myapp
version: "1.0"
author: A Rust Developer <rustme@home.com>
about: Does awesome things
args:
  - STRING1:
      about: First string to use
      required: true
      index: 1
  - STRING2:
      about: Second string to use
      required: true
      index: 2
  - SEPARATOR:
      about: Separtor to use
      required: true
      index: 3

- Then, simply add clap the yaml feature flag to your Cargo.toml.

[dependencies]
clap = { version = "3.0.0-beta.2", features = ["yaml"] }

- Enter this code in Rust source file

#[macro_use]
extern crate clap;
use clap::App;
fn main() {
    let yaml = load_yaml!("cli.yaml");
    let matches = App::from(yaml).get_matches();

    let str1 = matches.value_of("STRING1").unwrap();
    let str2 = matches.value_of("STRING2").unwrap();
    let str3 = matches.value_of("SEPARATOR").unwrap();

    println!("{:?}", f(&str1, &str2, &str3));
}

fn f<'a>(s1: &'a str, s2: &'a str, sep :&'a str) -> String{
    [s1,sep,sep,s2].iter().map(|x| *x).collect()
}

Output:

Rosetta::Code

S-lang

S-Lang includes a general-purpose shell called slsh. Command-line arguments are available with:

   slsh --help

Without any arguments it starts from the command-line in [REPL] command-mode:

> slsh<Enter>
slsh version 0.9.1-2; S-Lang version: pre2.3.1-23
Copyright (C) 2005-2014 John E. Davis <jed@jedsoft.org>
This is free software with ABSOLUTELY NO WARRANTY.

slsh> define f(s1, s2, sep) {<Enter>
       return(strcat(s1, sep, sep, s2));<Enter>
       }<Enter>
slsh> f("Rosetta", "Code", ":");<Enter>
Rosetta::Code
slsh> quit<Enter>
>

Scala

Scala has a REPL -- Read, Evaluate & Print Loop. Being a compiled language, everything you type is encapsulated into a compilable template, compiled, executed, and the return value assigned to a special variable and displayed.

One invokes the REPL by just typing "scala", which is either a shell script or a batch file depending on one's operating system:

C:\>scala
Welcome to Scala version 2.8.0.r21356-b20100407020120 (Java HotSpot(TM) Client V
M, Java 1.6.0_05).
Type in expressions to have them evaluated.
Type :help for more information.

scala> "rosetta"
res0: java.lang.String = rosetta

Scala's REPL, starting with version 2.8, offers both auto-completion and alternatives when typing TAB. For instance, to check what methods are available on a String, one may do the following:

scala> "rosetta".

!=                    ##                    $asInstanceOf
$isInstanceOf         +                     ==
charAt                clone                 codePointAt
codePointBefore       codePointCount        compareTo
compareToIgnoreCase   concat                contains
contentEquals         endsWith              eq
equals                equalsIgnoreCase      finalize
getBytes              getChars              getClass
hashCode              indexOf               intern
isEmpty               lastIndexOf           length
matches               ne                    notify
notifyAll             offsetByCodePoints    regionMatches
replace               replaceAll            replaceFirst
split                 startsWith            subSequence
substring             synchronized          this
toCharArray           toLowerCase           toString
toUpperCase           trim                  wait

scala> "rosetta".+(":")
res1: java.lang.String = rosetta:

One can use `object`, `class`, `trait`, `case object`, `case class`, `def`, `val` and `var` definitions at any point. However, `package` and `package object` definitions are not allowed.

scala> val str1 = "rosetta"
str1: java.lang.String = rosetta

Using these features, one can build the code for a method by testing it part of it individually:

scala> val str2 = "code"
str2: java.lang.String = code

scala> val separator = ":"
separator: java.lang.String = :

scala> str1 + separator + str2
res2: java.lang.String = rosetta:code

If one makes a mistake, the REPL will print an error message, and display the point at which the mistake was made.

scala> def (str1: String, str2: String, separator: String) =
<console>:1: error: identifier expected but '(' found.
       def (str1: String, str2: String, separator: String) =
           ^

If a definition takes more than a line, the REPL will print an indented "|" sign, and wait for more input. If one wishes to abort a definition, just enter two consecutive empty lines.

scala> def f(str1: String, str2: String, separator: String) =
     | str1 + separator + str2
f: (str1: String,str2: String,separator: String)java.lang.String

scala> f("rosetta", "code", ":")
res3: java.lang.String = rosetta:code

scala> f("code", "rosetta", ", ")
res4: java.lang.String = code, rosetta

Also starting with version 2.8, a line starting with a dot will be interpreted as a method call on the last result produced.

scala> .length
res5: Int = 13

scala>

The results are actually displayed with a special function, which pretty prints some results, and avoid eagerly evaluating others, where that could cause problems (such as infinite collections).

scala> Array(1, 2, 3, 4)
res8: Array[Int] = Array(1, 2, 3, 4)

scala> println(res8)
[I@383244

There are many other features, such as the ability to add new jars to the class path, executing commands on the shell, retrieving the last exception thrown, etc.

Scheme

Several interpreters exist for Scheme. These are just some examples.

> scheme
Scheme Microcode Version 14.9
MIT Scheme running under FreeBSD
Type `^C' (control-C) followed by `H' to obtain information about interrupts.
Scheme saved on Monday June 17, 2002 at 10:03:44 PM
  Release 7.7.1
  Microcode 14.9
  Runtime 15.1

1 ]=> (define (f string-1 string-2 separator)
        (string-append string-1 separator separator string-2))

;Value: f

1 ]=> (f "Rosetta" "Code" ":")

;Value 1: "Rosetta::Code"

1 ]=> ^D
End of input stream reached
Happy Happy Joy Joy.
>
> scheme48
Welcome to Scheme 48 1.8 (made by root on Wed Sep 24 22:37:08 UTC 2008)
Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees.
Please report bugs to scheme-48-bugs@s48.org.
Get more information at http://www.s48.org/.
Type ,? (comma question-mark) for help.
> (define (f string-1 string-2 separator)
    (string-append string-1 separator separator string-2))
; no values returned
> (f "Rosetta" "Code" ":")
"Rosetta::Code"
> ^D
Exit Scheme 48 (y/n)? ^D
I'll only ask another 100 times.
Exit Scheme 48 (y/n)? ^D
I'll only ask another 99 times.
Exit Scheme 48 (y/n)? y
>

Sidef

$ sidef -i
>>> func f(s1, s2, sep) { s1 + sep*2 + s2 };
f
>>> f('Rosetta', 'Code', ':')
"Rosetta::Code"
>>>

Slate

slate[1]> s@(String traits) rosettaWith: s2@(String traits) and: s3@(String traits) [s ; s3 ; s3 ; s2].
[rosettaWith:and:]
slate[2]> 'Rosetta' rosettaWith: 'Code' and: ':'.
'Rosetta::Code'

Smalltalk

Works with: GNU Smalltalk
$ gst
GNU Smalltalk ready

st> |concat|
st> concat := [ :a :b :c | (a,c,c,b) displayNl ].
a BlockClosure
st> concat value: 'Rosetta' value: 'Code' value: ':'.
Rosetta::Code
'Rosetta::Code'
st>
Works with: Smalltalk/X
$ stx --repl
Welcome...

STX> |concat|\
concat := [ :a :b :c | (a,c,c,b) displayNl ].\
concat value: 'Rosetta' value: 'Code' value: ':'.
Rosetta::Code
-> (Answer): 'Rosetta::Code'
STX>

SNOBOL4

Works with: Macro Spitbol
>spitbol code
SPITBOL-386   Release 3.7(ver 1.30.20)   Serial xxxxx
...
Enter SPITBOL statements:
? define('f(a,b,s)'):(z);f f = a s s b:(return);z
Success
?= f('Rosetta','Code',':')
Rosetta::Code
Success
?end
>

Standard ML

Works with: SML/NJ

Because you can enter expressions that span multiple lines, you have to type the semicolon (";") at the end so that it knows you are done.

$ sml
Standard ML of New Jersey v110.67 [built: Fri Jul  4 09:00:58 2008]
- fun f (s1, s2, sep) = String.concatWith sep [s1, "", s2];
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val f = fn : string * string * string -> string
- f ("Rosetta", "Code", ":");
val it = "Rosetta::Code" : string
-

Tcl

$ tclsh
% proc f {s1 s2 sep} {
    append result $s1 $sep $sep $s2
}
% f Rosetta Code :
Rosetta::Code
% exit

A simple alternative (one-liners are most convenient in an interactive shell):

$ tclsh
% proc f {a b s} {join [list $a "" $b] $s}
% f Rosetta Code :
Rosetta::Code
%

TI-89 BASIC

To switch to the interpreter ("home screen"), press the HOME key.

■ x & s & s & y → f(x,y,s)
                                  Done
■ f("Rosetta", "Code", ":")
                       "Rosetta::Code"

Input is left-aligned, output is right-aligned. “→” is typed by pressing STO▸, and “&” by pressing ◆ ×. All whitespace is optional.

UNIX Shell

Works with: Bourne Shell
$ sh
sh-3.2$ concat() { echo "$1$3$3$2"; }
sh-3.2$ concat Rosetta Code :
Rosetta::Code
sh-3.2$

C Shell

$ csh -f
% alias concat 'echo "\!:1\!:3\!:3\!:2"'
% concat Rosetta Code :
Rosetta::Code
%

es

$ es
; fn concat a b s { result $a$s$s$b }
; echo <={concat Rosetta Code :} 
Rosetta::Code
;

Ursa

$ java -jar ursa.jar
cygnus/x ursa v0.76 (default, release 1)
[Oracle Corporation JVM 1.8.0_91 on Linux 3.16.0-4-686-pae i386]
> def f (string s1, string s2, string sep)
..	return (+ s1 sep sep s2)
..end 
> out (f "Rosetta" "Code" ":") endl console
Rosetta::Code
> _

Vedit macro language

To enter command mode, type <Esc>c, or to open command mode window, type <Esc>w. Or if the command mode window is already open, just click on the window.

To define a macro in text register 100:

RS(100, "RS(10, @1) RS(10, @3, APPEND) RS(10, @3, APPEND) RS(10, @2, APPEND)")

To call the macro:

RS(1,"Rosetta") RS(2,"Code") RS(3,":") Call(100)
Message(@10)

XLISP

How to start a REPL depends on the operating system.

XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz
[1] (defun f (a b sep)
        (string-append a sep sep b))

F
[2] (f "Rosetta" "Code" ":")

"Rosetta::Code"
[3]

Wren

If one runs Wren's command line interpreter without passing it any arguments, then it starts the interpreter in interactive mode. This mode can be exited by pressing Ctrl-C or Ctrl-D.

$ ./wren
\\/"-
 \_/   wren v0.4.0
> var f = Fn.new { |s1, s2, sep| s1 + sep + sep + s2 }
> f.call("Rosetta", "Code", ":")
Rosetta::Code
> 
^C
$ 

zkl

$ zkl
zkl 1.12.8, released 2014-04-01
zkl: fcn f(a,b,c){String(a,c,c,b)}
Void
zkl: f("Rosetta", "Code", ":")
Rosetta::Code
zkl: