Abbreviations, easy: Difference between revisions

Added FreeBASIC
(→‎{{header|Prolog}}: Adding Prolog)
(Added FreeBASIC)
 
(13 intermediate revisions by 7 users not shown)
Line 87:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V command_table_text =
|‘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)</langsyntaxhighlight>
 
{{out}}
Line 140:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<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>
</lang>
<pre>
Enter command (or quit to stop) : riG
Line 590:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Characters.Handling;
with Ada.Containers.Indefinite_Vectors;
with Ada.Strings.Fixed;
Line 687:
Put_Match ("");
Put_Match ("o");
end Abbreviations_Easy;</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="algol68"># "Easy" abbreviations #
# 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 )</langsyntaxhighlight>
{{out}}
<pre>
Line 798:
<pre> Correction program 15/11/2020 </pre>
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program abbrEasy.s */
Line 1,186:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
 
<pre>
Line 1,214:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotKeylang="autohotkey">; Setting up command table as one string
str =
(
Line 1,258:
}
MsgBox % Trim(result)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,266:
 
=={{header|AWK}}==
<langsyntaxhighlight AWKlang="awk">#!/usr/bin/awk -f
BEGIN {
FS=" ";
Line 1,305:
 
 
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,314:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
Line 1,460:
free_command_list(commands);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,469:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <cctype>
#include <iostream>
Line 1,571:
std::cout << "output: " << output << '\n';
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,581:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="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>
</lang>
 
{{out}}
Line 1,636:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Abbreviations_Easy;
 
Line 1,715:
Writeln(string.Join(' ', results));
Readln;
end.</langsyntaxhighlight>
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
<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>
</lang>
{{out}}
<pre>
Line 1,761:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: arrays ascii assocs combinators.short-circuit io kernel
literals math qw sequences sequences.extras splitting.extras ;
IN: rosetta-code.abbreviations-easy
Line 1,813:
: main ( -- ) user-input "" [ .abbr ] bi@ ;
MAIN: main</langsyntaxhighlight>
{{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}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,890 ⟶ 2,066:
fmt.Print("\nfull words: ")
fmt.Println(strings.Join(results, " "))
}</langsyntaxhighlight>
 
{{out}}
Line 1,900 ⟶ 2,076:
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="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>
</lang>
 
=={{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">
<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
</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight Javalang="java">import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
Line 2,015 ⟶ 2,191:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,027 ⟶ 2,203:
=== Deno ===
Works in Browsers as well, uses ES6. Most of the hardwork was done by the RegEx engine.
<langsyntaxhighlight lang="javascript">
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>
</lang>
=={{header|jq}}==
<syntaxhighlight lang="jq">
<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>
</lang>
 
Invocation: jq -n -f abbreviations.jq
Line 2,100 ⟶ 2,276:
{{trans|Kotlin}}
 
<langsyntaxhighlight lang="julia">const table =
"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)))</langsyntaxhighlight>
 
{{out}}
Line 2,142 ⟶ 2,318:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.4-3
 
val r = Regex("[ ]+")
Line 2,184 ⟶ 2,360:
for (j in 0 until results.size) print("${results[j]} ")
println()
}</langsyntaxhighlight>
 
{{out}}
Line 2,193 ⟶ 2,369:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">#!/usr/bin/lua
 
local list1 = [[
Line 2,284 ⟶ 2,460:
 
start() -- run the program
</langsyntaxhighlight>
 
{{out}}
Line 2,295 ⟶ 2,471:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[ct, FunctionMatchQ, ValidFunctionQ, ProcessString]
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"]</langsyntaxhighlight>
{{out}}
<pre>"RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT"</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang="matlab">
<lang Matlab>
function R = abbreviations_easy(input)
 
Line 2,362 ⟶ 2,538:
R = [R,' ',result];
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,372 ⟶ 2,548:
=={{header|Nanoquery}}==
{{trans|Java}}
<langsyntaxhighlight lang="nanoquery">import map
 
COMMAND_TABLE = " Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy\n" +\
Line 2,421 ⟶ 2,597:
print "*error* "
end
end</langsyntaxhighlight>
{{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">
<lang Nim>
import sequtils
import strutils
Line 2,483 ⟶ 2,659:
echo ""
break
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,501 ⟶ 2,677:
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">let cmds = "\
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)</langsyntaxhighlight>
 
{{out}}
Line 2,558 ⟶ 2,734:
==={{header|Free Pascal}}===
{{trans|Delphi}} only modified to get the implicit declared variables and types.
<langsyntaxhighlight lang="pascal">
program Abbreviations_Easy;
{$IFDEF WINDOWS}
Line 2,660 ⟶ 2,836:
Readln;
{$ENDIF}
end.</langsyntaxhighlight>
{{out|@TIO.RUN fpc 3.0.4 }}
<pre>
Line 2,668 ⟶ 2,844:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">@c = (join ' ', qw<
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"</langsyntaxhighlight>
{{out}}
<pre>Input: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 2,702 ⟶ 2,878:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,752 ⟶ 2,928:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="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;
}</langsyntaxhighlight>
{{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">
<lang Picat>
import util.
 
Line 2,848 ⟶ 3,024:
end,
nl.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,855 ⟶ 3,031:
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell"><# Start with a string of the commands #>
$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</langsyntaxhighlight>
{{Out}}
<pre>User text: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 2,905 ⟶ 3,081:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">
<lang Prolog>
:- initialization(main).
 
Line 2,932 ⟶ 3,108:
 
validate(_, _, "*error*").
 
 
main :-
Line 2,944 ⟶ 3,119:
)),
nl.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,950 ⟶ 3,125:
</pre>
 
'''Bold text'''=={{header|Python}}==
{{works with|Python|3.6}}
<langsyntaxhighlight lang="python">command_table_text = \
"""Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 2,995 ⟶ 3,170:
 
print("user words:", user_words)
print("full words:", full_words)</langsyntaxhighlight>
{{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}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define command-string
Line 3,031 ⟶ 3,250:
full-command))
"*error*"))
" ")</langsyntaxhighlight>
 
{{out}}
Line 3,044 ⟶ 3,263:
Demonstrate that inputting an empty string returns an empty string in addition to the required test input.
 
<syntaxhighlight lang="raku" perl6line><
Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find
Line 3,066 ⟶ 3,285:
put ' Input: ', $str;
put 'Output: ', join ' ', $str.words.map: &abbr-easy;
}</langsyntaxhighlight>
{{out}}
<pre> Input: riG rePEAT copies put mo rest types fup. 6 poweRin
Line 3,074 ⟶ 3,293:
 
=={{header|REXX}}==
<syntaxhighlight lang REXX="rexx">/*REXX program validates a user "word" words against a "command table" with abbreviations.*/
parse arg uw Parse Arg userwords /*obtain optional arguments from the CLcommand line */
ifIf uwuserwords='' Then then uw= 'riG rePEAT copies put mo rest/* nothing specified, use typesdefault list from fup.task 6 poweRin'*/
userwords= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
say 'user words: ' uw
Say 'user words: ' userwords
 
@keyws= '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 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*/
 
sayExit 'full words: ' validate(uw) /*displaystick thea result(s)fork in it, we're toall theDone. terminal*/
/*----------------------------------------------------------------------------------*/
exit /*stick a fork in it, we're all done. */
validate: Procedure Expose keyws
/*──────────────────────────────────────────────────────────────────────────────────────*/
validate: procedure exposeArg userwords @; arg x; upper @ /*ARG Arg = capitalizesParse allUpper theArg get Xuserwords in words.uppercase */
res='' $= /* initialize the return string To null /*initialize the return string to null.*/
Do j=1 To words(userwords) /* loop through userwords do j=1 to words(x); _=word(x, j) /*obtain a word from the X list. */
uword=word(userwords,j) /* get next userword do k=1 to words(@); a=word(@, k) /*get a legitimate command name from @.*/
Do k=1 To words(keyws) /* loop through all keywords */
L=verify(_, 'abcdefghijklmnopqrstuvwxyz', "M") /*maybe get abbrev's len.*/
keyw=word(keyws,k)
if L==0 then L=length(_) /*0? Command name can't be abbreviated*/
L=verify(keyw,'abcdefghijklmnopqrstuvwxyz','M') /* pos. of first lowercase ch*/
if abbrev(a, _, L) then do; $=$ a; iterate j; end /*is valid abbrev?*/
If L==0 Then end /*k keyword is all uppercase */
L=length(keyw) $=$ '*error*' /* we need L characters for a match /*processed the whole list, not valid. */
end /*j*/Else
L=L-1 return strip($) /* number of uppercase characters /*elide the superfluous leading blank. */</lang>
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=&nbsp; when using the default input:}}
<pre>
Line 3,109 ⟶ 3,337:
=={{header|Ruby}}==
 
<langsyntaxhighlight lang="ruby">#!/usr/bin/env ruby
 
cmd_table = File.read(ARGV[0]).split
Line 3,125 ⟶ 3,353:
 
puts
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,134 ⟶ 3,362:
=={{header|Rust}}==
 
<langsyntaxhighlight lang="rust">use std::collections::HashMap;
 
fn main() {
Line 3,167 ⟶ 3,395:
println!("{}", corrected_line);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,174 ⟶ 3,402:
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">
<lang Scala>
object Main extends App {
implicit class StrOps(i: String) {
Line 3,207 ⟶ 3,435:
println(resultLine)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,214 ⟶ 3,442:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">
proc appendCmd {word} {
# Procedure to append the correct command from the global list ::cmds
Line 3,253 ⟶ 3,481:
 
puts $result
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,260 ⟶ 3,488:
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Private Function ValidateUserWords(userstring As String) As String
Dim s As String
Dim user_words() As String
Line 3,311 ⟶ 3,539:
Debug.Print "user words:", guserstring
Debug.Print "full words:", ValidateUserWords(guserstring)
End Sub</langsyntaxhighlight>{{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|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">// Command table:
Buf_Switch(#10=Buf_Free)
Ins_Text("
Line 3,379 ⟶ 3,607:
}
}
Return</langsyntaxhighlight>
{{out}}
<pre>
Line 3,385 ⟶ 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,445 ⟶ 3,673:
print("\nfull words: ")
println(results.join(" "))
}</langsyntaxhighlight>
 
{{out}}
Line 3,457 ⟶ 3,685:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
import "./str" for Str
var table =
Line 3,514 ⟶ 3,742:
}
System.write("\nfull words: ")
System.print(results.join(" "))</langsyntaxhighlight>
 
{{out}}
Line 3,523 ⟶ 3,751:
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">data "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy"
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,568 ⟶ 3,796:
return n
end sub
</syntaxhighlight>
</lang>
 
=={{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...
<langsyntaxhighlight lang="zkl">commands:=Data(0,String, // "Add\0ALTer\0..."
#<<<
"Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy
Line 3,596 ⟶ 3,824:
}
"*error*"
.concat(" ").println();</langsyntaxhighlight>
{{out}}
<pre>
2,122

edits