Starting a web browser: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 5: Line 5:
Write the code which automatically opens a web page in a browser showing the addresses.
Write the code which automatically opens a web page in a browser showing the addresses.
<em>No static data must be shown, only processed data.</em>
<em>No static data must be shown, only processed data.</em>



=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
Line 256: Line 255:
Similar to the Perl 6 entry.
Similar to the Perl 6 entry.
</pre>
</pre>



=={{header|Julia}}==
=={{header|Julia}}==
Line 443: Line 441:
</table>
</table>


=={{header|Perl 6}}==
=={{header|Phix}}==
<lang Phix>constant addresses = {"Plataanstraat 5",
"Straat 12",
"Straat 12 II",
"Dr. J. Straat 12",
"Dr. J. Straat 12 a",
"Dr. J. Straat 12-14",
"Laan 1940 - 1945 37",
"Plein 1940 2",
"1213-laan 11",
"16 april 1944 Pad 1",
"1e Kruisweg 36",
"Laan 1940-'45 66",
"Laan '40-'45",
"Langeloërduinen 3 46",
"Marienwaerdt 2e Dreef 2",
"Provincialeweg N205 1",
"Rivium 2e Straat 59.",
"Nieuwe gracht 20rd",
"Nieuwe gracht 20rd 2",
"Nieuwe gracht 20zw /2",
"Nieuwe gracht 20zw/3",
"Nieuwe gracht 20 zw/4",
"Bahnhofstr. 4",
"Wertstr. 10",
"Lindenhof 1",
"Nordesch 20",
"Weilstr. 6",
"Harthauer Weg 2",
"Mainaustr. 49",
"August-Horch-Str. 3",
"Marktplatz 31",
"Schmidener Weg 3",
"Karl-Weysser-Str. 6"}

function isDigit(integer ch)
return ch>='0' and ch<='9'
end function
function separateHouseNumber(integer i)
string address = addresses[i]
sequence parts = split(address,no_empty:=true)
string street, house
integer h = 0
if length(parts)>1 then
string last = parts[$]
if isDigit(last[1]) then
h = 1
string penult = parts[$-1]
if length(parts)>2
and isDigit(penult[1])
and match("194",penult)!=1 then
h = 2
end if
elsif length(parts)>2 then
h = 2
end if
end if
if h then
street = join(parts[1..$-h])
house = join(parts[$-h+1..$])
else
street = join(parts)
house = "(none)"
end if
string colour = iff(mod(i,2)=0?"#d7fffe":"#9dbcd4")
return {colour,address,street,house}
end function
constant html_hdr = """
<html>
<head>
<title>Rosetta Code - Start a Web Browser</title>
<meta charset="UTF-8">
</head>
<body bgcolor="#d8dcd6">
<p align="center">
<font face="Arial, sans-serif" size="5">Split the house number from the street name</font>
</p>
<p align="center">
<table border="2"> <tr bgcolor="#02ccfe">
<th>Address</th><th>Street</th><th>House Number</th>
""",
html_line = """
<tr bgcolor=%s><td>%s</td><td>%s</td><td>%s</td></tr>
""",
html_ftr = """
</table>
</p>
</body>
</html>
"""

procedure main()
integer fn = open("test.html","w")
printf(fn,html_hdr)
for i=1 to length(addresses) do
printf(fn,html_line,separateHouseNumber(i))
end for
printf(fn,html_ftr)
close(fn)
system("test.html")
end procedure
main()</lang>
output as perl

=={{header|Racket}}==

<lang racket>
#lang at-exp racket

... same code as "Separate_the_house_number_from_the_street_name" ...

(require net/sendurl scribble/html)

