2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,7 +1,22 @@
|
|||
Many language implementations come with an ''interactive mode''. This is a [[wp:command-line interpreter|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 ''[[wp:read-eval-print loop|read-eval-print loop]]'' (REPL), or a ''shell''.
|
||||
Many language implementations come with an ''interactive mode''.
|
||||
|
||||
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.
|
||||
This is a [[wp:command-line interpreter|command-line interpreter]] that reads lines from the user and evaluates these lines as statements or expressions.
|
||||
|
||||
For example, <tt>f('Rosetta', 'Code', ':')</tt> should return <tt>'Rosetta::Code'</tt>
|
||||
An interactive mode may also be known as a ''command mode'', a ''[[wp:read-eval-print loop|read-eval-print loop]]'' (REPL), or a ''shell''.
|
||||
|
||||
Note: this task is not about creating your own interactive mode.
|
||||
|
||||
;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 3<sup>rd</sup> argument).
|
||||
|
||||
|
||||
;Example:
|
||||
<big> f('Rosetta', 'Code', ':') </big>
|
||||
should return
|
||||
<big> 'Rosetta::Code' </big>
|
||||
|
||||
|
||||
;Note:
|
||||
This task is ''not'' about creating your own interactive mode.
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
iex(1)> f = fn str1,str2,sep -> [str1,"",str2] |> Enum.join(sep) end # Join list on seperator
|
||||
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,7 +3,7 @@ package main
|
|||
import "fmt"
|
||||
|
||||
func f(s1, s2, sep string) string {
|
||||
return s1+sep+sep+s2
|
||||
return s1 + sep + sep + s2
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
$ rebol -q
|
||||
>> f: func [a b s] [print rejoin [a s s b]]
|
||||
>> f "Rosetta" "Code" ":"
|
||||
Rosetta::Code
|
||||
>> q
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
/*REXX program to show 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 done.*/
|
||||
|
||||
/*──────────────────────────────────F subroutine────────────────────────*/
|
||||
f: return arg(1) || copies(arg(3),2) || arg(2) /*return required str.*/
|
||||
/*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*/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*REXX program to show interactive programming by using a function [F]. */
|
||||
say '══════════════════ enter the function F with three arguments:'
|
||||
/*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 done.*/
|
||||
/*──────────────────────────────────F subroutine────────────────────────*/
|
||||
f: return arg(1) || copies(arg(3),2) || arg(2) /*return required str.*/
|
||||
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*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
> 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>
|
||||
>
|
||||
Loading…
Add table
Add a link
Reference in a new issue