Jump to content

Abbreviations, simple: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 94:
{{trans|Python}}
 
<syntaxhighlight lang="11l">V command_table_text =
|‘add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 158:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program abbrSimple64.s */
Line 614:
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">with Ada.Characters.Handling;
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
Line 762:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<syntaxhighlight lang="algol68"># "Simple" abbreviations #
 
# returns the next word from text, updating pos #
Line 907:
<pre> Ok correction le 17/11/2020 16H </pre>
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
/* ARM assembly Raspberry PI */
/* program abbrSimple.s */
Line 1,343:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">table := "
(
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
Line 1,381:
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
Line 1,539:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <algorithm>
#include <cctype>
#include <iostream>
Line 1,666:
NOTE: Type Hints have been added here to indicate the types of function arguments and to make the program faster. They are not strictly necessary, since Clojure is a dynamically typed language (i.e., variable types are determined at runtime).
 
<syntaxhighlight lang="clojure">
(defn words
"Split string into words"
Line 1,739:
 
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">COMMAND_TABLE =
"add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 1,801:
 
=={{header|D}}==
<syntaxhighlight lang=D"d">class Abbreviations
{
import std.array: split, join;
Line 1,876:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang=Delphi"delphi">
program Abraviation_simple;
 
Line 1,985:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: arrays assocs combinators formatting fry grouping.extras
kernel literals math math.parser multiline sequences
splitting.extras unicode ;
Line 2,063:
Needs the FMS-SI (single inheritance) library code located here:
http://soton.mpeforth.com/flag/fms/index.html
<syntaxhighlight lang="forth">include FMS-SI.f
include FMS-SILib.f
 
Line 2,122:
=={{header|Go}}==
{{trans|Kotlin}}
<syntaxhighlight lang="go">package main
 
import (
Line 2,222:
=={{header|Haskell}}==
{{Trans|Python}}
<syntaxhighlight lang="haskell">import Data.List (find, isPrefixOf)
import Data.Char (isDigit, toUpper)
import Data.Maybe (maybe)
Line 2,273:
 
=={{header|J}}==
<syntaxhighlight lang=J"j">ctable=:|:(({.;~{:@(_,".)@;@}.);.1~ _2<nc) cut {{)n
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 2,294:
 
Task:
<syntaxhighlight lang=J"j"> ;:inv findmatch cut ' riG rePEAT copies put mo rest types fup. 6 poweRin'
RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT</syntaxhighlight>
 
=={{header|Java}}==
{{Trans|C++}}
<syntaxhighlight lang="java">import java.util.*;
 
public class Abbreviations {
Line 2,401:
{{Trans|Haskell}}
{{Trans|Python}}
<syntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 2,653:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
const commandtable = """
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
Line 2,705:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">import java.util.Locale
 
private const val table = "" +
Line 2,767:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">abbr = {
define = function(self, cmdstr)
local cmd
Line 2,812:
Object Queue is a list (using a hash table) which can hold same keys (strings or numbers or mix of them). Always the Exist(aQueuePointer, "word") set the internal index to the last key with name "word" if return true. We read the item in that index using Eval$(aQueuePointer) for string value, or Eval(aQueuePointer) for aritmetic value. We can't delete keys from anywhere, but only from the last entries using Drop statement to drop a number of keys. Here we didn't use drop, we have only a table of words.
 
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
Module Abbreviations_Simple {
Function Lex {
Line 2,879:
Here we use just a string to hold the words and the Instr() function to search for each abbreviation.
 
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
Module Abbreviations_Simple_2 {
Function Lex$ {
Line 2,955:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">ClearAll[ct, FunctionMatchQ, ValidFunctionQ, ProcessString]
ct = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 2,995:
 
=={{header|MiniScript}}==
<syntaxhighlight lang=MiniScript"miniscript">c = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3" +
" compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate" +
" 3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2" +
Line 3,044:
{{Trans|Python}}
Adapted from Python version with several modifications.
<syntaxhighlight lang=Nim"nim">
import parseutils
import strutils
Line 3,132:
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">open String
 
let table_as_string =
Line 3,154:
but for the latter, we need to ensure that the word corresponds to the abbreviation
(the abbreviation is a substring of the word and the abbreviation length is sufficient).
<syntaxhighlight lang="ocaml">module Entry = struct
type t = { word : string ; min : int }
let compare e1 e2 =
Line 3,167:
 
The few functions below are used to build the table from the string at the beginning.
<syntaxhighlight lang="ocaml">let clean_strings strs =
List.filter (fun w -> w <> "" && w <> " ") strs
 
Line 3,190:
 
Finally, here is the function looking for a word :
<syntaxhighlight lang="ocaml">let abbrev (table:Table.t) (w:string) : string =
let w = uppercase_ascii w in
try
Line 3,213:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">@c = (uc join ' ', qw<
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 3,248:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">abbrtxt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
Line 3,306:
====Procedural====
{{works with|Python|3.6}}
<syntaxhighlight lang="python">
 
command_table_text = """add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
Line 3,379:
====Composition of pure functions====
{{Works with|Python|3.7}}
<syntaxhighlight lang="python">'''Simple abbreviations'''
 
from functools import reduce
Line 3,559:
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">#lang racket
(require srfi/13)
 
Line 3,614:
Demonstrate that inputting an empty string returns an empty string in addition to the required test input.
 
<syntaxhighlight lang=perl6"raku" line><
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
Line 3,645:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program validates a user "word" against a "command table" with abbreviations.*/
parse arg uw /*obtain optional arguments from the CL*/
if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
Line 3,681:
 
=={{header|Ruby}}==
<syntaxhighlight lang=Ruby"ruby">str = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2
Line 3,711:
{{works with|Rust|1.35.0}}
cargo clippy and cargo fmt run against it
<syntaxhighlight lang="rust">use std::collections::HashMap;
 
// The plan here is to build a hashmap of all the commands keyed on the minimum number of
Line 3,829:
 
=={{header|Scala}}==
<syntaxhighlight lang=Scala"scala">
object Main extends App {
implicit class StrOps(i: String) {
Line 3,883:
=={{header|SNOBOL4}}==
{{works with|SNOBOL4, SPITBOL for Linux}}
<syntaxhighlight lang=SNOBOL4"snobol4">
* Program: abbr_simple.sbl
* To run: sbl abbr_simple.sbl
Line 3,957:
=={{header|Tcl}}==
 
<syntaxhighlight lang="tcl">proc appendCmd {word} {
# Procedure to append the correct command from the global list ::cmds
# for the word given as parameter to the global list ::result.
Line 4,002:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">Private Function ValidateUserWords(userstring As String) As String
Dim s As String
Dim user_words() As String
Line 4,066:
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
option explicit
 
Line 4,165:
=={{header|Vlang}}==
{{trans|Go}}
<syntaxhighlight lang="vlang">import encoding.utf8
import strconv
fn read_table(table string) ([]string, []int) {
Line 4,251:
{{libheader|Wren-str}}
Based on an older version of the Go entry.
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt
import "/str" for Str
 
Line 4,328:
 
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic"yabasic">c$ = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3"
c$ = c$ + " compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate"
c$ = c$ + " 3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2"
Line 4,384:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">commands:=Data(0,String, // "add\01\0alter\0..."
#<<<
"add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.