(define (render-table)
(for/list ([str (in-list (string-split adressen #rx" *\r?\n *"))]
[i (in-naturals)])
(tr bgcolor: (if (even? i) "#fcf" "#cff")
(td str)
(map td (cond [(splits-adressen str) => cdr] [else '(??? ???)])))))

@(compose1 send-url/contents xml->string){
@html{@head{@title{Splitting Results}}
@body{@h1{Splitting Results}
@table{@render-table}}}
}
</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2017.09}}
{{works with|Rakudo|2017.09}}
Uses the code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task almost verbatim. Included here to make a complete, runnable example.
Uses the code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task almost verbatim. Included here to make a complete, runnable example.
Line 582: Line 710:
<tr bgcolor="#d7fffe"><td>Karl-Weysser-Str. 6</td><td>Karl-Weysser-Str.</td><td>6</td></tr>
<tr bgcolor="#d7fffe"><td>Karl-Weysser-Str. 6</td><td>Karl-Weysser-Str.</td><td>6</td></tr>
</table>
</table>

=={{header|Phix}}==
<lang Phix>constant addresses = {"Plataanstraat 5",
"Straat 12",
"Straat 12 II",
"Dr. J. Straat 12",
"Dr. J. Straat 12 a",
"Dr. J. Straat 12-14",
"Laan 1940 - 1945 37",
"Plein 1940 2",
"1213-laan 11",
"16 april 1944 Pad 1",
"1e Kruisweg 36",
"Laan 1940-'45 66",
"Laan '40-'45",
"Langeloërduinen 3 46",
"Marienwaerdt 2e Dreef 2",
"Provincialeweg N205 1",
"Rivium 2e Straat 59.",
"Nieuwe gracht 20rd",
"Nieuwe gracht 20rd 2",
"Nieuwe gracht 20zw /2",
"Nieuwe gracht 20zw/3",
"Nieuwe gracht 20 zw/4",
"Bahnhofstr. 4",
"Wertstr. 10",
"Lindenhof 1",
"Nordesch 20",
"Weilstr. 6",
"Harthauer Weg 2",
"Mainaustr. 49",
"August-Horch-Str. 3",
"Marktplatz 31",
"Schmidener Weg 3",
"Karl-Weysser-Str. 6"}

function isDigit(integer ch)
return ch>='0' and ch<='9'
end function
function separateHouseNumber(integer i)
string address = addresses[i]
sequence parts = split(address,no_empty:=true)
string street, house
integer h = 0
if length(parts)>1 then
string last = parts[$]
if isDigit(last[1]) then
h = 1
string penult = parts[$-1]
if length(parts)>2
and isDigit(penult[1])
and match("194",penult)!=1 then
h = 2
end if
elsif length(parts)>2 then
h = 2
end if
end if
if h then
street = join(parts[1..$-h])
house = join(parts[$-h+1..$])
else
street = join(parts)
house = "(none)"
end if
string colour = iff(mod(i,2)=0?"#d7fffe":"#9dbcd4")
return {colour,address,street,house}
end function
constant html_hdr = """
<html>
<head>
<title>Rosetta Code - Start a Web Browser</title>
<meta charset="UTF-8">
</head>
<body bgcolor="#d8dcd6">
<p align="center">
<font face="Arial, sans-serif" size="5">Split the house number from the street name</font>
</p>
<p align="center">
<table border="2"> <tr bgcolor="#02ccfe">
<th>Address</th><th>Street</th><th>House Number</th>
""",
html_line = """
<tr bgcolor=%s><td>%s</td><td>%s</td><td>%s</td></tr>
""",
html_ftr = """
</table>
</p>
</body>
</html>
"""

procedure main()
integer fn = open("test.html","w")
printf(fn,html_hdr)
for i=1 to length(addresses) do
printf(fn,html_line,separateHouseNumber(i))
end for
printf(fn,html_ftr)
close(fn)
system("test.html")
end procedure
main()</lang>
output as perl

=={{header|Racket}}==

<lang racket>
#lang at-exp racket

... same code as "Separate_the_house_number_from_the_street_name" ...

(require net/sendurl scribble/html)

(define (render-table)
(for/list ([str (in-list (string-split adressen #rx" *\r?\n *"))]
[i (in-naturals)])
(tr bgcolor: (if (even? i) "#fcf" "#cff")
(td str)
(map td (cond [(splits-adressen str) => cdr] [else '(??? ???)])))))

@(compose1 send-url/contents xml->string){
@html{@head{@title{Splitting Results}}
@body{@h1{Splitting Results}
@table{@render-table}}}
}
</lang>


=={{header|Scala}}==
=={{header|Scala}}==