Abbreviations, easy: Difference between revisions
Added FreeBASIC
(→{{header|Picat}}: Adding Picat) |
(Added FreeBASIC) |
||
(14 intermediate revisions by 7 users not shown) | |||
Line 87:
{{trans|Python}}
<
|‘Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 130:
print(‘user words: ’user_words)
print(‘full words: ’full_words)</
{{out}}
Line 140:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program abbrEasy64.s */
Line 562:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
<pre>
Enter command (or quit to stop) : riG
Line 590:
=={{header|Ada}}==
<
with Ada.Containers.Indefinite_Vectors;
with Ada.Strings.Fixed;
Line 687:
Put_Match ("");
Put_Match ("o");
end Abbreviations_Easy;</
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68G specific is lower and to upper procedures. Does not use a hash table.
<
# table of "commands" - upper-case indicates the mminimum abbreviation #
STRING command table = "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy "
Line 776:
# task test cases #
test expand( "riG rePEAT copies put mo rest types fup. 6 poweRin", command table );
test expand( "", command table )</
{{out}}
<pre>
Line 798:
<pre> Correction program 15/11/2020 </pre>
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program abbrEasy.s */
Line 1,186:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
<pre>
Line 1,214:
=={{header|AutoHotkey}}==
<
str =
(
Line 1,258:
}
MsgBox % Trim(result)
</syntaxhighlight>
{{out}}
<pre>
Line 1,266:
=={{header|AWK}}==
<
BEGIN {
FS=" ";
Line 1,305:
</syntaxhighlight>
{{out}}
Line 1,314:
=={{header|C}}==
<
#include <stdbool.h>
#include <stdio.h>
Line 1,460:
free_command_list(commands);
return 0;
}</
{{out}}
Line 1,469:
=={{header|C++}}==
<
#include <cctype>
#include <iostream>
Line 1,571:
std::cout << "output: " << output << '\n';
return 0;
}</
{{out}}
Line 1,581:
=={{header|Clojure}}==
<
(defn words [str]
"Split string into words"
Line 1,626:
;; Example Input
(print (solution "riG rePEAT copies put mo rest types fup. 6 poweRin"))
</syntaxhighlight>
{{out}}
Line 1,636:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Abbreviations_Easy;
Line 1,715:
Writeln(string.Join(' ', results));
Readln;
end.</
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
include std/text.e -- for upper conversion
include std/console.e -- for display
Line 1,753:
return flatten(join(results," ")) -- convert sequence of strings into one string, words separated by a single space;
end function
</syntaxhighlight>
{{out}}
<pre>
Line 1,761:
=={{header|Factor}}==
<
literals math qw sequences sequences.extras splitting.extras ;
IN: rosetta-code.abbreviations-easy
Line 1,813:
: main ( -- ) user-input "" [ .abbr ] bi@ ;
MAIN: main</
{{out}}
<pre>
Line 1,821:
Full words:
</pre>
=={{header|FreeBASIC}}==
{{trans|ALGOL 68}}
<syntaxhighlight lang="vbnet">Dim As String table = "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy " _
+ "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find " _
+ "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput " _
+ "Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO " _
+ "MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT " _
+ "READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT " _
+ "RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up"
Function NextWord(Byref posic As Integer, text As String) As String
' skip spaces
While posic <= Len(text) And Mid(text, posic, 1) = " "
posic += 1
Wend
' get the word
Dim word As String = ""
While posic <= Len(text) And Mid(text, posic, 1) <> " "
word += Mid(text, posic, 1)
posic += 1
Wend
Return word
End Function
Function MinABLength(comando As String) As Integer
Dim ab_min As Integer = 1
While ab_min <= Len(comando) And Ucase(Mid(comando, ab_min, 1)) = Mid(comando, ab_min, 1)
ab_min += 1
Wend
Return ab_min - 1
End Function
Function Expand(table As String, word As String) As String
If Len(word) = 0 Then
Return ""
Else
Dim As Integer word_len = Len(word)
Dim As String result = "*error*"
Dim As Integer posic = 1
Do
Dim As String comando = NextWord(posic, table)
If Len(comando) = 0 Then
Exit Do
Elseif word_len < MinABLength(comando) Or word_len > Len(comando) Then
Continue Do
Elseif Ucase(word) = Ucase(Left(comando, word_len)) Then
result = Ucase(comando)
Exit Do
End If
Loop
Return result
End If
End Function
Sub TestExpand(words As String, table As String)
Dim As String word, results = "", separator = ""
Dim As Integer posic = 1
Do
word = NextWord(posic, words)
If Len(word) = 0 Then Exit Do
results += separator + Expand(table, word)
separator = " "
Loop
Print "Input: "; words
Print "Output: "; results
End Sub
' task test cases
TestExpand("riG rePEAT copies put mo rest types fup. 6 poweRin", table)
TestExpand("", table)
Sleep</syntaxhighlight>
{{out}}
<pre>Same as ALGOL 68 entry.</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_userStringFld
_validateBtn
_resultsStringFld
end enum
void local fn BuildWindow
window _window, @"Abbreviations, easy", (0,0,600,268)
WindowSetContentMinSize( _window, fn CGSizeMake( 200, 268 ) )
WindowSetContentMaxSize( _window, fn CGSizeMake( 10000, 268 ) )
textfield _userStringFld,, @"riG rePEAT copies put mo rest types fup. 6 poweRin", (20,152,560,96)
TextFieldSetPlaceholderString( _userStringFld, @"Enter commands" )
ViewSetAutoresizingMask( _userStringFld, NSViewWidthSizable )
button _validateBtn,,, @"Validate", (259,117,83,32)
ViewSetAutoresizingMask( _validateBtn, NSViewMinXMargin + NSViewMaxXMargin )
textfield _resultsStringFld,,, (20,20,560,96)
TextFieldSetEditable( _resultsStringFld, NO )
TextFieldSetSelectable( _resultsStringFld, YES )
ViewSetAutoresizingMask( _resultsStringFld, NSViewWidthSizable )
end fn
local fn Commands as CFArrayRef
CFStringRef words = @"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy "
words = fn StringByAppendingString( words, @"COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find " )
words = fn StringByAppendingString( words, @"NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput " )
words = fn StringByAppendingString( words, @"Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO " )
words = fn StringByAppendingString( words, @"MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT " )
words = fn StringByAppendingString( words, @"READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT " )
words = fn StringByAppendingString( words, @"RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up" )
end fn = fn StringComponentsSeparatedByCharactersInSet( words, fn CharacterSetWhitespaceAndNewlineSet )
local fn MinLength( string as CFStringRef ) as long
long index, minLength = 0
long length = len(string)
for index = 0 to length - 1
unichar chr = fn StringCharacterAtIndex( string, index )
if ( chr >= _"A" and chr <= _"Z" )
minLength++
else
break
end if
next
end fn = minlength
void local fn Validate
CFArrayRef commands = fn Commands
CFStringRef userString = fn ControlStringValue( _userStringFld )
CFArrayRef words = fn StringComponentsSeparatedByCharactersInSet( userString, fn CharacterSetWhitespaceAndNewlineSet )
long cmdCount = len(commands)
CFMutableStringRef results = fn MutableStringWithCapacity(0)
long wordCount = len(words)
long i, j
for i = 0 to wordCount - 1
CFStringRef result = @"*error* "
CFStringRef wd = words[i]
long wordLength = len(wd)
if ( wordLength )
for j = 0 to cmdCount - 1
CFStringRef cmd = commands[j]
if ( fn StringHasPrefix( lcase(cmd), lcase(wd) ) )
if ( wordLength >= fn MinLength(cmd) )
result = fn StringWithFormat( @"%@ ",ucase(cmd) )
break
end if
end if
next
MutableStringAppendString( results, result )
end if
next
ControlSetStringValue( _resultsStringFld, results )
end fn
void local fn DoDialog( ev as long, tag as long )
select ( ev )
case _btnClick
select ( tag )
case _validateBtn : fn Validate
end select
end select
end fn
editmenu 1
fn BuildWindow
on dialog fn DoDialog
HandleEvents
</syntaxhighlight>
=={{header|Go}}==
{{trans|Kotlin}}
<
import (
Line 1,890 ⟶ 2,066:
fmt.Print("\nfull words: ")
fmt.Println(strings.Join(results, " "))
}</
{{out}}
Line 1,900 ⟶ 2,076:
=={{header|Haskell}}==
<
import Data.Maybe (fromMaybe)
import Data.List (find, isPrefixOf)
Line 1,937 ⟶ 2,113:
let commands = map (fromMaybe "*error*" . expandAbbreviation commandTable) abbreviations
putStrLn $ unwords results
</syntaxhighlight>
=={{header|J}}==
Using the expand definition as well as its dependencies from [[Abbreviations, simple#J]]
we convert this command table into the form with the abbreviation length given as a number.
<syntaxhighlight lang="j">
COMMAND_TABLE=: noun define
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 1,958 ⟶ 2,134:
CT expand user_words
RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT
</
=={{header|Java}}==
<
import java.util.Map;
import java.util.Scanner;
Line 2,015 ⟶ 2,191:
}
}
</syntaxhighlight>
{{out}}
Line 2,027 ⟶ 2,203:
=== Deno ===
Works in Browsers as well, uses ES6. Most of the hardwork was done by the RegEx engine.
<
var abr=`Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,050 ⟶ 2,226:
)
</syntaxhighlight>
=={{header|jq}}==
<syntaxhighlight lang="jq">
def commands:
"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy " +
Line 2,088 ⟶ 2,264:
"riG rePEAT copies put mo rest types fup. 6 poweRin"
| translation
</syntaxhighlight>
Invocation: jq -n -f abbreviations.jq
Line 2,100 ⟶ 2,276:
{{trans|Kotlin}}
<
"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy " *
"COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find " *
Line 2,135 ⟶ 2,311:
result = validate(commands, minlens, words)
println("User words: ", join(lpad.(words, 11)))
println("Full words: ", join(lpad.(result, 11)))</
{{out}}
Line 2,142 ⟶ 2,318:
=={{header|Kotlin}}==
<
val r = Regex("[ ]+")
Line 2,184 ⟶ 2,360:
for (j in 0 until results.size) print("${results[j]} ")
println()
}</
{{out}}
Line 2,193 ⟶ 2,369:
=={{header|Lua}}==
<
local list1 = [[
Line 2,284 ⟶ 2,460:
start() -- run the program
</
{{out}}
Line 2,295 ⟶ 2,471:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
ct = "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,327 ⟶ 2,503:
StringRiffle[ValidFunctionQ /@ parts, " "]
]
ProcessString["riG rePEAT copies put mo rest types fup. 6 poweRin"]</
{{out}}
<pre>"RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT"</pre>
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang="matlab">
function R = abbreviations_easy(input)
Line 2,362 ⟶ 2,538:
R = [R,' ',result];
end
</syntaxhighlight>
{{out}}
Line 2,372 ⟶ 2,548:
=={{header|Nanoquery}}==
{{trans|Java}}
<
COMMAND_TABLE = " Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy\n" +\
Line 2,421 ⟶ 2,597:
print "*error* "
end
end</
{{out}}
<pre>Please enter your command to verify: riG rePEAT copies put mo rest types fup. 6 poweRin RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT</pre>
Line 2,428 ⟶ 2,604:
{{trans|Kotlin}}
This is a translation of Kotlin solution with some modifications.
<syntaxhighlight lang="nim">
import sequtils
import strutils
Line 2,483 ⟶ 2,659:
echo ""
break
</syntaxhighlight>
{{out}}
<pre>
Line 2,501 ⟶ 2,677:
=={{header|OCaml}}==
<
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,547 ⟶ 2,723:
) user
in
print_endline (String.concat " " r)</
{{out}}
Line 2,558 ⟶ 2,734:
==={{header|Free Pascal}}===
{{trans|Delphi}} only modified to get the implicit declared variables and types.
<
program Abbreviations_Easy;
{$IFDEF WINDOWS}
Line 2,660 ⟶ 2,836:
Readln;
{$ENDIF}
end.</
{{out|@TIO.RUN fpc 3.0.4 }}
<pre>
Line 2,668 ⟶ 2,844:
=={{header|Perl}}==
{{trans|Raku}}
<
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,695 ⟶ 2,871:
}
print "$inp\n$out\n"</
{{out}}
<pre>Input: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 2,702 ⟶ 2,878:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">abbrtxt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 2,745 ⟶ 2,921:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 2,752 ⟶ 2,928:
=={{header|PHP}}==
<
// note this is php 7.x
$commands = 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 2,803 ⟶ 2,979:
}
return $rs;
}</
{{Out}}
<pre>user words: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 2,811 ⟶ 2,987:
{{trans|Prolog}}
{{works with|Picat}}
<syntaxhighlight lang="picat">
import util.
Line 2,848 ⟶ 3,024:
end,
nl.
</syntaxhighlight>
{{out}}
<pre>
Line 2,855 ⟶ 3,031:
=={{header|PowerShell}}==
<
$cmdTableStr =
"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 2,898 ⟶ 3,074:
# Below lines display the input and output
"User text: " + $userWordStr
"Full text: " + $outputStr</
{{Out}}
<pre>User text: riG rePEAT copies put mo rest types fup. 6 poweRin
Full text: RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT</pre>
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">
:- initialization(main).
command_table("Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput
Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO
MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT
READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT
RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up").
validate("", _, "") :- !.
validate(Word, Commands, Result) :-
member(Command, Commands),
string_concat(Prefix, Suffix, Command),
string_upper(Prefix, Prefix),
string_lower(Suffix, Suffix),
string_lower(Word, LowWord),
string_lower(Prefix, LowPrefix),
string_concat(LowPrefix, _, LowWord),
string_lower(Command, LowCommand),
string_concat(LowWord, _, LowCommand),
string_upper(Command, Result),
!.
validate(_, _, "*error*").
main :-
current_prolog_flag(argv, Args),
command_table(Table),
split_string(Table, " \t\n", "", Commands),
forall(member(Arg, Args), (
atom_string(Arg, Word),
validate(Word, Commands, Result),
format("~w ", Result)
)),
nl.
</syntaxhighlight>
{{out}}
<pre>
RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT
</pre>
=={{header|Python}}==
{{works with|Python|3.6}}
<
"""Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,948 ⟶ 3,170:
print("user words:", user_words)
print("full words:", full_words)</
{{Out}}
<pre>user words: riG rePEAT copies put mo rest types fup. 6 poweRin
full words: RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT</pre>
=={{header|R}}==
<syntaxhighlight lang="R">
library(stringi)
cmds_block <- "
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput
Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO
MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT
READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT
RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up"
cmds <- cmds_block %>% trimws() %>% stri_split_regex("\\s+") %>% unlist()
check_word <- function(inputw,comw) {
inputl <- nchar(inputw)
coml <- nchar(comw)
cap_cnt <- stri_count_regex(comw,"[A-Z]")
ifelse(cap_cnt != 0 && inputl >= cap_cnt && inputl <= coml &&
stri_startswith_fixed(toupper(comw),toupper(inputw)),T,F)
}
# Inputs
intstr_list <- "riG rePEAT copies put mo rest types fup. 6 poweRin" %>%
stri_split_regex("\\s+") %>% unlist()
# Results
results <- sapply(intstr_list,\(y) {
matc <- cmds[sapply(cmds,\(x) check_word(y,x))]
ifelse(length(matc) != 0,toupper(matc[1]),"*error*")
})
print(results)
</syntaxhighlight>
{{Out}}
<pre>
riG rePEAT copies put mo rest types fup. 6 poweRin
"RIGHT" "REPEAT" "*error*" "PUT" "MOVE" "RESTORE" "*error*" "*error*" "*error*" "POWERINPUT"
</pre>
=={{header|Racket}}==
<
(define command-string
Line 2,984 ⟶ 3,250:
full-command))
"*error*"))
" ")</
{{out}}
Line 2,997 ⟶ 3,263:
Demonstrate that inputting an empty string returns an empty string in addition to the required test input.
<syntaxhighlight lang="raku"
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 3,019 ⟶ 3,285:
put ' Input: ', $str;
put 'Output: ', join ' ', $str.words.map: &abbr-easy;
}</
{{out}}
<pre> Input: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 3,027 ⟶ 3,293:
=={{header|REXX}}==
<syntaxhighlight lang
userwords= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
Say 'user words: ' userwords
'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find'
'NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput'
'Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO'
'MErge MOve MODify MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT'
'READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT'
'RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up'
Say 'full words: ' validate(userwords) /*display the result(s) To the terminal*/
/*----------------------------------------------------------------------------------*/
validate: Procedure Expose keyws
res=''
Do j=1 To words(userwords) /* loop through userwords
uword=word(userwords,j) /* get next userword
Do k=1 To words(keyws) /* loop through all keywords */
keyw=word(keyws,k)
L=verify(keyw,'abcdefghijklmnopqrstuvwxyz','M') /* pos. of first lowercase ch*/
If L==0 Then
L=length(keyw)
L=L-1
If abbrev(translate(keyw),uword,L) Then Do /* uword is an abbreviation */
res=res keyw /* add the matching keyword To the result string */
iterate j /* and proceed with the next userword if any */
End
End
res=res '*error*' /* no match found. indicate error */
End
Return strip(res) /* get rid of leading böank */
syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
Line 3,062 ⟶ 3,337:
=={{header|Ruby}}==
<
cmd_table = File.read(ARGV[0]).split
Line 3,078 ⟶ 3,353:
puts
</syntaxhighlight>
{{out}}
<pre>
Line 3,087 ⟶ 3,362:
=={{header|Rust}}==
<
fn main() {
Line 3,120 ⟶ 3,395:
println!("{}", corrected_line);
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,127 ⟶ 3,402:
=={{header|Scala}}==
<syntaxhighlight lang="scala">
object Main extends App {
implicit class StrOps(i: String) {
Line 3,160 ⟶ 3,435:
println(resultLine)
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,167 ⟶ 3,442:
=={{header|Tcl}}==
<
proc appendCmd {word} {
# Procedure to append the correct command from the global list ::cmds
Line 3,206 ⟶ 3,481:
puts $result
</syntaxhighlight>
{{out}}
<pre>
Line 3,213 ⟶ 3,488:
=={{header|VBA}}==
<
Dim s As String
Dim user_words() As String
Line 3,264 ⟶ 3,539:
Debug.Print "user words:", guserstring
Debug.Print "full words:", ValidateUserWords(guserstring)
End Sub</
full words: RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT </pre>
=={{header|Vedit macro language}}==
<
Buf_Switch(#10=Buf_Free)
Ins_Text("
Line 3,332 ⟶ 3,607:
}
}
Return</
{{out}}
<pre>
Line 3,338 ⟶ 3,613:
</pre>
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">import encoding.utf8
fn validate(commands []string, words []string, min_len []int) []string {
Line 3,398 ⟶ 3,673:
print("\nfull words: ")
println(results.join(" "))
}</
{{out}}
Line 3,410 ⟶ 3,685:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<
import "./str" for Str
var table =
Line 3,467 ⟶ 3,742:
}
System.write("\nfull words: ")
System.print(results.join(" "))</
{{out}}
Line 3,476 ⟶ 3,751:
=={{header|Yabasic}}==
<
data "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find"
data "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput"
Line 3,521 ⟶ 3,796:
return n
end sub
</syntaxhighlight>
=={{header|zkl}}==
Rather more brute force than I'd like but hashing the command table is
just too much code. And the table is so small...
<
#<<<
"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 3,549 ⟶ 3,824:
}
"*error*"
.concat(" ").println();</
{{out}}
<pre>
|