Map can also be used to permute strings. Consider:
map("0123456789","0516273849",s) where s is any 10 character string
see https://www.cs.arizona.edu/icon/ftp/doc/tr78_15.pdf
David
From: Jay Hammond <[email protected]>
To: John Sampson <[email protected]>; [email protected]
Sent: Monday, May 30, 2016 6:20 PM
Subject: Re: [Unicon-group] Convert string to lowercase
Yes caveats: my (un)icon says it is ASCII in &features. answer: map does it.
the unicon book (p 40) in the 2014 edition has a function
map(string,select,replacements) (I named the 3 parameters) the 2nd parameter
defaults to the ordered string of uppercase characters i.e. ABCD .. XYZ
the 3rd parameter defaults to the ordered string of lowercase characters
i.e. abcd .. xyz Example
map("MyMixed Case String",,)
# the commas are optional
Map looks at the characters in parameter1, and if any match those in
parameter2, they are replaced by the equivalent ones in parameter 3. e.g 'M'
in "My" and "Mixed" is replaced each time by 'm', 'C' in "Case" is replaced
by 'c' and 'S' in "String" is replaced by 's'. You can get other helpful
effects if you don't use the defaults. toupper(string) is
map(string,&lcase,&ucase)
hth Jay Hammond
here is p40 Listing 3-1
A simple concordance program
procedure main(args)
(*args = 1) | stop("Need a file!")
f := open(args[1]) | stop("Couldn't open ", args[1])
wordlist := table()
lineno := 0
while line := map(read(f)) do {
lineno +:= 1
every word := getword(line) do
if *word > 3 then {
# if word isn't in the table, set entry to empty list
/wordlist[word] := list()
put(wordlist[word], lineno)
}
}
L := sort(wordlist)
every l := !L do {
writes(l[1], "\t")
linelist := ""
# Collect line numbers into a string
every linelist ||:= (!l[2] || ", ")
# trim the final ", "
write(linelist[1:-2])
}
end
procedure getword(s)
s ? while tab(upto(&letters)) do {
word := tab(many(&letters))
suspend word
}
end If we run this program on this input:
Half a league, half a league,
Half a league onward,
All in the valley of Death
Rode the six hundred. the program writes this output:
death 3
half 1, 2
hundred 4
league 1, 1, 2
onward 2
rode 4
valley 3 First, note that the main() procedure requires a command-line
argument, the name of a file to open. Also, we pass all the lines read
through the function map(). This is a function that takes three arguments,
the first being the string to map; and the second and third specifying how
the string should be mapped on a character by character basis. The defaults
for the second and third arguments are the uppercase letters and the
lowercase letters, respectively; therefore, the call to map() converts the
line just read in to all lowercase.
On 30/05/2016 20:18, John Sampson wrote:
Does Unicon have the equivalent of Python's "lower" method, to convert a
string from uppercase to lowercase?
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group