The Name Game: Difference between revisions
→{{header|EasyLang}}
(Added XPL0 example.) |
|||
(12 intermediate revisions by 6 users not shown) | |||
Line 184:
)
</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">nameGame: function [Name][
L: take Name 1
name: lower Name
unless in? L "AEIOU" -> drop 'name
[B F M]: ["b" "f" "m"]
if L="B" -> B: ""
if L="F" -> F: ""
if L="M" -> M: ""
~{
|Name|, |Name|, bo-|B||name|
Banana-fana fo-|F||name|
Fee-fi-mo-|M||name|
|Name|!
}
]
["Gary" "Earl" "Billy" "Felicia" "Marissa" "Sarah"]
| map => nameGame
| loop => [print & ++ "\n"]</syntaxhighlight>
{{out}}
<pre>Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
Felicia, Felicia, bo-belicia
Banana-fana fo-elicia
Fee-fi-mo-melicia
Felicia!
Marissa, Marissa, bo-barissa
Banana-fana fo-farissa
Fee-fi-mo-arissa
Marissa!
Sarah, Sarah, bo-barah
Banana-fana fo-farah
Fee-fi-mo-marah
Sarah!</pre>
=={{header|AutoHotkey}}==
Line 742 ⟶ 788:
}
}</syntaxhighlight>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
function WaitForString(Memo: TMemo; Prompt: string): string;
{Wait for key stroke on TMemo component}
var KW: TKeyWaiter;
begin
{Use custom object to wait and capture key strokes}
KW:=TKeyWaiter.Create(Memo);
try
Memo.Lines.Add(Prompt);
Memo.SelStart:=Memo.SelStart-1;
Memo.SetFocus;
Result:=KW.WaitForString;
finally KW.Free; end;
end;
procedure NameGame(Memo: TMemo);
var Name: string;
var Str2: string;
var FL: Char;
function GetPattern: string;
var BStr,FStr,MStr: string;
begin
if FL='b' then BStr:='bo-' else BStr:='bo-b';
if FL='f' then FStr:='fo-' else FStr:='fo-f';
if FL='m' then MStr:='mo-' else MStr:='mo-m';
Result:=Format('%S, %S, %S%S',[Name,Name,BStr,Str2])+CRLF;
Result:=Result+Format('Banana-fana %S%S',[FStr,Str2])+CRLF;
Result:=Result+Format('Fee-fi-%S%S',[MStr,Str2])+CRLF;
Result:=Result+Format('%S!',[Name])+CRLF;
end;
begin
while true do
begin
Name:=WaitForString(Memo,'Enter a name: ');
if Name='' then break;
Str2:=LowerCase(Name);
FL:=Str2[1];
if not (FL in ['a','e','i','o','u']) then Delete(Str2,1,1);
Memo.Lines.Add(GetPattern);
end;
end;
</syntaxhighlight>
{{out}}
<pre>
Enter a name:
Gary
Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!
Enter a name:
Earl
Earl, Earl, bo-bearl
Banana-fana fo-fearl
Fee-fi-mo-mearl
Earl!
Enter a name:
Billy
Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
Enter a name:
Felix
Felix, Felix, bo-belix
Banana-fana fo-elix
Fee-fi-mo-melix
Felix!
Enter a name:
Mary
Mary, Mary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-ary
Mary!
Enter a name:
Elapsed Time: 01:18.249 min
</pre>
=={{header|Dyalect}}==
Line 798 ⟶ 946:
=={{header|EasyLang}}==
<syntaxhighlight>
proc verse x$ . .
x1$ = substr x$ 1 1
y$ = substr x$ 2 99
if strpos "AEIOU" x1$ <> 0
.
b$ = "b" & y$
f$ = "f" & y$
elif x1$ =
elif x1$ = "M"
m$ = y$
.
print x$ & ", " & x$ & ", bo-" & b$
print "Banana-fana fo-" & f$
print "Fee-fi-mo-" & m$
print x$ & "!"
.
for n$ in [ "Gary" "Earl" "Billy" "Felix" "Mary" ]
verse n$
print ""
.
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
Line 1,086 ⟶ 1,167:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/The_Name_Game}}
'''Solution'''
[[File:Fōrmulæ - The Name Game 01.png]]
'''Test cases'''
[[File:Fōrmulæ - The Name Game 02.png]]
[[File:Fōrmulæ - The Name Game 03.png]]
=={{header|Go}}==
Line 2,569 ⟶ 2,656:
Extra code was added to the REXX program to capitalize the name (and lowercase all characters in the name except the 1<sup>st</sup> character).
<br>Also, dual names are supported (like Mary Ann).
<syntaxhighlight lang="rexx">/*REXX program displays the
/* 20230526 Walter Pachl refurbished Gerald Schildberger's original program */
Parse Arg namelist /*obtain optional argument(s) from C.L.*/
If namelist='' Then /*Not specified?
namelist="gAry, eARL, billy, FeLix,
Do While namelist>''
namelist=space(namelist) /*elide superfluous blanks from list. */
Parse Var namelist name',' namelist /*get name (could be 2 words) from list*/
call song name /*invoke subroutine to display lyrics. */
End
Exit /*stick a fork in it, we're all Done. */
/*---------------------------------------------------------------------------------*/
song:
Parse Arg name
Parse Value 'b f m' With bb ff
lowercase='abcdefghijklmnopqrstuvwxyz' /*build 2 alphabets*/
uppercase=translate(lowercase)
name =translate(left(name,1),uppercase,lowercase)||,
translate(substr(name,2),lowercase,uppercase)
namel=translate(name,lowercase,uppercase)
Parse Var name first +1 rest
Select
When pos(first,'AEIOU')>0 Then Do
Say name',' name", bo-b"namel
Say 'Banana-fana fo-f'namel
Say 'Fee-fi-mo-m'namel
End
When pos(first,'BFM')>0 Then Do
Select
When first=='B' Then
When first=='F' Then ff=''
When first=='M' Then mm=''
End
Say name',' name', bo-'bb||rest
Say 'Banana-fana fo-'ff||rest
Say 'Fee-fi-mo-'mm||rest
End
Otherwise Do
Say name',' name', bo-b'rest
Say 'Banana-fana fo-f'rest
Say 'Fee-fi-mo-m'rest
End
End /*select*/
Say name'!'
Say ''
Return
</syntaxhighlight>
{{out|output|text= when using the default (internal) names:}}
<pre>
Line 3,008 ⟶ 3,110:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="
var printVerse = Fn.new { |name|
|