Abbreviations, automatic: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
Thundergnat (talk | contribs) m Automated syntax highlighting fixup (second round - minor fixes) |
||
Line 141: | Line 141: | ||
{{trans|Python}} |
{{trans|Python}} |
||
<syntaxhighlight lang=11l>F shortest_abbreviation_length(line, list_size) |
<syntaxhighlight lang="11l">F shortest_abbreviation_length(line, list_size) |
||
V words = line.split(‘ ’) |
V words = line.split(‘ ’) |
||
V word_count = words.len |
V word_count = words.len |
||
Line 269: | Line 269: | ||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="aarch64 assembly"> |
||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
/* ARM assembly AARCH64 Raspberry PI 3B */ |
||
/* program abbrAuto64.s */ |
/* program abbrAuto64.s */ |
||
Line 848: | Line 848: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="ada">with Ada.Containers.Indefinite_Vectors; |
||
with Ada.Strings.Fixed; |
with Ada.Strings.Fixed; |
||
with Ada.Strings.Maps; |
with Ada.Strings.Maps; |
||
Line 1,024: | Line 1,024: | ||
=={{header|Amazing Hopper}}== |
=={{header|Amazing Hopper}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="amazing hopper"> |
||
#include <jambo.h> |
#include <jambo.h> |
||
Line 1,066: | Line 1,066: | ||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="arm assembly"> |
||
/* ARM assembly Raspberry PI */ |
/* ARM assembly Raspberry PI */ |
||
/* program abbrAuto.s */ |
/* program abbrAuto.s */ |
||
Line 1,592: | Line 1,592: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="autohotkey">AutoAbbreviations(line){ |
||
len := prev := 0 |
len := prev := 0 |
||
Days := StrSplit(line, " ") |
Days := StrSplit(line, " ") |
||
Line 1,614: | Line 1,614: | ||
return len |
return len |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
Examples:<syntaxhighlight lang= |
Examples:<syntaxhighlight lang="autohotkey">data := " |
||
( |
( |
||
Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
||
Line 1,644: | Line 1,644: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="awk"> |
||
# syntax: GAWK -f ABBREVIATIONS_AUTOMATIC.AWK ABBREVIATIONS_AUTOMATIC.TXT |
# syntax: GAWK -f ABBREVIATIONS_AUTOMATIC.AWK ABBREVIATIONS_AUTOMATIC.TXT |
||
{ dow_arr[NR] = $0 } |
{ dow_arr[NR] = $0 } |
||
Line 1,801: | Line 1,801: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=c>#include <stdio.h> |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 1,998: | Line 1,998: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
<syntaxhighlight lang=csharp>using System; |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
Line 2,152: | Line 2,152: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=cpp>#include <iomanip> |
<syntaxhighlight lang="cpp">#include <iomanip> |
||
#include <iostream> |
#include <iostream> |
||
#include <fstream> |
#include <fstream> |
||
Line 2,320: | Line 2,320: | ||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
{{works with|GnuCOBOL|3.1.2.0}} |
{{works with|GnuCOBOL|3.1.2.0}} |
||
<syntaxhighlight lang=cobol> IDENTIFICATION DIVISION. |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. AUTO-ABBREVIATIONS. |
PROGRAM-ID. AUTO-ABBREVIATIONS. |
||
Line 2,587: | Line 2,587: | ||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
It uses the standard library split-sequence to split the string into words. |
It uses the standard library split-sequence to split the string into words. |
||
<syntaxhighlight lang=lisp> |
<syntaxhighlight lang="lisp"> |
||
(defun max-mismatch (list) |
(defun max-mismatch (list) |
||
(if (cdr list) |
(if (cdr list) |
||
Line 2,703: | Line 2,703: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="d">import std.conv; |
||
import std.exception; |
import std.exception; |
||
import std.range; |
import std.range; |
||
Line 2,846: | Line 2,846: | ||
{{libheader| System.IOUtils}} |
{{libheader| System.IOUtils}} |
||
{{Trans|Kotlin}} |
{{Trans|Kotlin}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="delphi"> |
||
program Abbreviations_Automatic; |
program Abbreviations_Automatic; |
||
Line 2,941: | Line 2,941: | ||
The output is of the set of abbreviations. These are not sorted correctly and some encoding errors remain. |
The output is of the set of abbreviations. These are not sorted correctly and some encoding errors remain. |
||
<syntaxhighlight lang=erlang> |
<syntaxhighlight lang="erlang"> |
||
-module(abbreviateweekdays). |
-module(abbreviateweekdays). |
||
-export([ main/0 ]). |
-export([ main/0 ]). |
||
Line 3,011: | Line 3,011: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
===The function=== |
===The function=== |
||
<syntaxhighlight lang=fsharp> |
<syntaxhighlight lang="fsharp"> |
||
let fN g=let rec fN n=if g|>List.map(fun(g:string)->g.[0..n])|>Set.ofList|>Set.count=(List.length g) then (n+1) else fN(n+1) |
let fN g=let rec fN n=if g|>List.map(fun(g:string)->g.[0..n])|>Set.ofList|>Set.count=(List.length g) then (n+1) else fN(n+1) |
||
fN 0 |
fN 0 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
===The Task - Demonstrate the function=== |
===The Task - Demonstrate the function=== |
||
<syntaxhighlight lang=fsharp> |
<syntaxhighlight lang="fsharp"> |
||
fN ["Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday"; "Saturday"] // -> 2 |
fN ["Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday"; "Saturday"] // -> 2 |
||
fN ["Sondag"; "Maandag"; "Dinsdag"; "Woensdag"; "Donderdag"; "Vrydag"; "Saterdag"] // -> 2 |
fN ["Sondag"; "Maandag"; "Dinsdag"; "Woensdag"; "Donderdag"; "Vrydag"; "Saterdag"] // -> 2 |
||
Line 3,029: | Line 3,029: | ||
As a concatenative language, Factor is uniquely suited for factoring words into smaller words. Assuming lexical/dynamic variables are not used, factoring is a cut-and-paste job that can be performed almost anywhere there is whitespace. |
As a concatenative language, Factor is uniquely suited for factoring words into smaller words. Assuming lexical/dynamic variables are not used, factoring is a cut-and-paste job that can be performed almost anywhere there is whitespace. |
||
<syntaxhighlight lang=factor>USING: formatting io io.encodings.utf8 io.files kernel math |
<syntaxhighlight lang="factor">USING: formatting io io.encodings.utf8 io.files kernel math |
||
sequences sets splitting ; |
sequences sets splitting ; |
||
IN: rosetta-code.abbreviations-automatic |
IN: rosetta-code.abbreviations-automatic |
||
Line 3,166: | Line 3,166: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import( |
import( |
||
Line 3,249: | Line 3,249: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang=groovy>class Abbreviations { |
<syntaxhighlight lang="groovy">class Abbreviations { |
||
static void main(String[] args) throws IOException { |
static void main(String[] args) throws IOException { |
||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("days_of_week.txt"), "utf-8")) |
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("days_of_week.txt"), "utf-8")) |
||
Line 3,395: | Line 3,395: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<syntaxhighlight lang=haskell>import Data.List (inits, intercalate, transpose) |
<syntaxhighlight lang="haskell">import Data.List (inits, intercalate, transpose) |
||
import qualified Data.Set as S |
import qualified Data.Set as S |
||
Line 3,436: | Line 3,436: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j">NB. y is words in boxes |
||
abbreviation_length =: monad define |
abbreviation_length =: monad define |
||
N =. # y |
N =. # y |
||
Line 3,477: | Line 3,477: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|D}} |
{{trans|D}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="java">import java.io.IOException; |
||
import java.nio.file.Files; |
import java.nio.file.Files; |
||
import java.nio.file.Path; |
import java.nio.file.Path; |
||
Line 3,632: | Line 3,632: | ||
===Procedural=== |
===Procedural=== |
||
The list of the names was edited and embedded in the HTML-Document with a <script>-tag, where it is accessible as an array called $list. |
The list of the names was edited and embedded in the HTML-Document with a <script>-tag, where it is accessible as an array called $list. |
||
<syntaxhighlight lang=javascript> |
<syntaxhighlight lang="javascript"> |
||
Array.prototype.hasDoubles = function() { |
Array.prototype.hasDoubles = function() { |
||
let arr = this.slice(); |
let arr = this.slice(); |
||
Line 3,774: | Line 3,774: | ||
{{Works with|MacOS JXA}} |
{{Works with|MacOS JXA}} |
||
<syntaxhighlight lang=javascript>(() => { |
<syntaxhighlight lang="javascript">(() => { |
||
"use strict"; |
"use strict"; |
||
Line 3,948: | Line 3,948: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang=julia>const text = """ |
<syntaxhighlight lang="julia">const text = """ |
||
Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
||
Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag |
Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag |
||
Line 4,092: | Line 4,092: | ||
===Original O(''n<sup>2</sup>'') solution=== |
===Original O(''n<sup>2</sup>'') solution=== |
||
where ''n'' is the number of strings in each line. |
where ''n'' is the number of strings in each line. |
||
<syntaxhighlight lang=scala>// version 1.1.4-3 |
<syntaxhighlight lang="scala">// version 1.1.4-3 |
||
import java.io.File |
import java.io.File |
||
Line 4,226: | Line 4,226: | ||
===Alternative O(''n log n'') solution based on sorting=== |
===Alternative O(''n log n'') solution based on sorting=== |
||
<syntaxhighlight lang=scala>import java.io.File |
<syntaxhighlight lang="scala">import java.io.File |
||
import kotlin.math.max |
import kotlin.math.max |
||
Line 4,364: | Line 4,364: | ||
=={{header|Ksh}}== |
=={{header|Ksh}}== |
||
<syntaxhighlight lang=ksh> |
<syntaxhighlight lang="ksh"> |
||
#!/bin/ksh |
#!/bin/ksh |
||
Line 4,455: | Line 4,455: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<syntaxhighlight lang=lua>function split(line) |
<syntaxhighlight lang="lua">function split(line) |
||
local wa = {} |
local wa = {} |
||
for i in string.gmatch(line, "%S+") do |
for i in string.gmatch(line, "%S+") do |
||
Line 4,607: | Line 4,607: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="mathematica"> |
||
(*This function gives all 'heads' of str of length 1 to maxLength. Since the input data was formatted to use underscores in place of spaces, there is an edge case where distinct abbreviations derived from the input data would actually not be distinct in the 'real' abbreviations. See further comments below regarding the difference between my output and the output of other solutions.*) |
(*This function gives all 'heads' of str of length 1 to maxLength. Since the input data was formatted to use underscores in place of spaces, there is an edge case where distinct abbreviations derived from the input data would actually not be distinct in the 'real' abbreviations. See further comments below regarding the difference between my output and the output of other solutions.*) |
||
Abbreviations[maxLength_Integer][str_String]:=Array[StringTake[StringPadRight[str,maxLength,"_"],#]&,maxLength]; |
Abbreviations[maxLength_Integer][str_String]:=Array[StringTake[StringPadRight[str,maxLength,"_"],#]&,maxLength]; |
||
Line 4,742: | Line 4,742: | ||
We provide two solutions, one consisting to build the abbreviations for each language and stopping when all of them are different, the second sorting the list of day names for each language and adjusting the abbreviation length to make sure that two consecutive day names are different. The second method should be more efficient, but it doesn’t really matters here. |
We provide two solutions, one consisting to build the abbreviations for each language and stopping when all of them are different, the second sorting the list of day names for each language and adjusting the abbreviation length to make sure that two consecutive day names are different. The second method should be more efficient, but it doesn’t really matters here. |
||
===Using a set=== |
===Using a set=== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="nim"> |
||
import sets |
import sets |
||
import unicode |
import unicode |
||
Line 4,776: | Line 4,776: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
===Using a sorted list=== |
===Using a sorted list=== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="nim"> |
||
import algorithm |
import algorithm |
||
import unicode |
import unicode |
||
Line 4,914: | Line 4,914: | ||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
<syntaxhighlight lang=objeck>use System.IO.File; |
<syntaxhighlight lang="objeck">use System.IO.File; |
||
use Collection; |
use Collection; |
||
Line 5,086: | Line 5,086: | ||
Output is the same as for Raku. |
Output is the same as for Raku. |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
<syntaxhighlight lang=perl>use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use utf8; |
use utf8; |
||
binmode STDOUT, ":utf8"; |
binmode STDOUT, ":utf8"; |
||
Line 5,111: | Line 5,111: | ||
The file abbrev_auto.txt was manually created from the task description. The following code |
The file abbrev_auto.txt was manually created from the task description. The following code |
||
assumes a more recent version of get_text() that strips any leading utf8 bom by default (0.8.0+). |
assumes a more recent version of get_text() that strips any leading utf8 bom by default (0.8.0+). |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abbrev_auto.txt"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">GT_LF_STRIPPED</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abbrev_auto.txt"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">GT_LF_STRIPPED</span><span style="color: #0000FF;">)</span> |
||
Line 5,144: | Line 5,144: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
{{works with|Picat}} |
{{works with|Picat}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="picat"> |
||
import util. |
import util. |
||
Line 5,284: | Line 5,284: | ||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
{{works with|SWI Prolog}} |
{{works with|SWI Prolog}} |
||
<syntaxhighlight lang=prolog>minimum_abbreviation_length(Day_names, Min_length):- |
<syntaxhighlight lang="prolog">minimum_abbreviation_length(Day_names, Min_length):- |
||
sort(Day_names, Sorted_names), |
sort(Day_names, Sorted_names), |
||
minimum_abbreviation_length(Sorted_names, Min_length, 1). |
minimum_abbreviation_length(Sorted_names, Min_length, 1). |
||
Line 5,442: | Line 5,442: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="purebasic">EnableExplicit |
||
#TZ="|" |
#TZ="|" |
||
#FZ="@" |
#FZ="@" |
||
Line 5,691: | Line 5,691: | ||
{{works with|Python|3.6}} |
{{works with|Python|3.6}} |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang=python>def shortest_abbreviation_length(line, list_size): |
<syntaxhighlight lang="python">def shortest_abbreviation_length(line, list_size): |
||
words = line.split() |
words = line.split() |
||
word_count = len(words) |
word_count = len(words) |
||
Line 5,825: | Line 5,825: | ||
===Functional=== |
===Functional=== |
||
In terms of generators: |
In terms of generators: |
||
<syntaxhighlight lang=python>import operator |
<syntaxhighlight lang="python">import operator |
||
from itertools import (accumulate, |
from itertools import (accumulate, |
||
repeat) |
repeat) |
||
Line 5,988: | Line 5,988: | ||
The generic primitives are curried, allowing for more flexible composition: |
The generic primitives are curried, allowing for more flexible composition: |
||
{{Works with|Python|3}} |
{{Works with|Python|3}} |
||
<syntaxhighlight lang=python>'''Automatic abbreviations''' |
<syntaxhighlight lang="python">'''Automatic abbreviations''' |
||
from itertools import (accumulate, chain) |
from itertools import (accumulate, chain) |
||
Line 6,129: | Line 6,129: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang=racket>#lang racket |
<syntaxhighlight lang="racket">#lang racket |
||
(require racket/set) |
(require racket/set) |
||
Line 6,162: | Line 6,162: | ||
Note that this is using a previous version of the date file that has erroneous duplicate day names (see line 90). Since the effort was already expended to catch such problems, it may as well be demonstrated. |
Note that this is using a previous version of the date file that has erroneous duplicate day names (see line 90). Since the effort was already expended to catch such problems, it may as well be demonstrated. |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="raku" line>sub auto-abbreviate ( Str $string ) { |
||
return Nil unless my @words = $string.words; |
return Nil unless my @words = $string.words; |
||
return $_ if @words».substr(0, $_).Set == @words for 1 .. @words».chars.max; |
return $_ if @words».substr(0, $_).Set == @words for 1 .. @words».chars.max; |
||
Line 6,273: | Line 6,273: | ||
=={{header|Red}}== |
=={{header|Red}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="red"> |
||
Red [] |
Red [] |
||
;; read and convert data to a string - to char conversion is neccessary to avoid |
;; read and convert data to a string - to char conversion is neccessary to avoid |
||
Line 6,326: | Line 6,326: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<syntaxhighlight lang=rexx>/*REXX program finds the minimum length abbreviation for a lists of words (from a file).*/ |
<syntaxhighlight lang="rexx">/*REXX program finds the minimum length abbreviation for a lists of words (from a file).*/ |
||
parse arg uw /*obtain optional arguments from the CL*/ |
parse arg uw /*obtain optional arguments from the CL*/ |
||
iFID= 'ABBREV_A.TAB' /*name of the file that has the table. */ |
iFID= 'ABBREV_A.TAB' /*name of the file that has the table. */ |
||
Line 6,463: | Line 6,463: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang=ruby>require "abbrev" |
<syntaxhighlight lang="ruby">require "abbrev" |
||
File.read("daynames.txt").each_line do |line| |
File.read("daynames.txt").each_line do |line| |
||
Line 6,505: | Line 6,505: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
<syntaxhighlight lang=c>/** |
<syntaxhighlight lang="c">/** |
||
* Abbreviations from tintenalarm.de |
* Abbreviations from tintenalarm.de |
||
*/ |
*/ |
||
Line 6,663: | Line 6,663: | ||
===Functional programmed=== |
===Functional programmed=== |
||
====build.sbt==== |
====build.sbt==== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="scala">name := "Abbreviations-automatic" |
||
scalaVersion := "2.13.0" |
scalaVersion := "2.13.0" |
||
version := "0.1" |
version := "0.1" |
||
Line 6,671: | Line 6,671: | ||
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.3.0"</syntaxhighlight> |
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.3.0"</syntaxhighlight> |
||
====AbbreviationsAuto.scala==== |
====AbbreviationsAuto.scala==== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="scala">object AbbreviationsAuto extends App { |
||
private val wd = os.pwd |
private val wd = os.pwd |
||
Line 6,794: | Line 6,794: | ||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
<syntaxhighlight lang=sensetalk>function AbbreviationsAutomatic days |
<syntaxhighlight lang="sensetalk">function AbbreviationsAutomatic days |
||
put 1 into abbreviationLength |
put 1 into abbreviationLength |
||
put the number of items in days into len |
put the number of items in days into len |
||
Line 6,812: | Line 6,812: | ||
end repeat |
end repeat |
||
end AbbreviationsAutomatic</syntaxhighlight> |
end AbbreviationsAutomatic</syntaxhighlight> |
||
<syntaxhighlight lang=sensetalk>put "Weekdays.txt" into myFile |
<syntaxhighlight lang="sensetalk">put "Weekdays.txt" into myFile |
||
put the defaultStringEncoding into savedEncoding |
put the defaultStringEncoding into savedEncoding |
||
Line 6,851: | Line 6,851: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
<syntaxhighlight lang=tcl> |
<syntaxhighlight lang="tcl"> |
||
set f [open abbreviations_automatic_weekdays.txt] |
set f [open abbreviations_automatic_weekdays.txt] |
||
set lines [split [read -nonewline $f] \n] |
set lines [split [read -nonewline $f] \n] |
||
Line 6,886: | Line 6,886: | ||
=={{header|Transd}}== |
=={{header|Transd}}== |
||
<syntaxhighlight lang=scheme>#lang transd |
<syntaxhighlight lang="scheme">#lang transd |
||
MainModule : { |
MainModule : { |
||
Line 7,002: | Line 7,002: | ||
=={{header|TSE SAL}}== |
=={{header|TSE SAL}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="tsesal"> |
||
STRING PROC FNStringGetExpressionRegularCharacterMetaEscapeS( STRING inS ) |
STRING PROC FNStringGetExpressionRegularCharacterMetaEscapeS( STRING inS ) |
||
STRING s[255] = inS |
STRING s[255] = inS |
||
Line 7,203: | Line 7,203: | ||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
Function : |
Function : |
||
<syntaxhighlight lang=vb>Function MinimalLenght(strLine As String) As Integer |
<syntaxhighlight lang="vb">Function MinimalLenght(strLine As String) As Integer |
||
Dim myVar As Variant, I As Integer, Flag As Boolean, myColl As Collection, Count As Integer |
Dim myVar As Variant, I As Integer, Flag As Boolean, myColl As Collection, Count As Integer |
||
myVar = Split(strLine, " ") |
myVar = Split(strLine, " ") |
||
Line 7,223: | Line 7,223: | ||
End Function</syntaxhighlight> |
End Function</syntaxhighlight> |
||
To call it : |
To call it : |
||
<syntaxhighlight lang=vb>Sub Main_Abbr_Auto() |
<syntaxhighlight lang="vb">Sub Main_Abbr_Auto() |
||
Dim Nb As Integer, s As String, Result() As String, c As Integer |
Dim Nb As Integer, s As String, Result() As String, c As Integer |
||
Nb = FreeFile |
Nb = FreeFile |
||
Line 7,340: | Line 7,340: | ||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<syntaxhighlight lang=vb> |
<syntaxhighlight lang="vb"> |
||
sub print(s) wscript.stdout.writeline s :end sub |
sub print(s) wscript.stdout.writeline s :end sub |
||
Line 7,411: | Line 7,411: | ||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=vbnet>Module Module1 |
<syntaxhighlight lang="vbnet">Module Module1 |
||
Sub Main() |
Sub Main() |
||
Line 7,562: | Line 7,562: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=vlang>import os |
<syntaxhighlight lang="vlang">import os |
||
fn distinct_strings(strs []string) []string { |
fn distinct_strings(strs []string) []string { |
||
Line 7,632: | Line 7,632: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
<syntaxhighlight lang=ecmascript>import "io" for File |
<syntaxhighlight lang="ecmascript">import "io" for File |
||
import "/pattern" for Pattern |
import "/pattern" for Pattern |
||
import "/seq" for Lst |
import "/seq" for Lst |
||
Line 7,766: | Line 7,766: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="yabasic"> |
||
a = open("days_of_week.txt", "r") |
a = open("days_of_week.txt", "r") |
||
Line 7,798: | Line 7,798: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
zkl doesn't grok UTF-8 so I'm using a byte by byte check. It works surprisingly well. |
zkl doesn't grok UTF-8 so I'm using a byte by byte check. It works surprisingly well. |
||
<syntaxhighlight lang=zkl>nds:=File("daysOfWeek.txt").read().howza(11) // stripped lines |
<syntaxhighlight lang="zkl">nds:=File("daysOfWeek.txt").read().howza(11) // stripped lines |
||
.pump(List,Void.Filter,fcn(day){ |
.pump(List,Void.Filter,fcn(day){ |
||
d,N,m := day.split(),d.len(),(0).max(d.apply("len")); // N==7 |
d,N,m := day.split(),d.len(),(0).max(d.apply("len")); // N==7 |