Introspection: Difference between revisions
Content added Content deleted
No edit summary |
m (→[[E]]: Split off Forth section) |
||
Line 41: | Line 41: | ||
x.abs() |
x.abs() |
||
} |
} |
||
==[[Forth]]== |
|||
[[Category:Forth]] |
Revision as of 16:02, 6 April 2007
Introspection
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
This task asks to
- verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
- check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop).
Perl
Interpreter: Perl 5.x
require v5.6.1; # run time version check require 5.6.1; # ditto require 5.006_001; # ditto; preferred for backwards compatibility
Ruby
puts RUBY_VERSION # print the version of the interpreter puts "abs is available" if 42.respond_to?(:abs)
Tcl
package require Tcl 8.2 ; # throws an error if older if {[info exists bloop] && [llength [info functions abs]]} { puts [expr abs($bloop)] }
E
def version := interp.getProps()["e.version"]
(There is no built-in version comparison, and the author of this example assumes that implementing a version comparison algorithm isn't the point of this task.)
escape fail { def &x := meta.getState().fetch("&bloop", fn { fail("no bloop") }) if (!x.__respondsTo("abs", 0)) { fail("no abs") } x.abs() }