Rosetta Code/Run examples: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: use common code)
m (syntax highlighting fixup automation)
Line 26:
 
No attempt has been at 'extra credit' which would take all day for Go alone and 'more credit' seems pointless as program output is seldom, if ever, exactly the same for all languages.
<langsyntaxhighlight lang="go">package main
 
import (
Line 155:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 342:
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
' ********************************************************************
' ** **
Line 584:
GetTempPath$ = buf$
End Function
</syntaxhighlight>
</lang>
 
 
Line 597:
The present program must be compiled with option <code>-d:ssl</code>
 
<langsyntaxhighlight Nimlang="nim">import htmlparser, httpclient, os, osproc, re, sets, strutils, xmltree
 
const
Line 687:
answer = stdin.readLine()
if answer notin ["y", "Y"]:
break</langsyntaxhighlight>
 
=={{header|Phix}}==
Screenshot [http://phix.x10.mx/run_examples.png here]
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Run_examples.exw
Line 1,344:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Raku}}==
Line 1,365:
Note: This is set up to run under Linux. It could be adapted for Windows (or OSX I suppose) fairly easily but I don't have access to those OSs, nor do I care to seek it.
 
<syntaxhighlight lang="raku" perl6line>use HTTP::UserAgent;
use URI::Escape;
use JSON::Fast;
Line 1,677:
# note that this tag only selects the syntax highlighting, continue to
# use 'perl6' until 'raku' as added on the site.
tag => rx/<?after '<langsyntaxhighlight lang="' 'perl6' '">' > .*? <?before '</' 'lang>'>/,
) }
 
Line 1,686:
dir => 'perl',
header => 'Perl',
tag => rx/:i <?after '<langsyntaxhighlight lang="' 'perl' '">' > .*? <?before '</' 'lang>'>/,
) }
 
Line 1,695:
dir => 'python',
header => 'Python',
tag => rx/:i <?after '<langsyntaxhighlight lang="' 'python' '">' > .*? <?before '</' 'lang>'>/,
) }
 
Line 1,704:
dir => 'go',
header => 'Go',
tag => rx/:i <?after '<langsyntaxhighlight lang="' 'go' '">' > .*? <?before '</' 'lang>'>/,
) }
 
Line 1,713:
dir => 'tcl',
header => 'Tcl',
tag => rx/:i <?after '<langsyntaxhighlight lang="' 'tcl' '">' > .*? <?before '</' 'lang>'>/,
) }
 
multi load-lang ($unknown) { die "Sorry, don't know how to handle $unknown language." };
 
multi load-resources ($unknown) { () };</langsyntaxhighlight>
 
{{out}} with command line: '''raku RC-run.p6 -q "Determine if a string is numeric"'''
Line 1,825:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">bf$ = "<SPAN STYLE='font-family:Arial; font-weight:700; font-size:12pt'>"
a$ = httpGet$("http://rosettacode.org/wiki/Category:Run_BASIC") ' get RB tasks from [RC]
a1$ = word$(a$,2,"Pages in category ""Run BASIC")
Line 1,905:
i = i + 1
WEND
END FUNCTION</langsyntaxhighlight>
 
=={{header|Tcl}}==
This code only includes support for running Tcl task solutions, but it can download any language's; it assumes that the first <nowiki><lang…></nowiki> is sufficient when it comes to task extraction (definitely not true universally, but mostly good enough).
{{tcllib|uri}}
<langsyntaxhighlight lang="tcl"># Code to download task contents from find-bare-lang-tags task
package require Tcl 8.5
package require http
Line 1,938:
}
 
# Code to extract the first <syntaxhighlight lang="text"> section for a language
proc getTaskCodeForLanguage {task language} {
set content [getTaskContent $task]
Line 1,951:
}
set content [string range $content [lindex $start 1] [lindex $end 0]]
# Extended format RE used to allow embedding within _this_ task's <syntaxhighlight lang="text">!
if {![regexp {(?x)<langsyntaxhighlight lang=".*?">(.*?)</ lang>} $content -> solution]} {
error "$language solution of task \"$task\" has no useful code"
}
Line 1,969:
exec [info nameofexecutable] $filename <@stdin >@stdout 2>@stderr
}
runTclTaskForLanguage {*}$argv</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
Line 1,987:
 
However, no attempt has been made - at least for now - to run other embedded programs (which can be identified by the presence of the 'foreign' keyword) due to a number of technical difficulties in doing so.
<langsyntaxhighlight lang="ecmascript">/* rc_run_examples.wren */
 
import "./set" for Set
Line 2,075:
var fileName = "rc_temp." + ext
var p1 = Pattern.new("/=/={{header/|%(lang2)}}/=/=")
var p2 = Pattern.new("<langsyntaxhighlight lang="%(lang3)">")
var p3 = Pattern.new("<//lang>")
var s = p1.split(page, 1, 0)
Line 2,120:
if (yn != "y" && yn != "Y") return
}
}</langsyntaxhighlight>
We now embed this script in the following Go program and run it:
<langsyntaxhighlight lang="go">/* go run rc_run_examples.go */
 
package main
Line 2,250:
vm.InterpretFile(fileName)
vm.Free()
}</langsyntaxhighlight>
 
{{out}}
10,327

edits