Function frequency: Difference between revisions

Added FreeBASIC
(Added XPL0 example.)
(Added FreeBASIC)
 
(3 intermediate revisions by 2 users not shown)
Line 926:
$
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Dim As String code, word, char
Dim As Integer i, j
Dim As String words()
Dim As Integer counts()
 
Open "i:\your_file.bas" For Input As #1
While Not Eof(1)
Line Input #1, code
For i = 1 To Len(code)
char = Lcase(Mid(code, i, 1))
If char >= "a" And char <= "z" Then
word &= Mid(code, i, 1)
Elseif word <> "" Then
For j = 0 To Ubound(words)
If words(j) = word Then
counts(j) += 1
Exit For
End If
Next
If j > Ubound(words) Then
Redim Preserve words(Ubound(words) + 1)
Redim Preserve counts(Ubound(counts) + 1)
words(Ubound(words)) = word
counts(Ubound(counts)) = 1
End If
word = ""
End If
Next
Wend
Close #1
 
For i = 0 To 9
Dim As Integer maxj = 0
For j = 0 To Ubound(counts)
If counts(j) > counts(maxj) Then maxj = j
Next
Print words(maxj); " occurs"; counts(maxj); " times"
counts(maxj) = 0
Next
 
Sleep</syntaxhighlight>
 
=={{header|Go}}==
Line 2,092 ⟶ 2,135:
1 wordsort
0.093000 seconds elapsed for 2200 tokens in 510 lines.</pre>
 
=={{header|RPL}}==
« DUP 1 DUP SUB ROT SWAP + → seps input
« { }
1 input SIZE '''FOR''' j
1 OVER TYPE 5 == ::SF ::CF IFTE
input j DUP SUB
seps OVER POS ::DROP IFT
1 FC? ::+ IFT
'''NEXT'''
» » '<span style="color:blue">TOKNZ</span>' STO <span style="color:grey">''@ ("input" "seps" → { "tokens" } )''</span>
« RCL →STR " /n" <span style="color:blue">TOKNZ</span> → tokens <span style="color:grey">''@ "/n" means "new line" character ''</span>
« { { 0 "" } }
1 tokens SIZE '''FOR''' j
tokens j GET "'" SWAP OVER + +
'''IFERR''' STR→ '''THEN'''
2 OVER SIZE 1 - SUB
'''IF''' "{}][()" OVER POS <span style="color:grey">''@ exclude separators from the count''</span>
'''THEN''' DROP
'''ELSE'''
OVER 1 « 2 GET » DOLIST
'''IF''' OVER POS
'''THEN''' LASTARG SWAP DROP DUP2 GET { 1 "" } ADD PUT
'''ELSE''' 1 SWAP 2 →LIST 1 →LIST + END
'''ELSE''' DROP '''END'''
'''END'''
'''NEXT'''
SORT REVLIST 1 10 SUB
1 « EVAL →TAG » DOLIST
» » '<span style="color:blue">FNFREQ</span>' STO <span style="color:grey">''@ ( 'program' → { :word: occ .. :word: occ } ''</span>
 
'<span style="color:blue">FNFREQ</span>' <span style="color:blue">FNFREQ</span>
{{out}}
<pre>
1: { :OVER: 5 :»: 4 :«: 4 :END: 3 :ELSE: 3 :DROP: 3 :THEN: 3 :+: 3 :SWAP: 3 :GET: 3 }
</pre>
 
=={{header|Sidef}}==
Line 2,202 ⟶ 2,282:
 
In the absence of any other feasible approach, we simply search for method/function calls in a given Wren source file and count them to find the 'top ten'.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "os" for Process
import "./pattern" for Pattern
import "./set" for Bag
import "./sort" for Sort
import "./fmt" for Fmt
 
var args = Process.arguments
2,148

edits