Introspection: Difference between revisions

Content deleted Content added
Added C++
Thundergnat (talk | contribs)
Rename Perl 6 -> Raku, alphabetize, minor clean-up
Line 88:
There are 3 integer variables in the global scope
Their sum is 1936
 
 
 
=={{header|ALGOL 68}}==
Line 227 ⟶ 225:
if IsFunc("abs")
MsgBox % abs(bloop)
return</lang>
 
=={{header|AWK}}==
Line 296 ⟶ 294:
doing this kind of check in a shell script and defining symbols
such as HAVE_ABS which ''can'' be checked by the preprocessor.
=={{header|C++}}==
Identifying the version of the C++ standard used by the compiler in C++ is syntactically very similar to the way of checking the C standard version (also seen on this page).
 
<lang cpp>#if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
// ...
#endif</lang>
 
As in C, the introspective capabilities of C++ are very limited.
=={{header|C sharp|C#}}==
There has to be some caveats made with C#. There are no truly "global" variables - just publicly exported ones from individual classes/types. I chose to make a couple of public static variables in my program's class. Also, the "version" of the compiler is difficult to impossible to get at. There are no predefined compiler constants that can be compared against as in C/C++ but then again, it's hardly the thing that counts in C#. What really counts is the version of .NET and the framework you're working with since that determines what C++ features you can use and the various calls that can be made. Consequently, I check the .NET version to make sure it's past 4.0 and exit if not.
Line 394 ⟶ 383:
<pre>bloop's abs value = 10
2 exported ints which total to -30</pre>
 
=={{header|C++}}==
Identifying the version of the C++ standard used by the compiler in C++ is syntactically very similar to the way of checking the C standard version (also seen on this page).
 
<lang cpp>#if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
// ...
#endif</lang>
 
As in C, the introspective capabilities of C++ are very limited.
 
=={{header|Clojure}}==
Line 410:
(throw (Error. "Bad version"))))
</lang>
 
 
=={{header|Common Lisp}}==
Line 1,543 ⟶ 1,542:
4 integers, sum = 74717
</pre>
 
=={{header|Perl 6}}==
<lang perl6>use v6; # require Perl 6
 
my $bloop = -123;
 
if MY::{'$bloop'}.defined and CORE::{'&abs'}.defined { say abs $bloop }
 
my @ints = ($_ when Int for PROCESS::.values);
say "Number of PROCESS vars of type Int: ", +@ints;
say "PROCESS vars of type Int add up to ", [+] @ints;</lang>
{{out}}
<pre>123
Number of PROCESS vars of type Int: 1
PROCESS vars of type Int add up to 28785</pre>
Obviously Perl 6 doesn't maintain a lot of global integer variables... <tt>:-)</tt>
 
Nevertheless, you can use similar code to access all the variables in any package you like,
such as the GLOBAL package, which typically has absolutely nothing in it. Since the PROCESS package is even more global than GLOBAL, we used that instead. Go figure...
 
=={{header|Phix}}==
Line 1,939 ⟶ 1,919:
(unless (version<=? "5.3" (version)) (error "ancient version"))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>use v6; # require Perl 6
 
my $bloop = -123;
 
if MY::{'$bloop'}.defined and CORE::{'&abs'}.defined { say abs $bloop }
 
my @ints = ($_ when Int for PROCESS::.values);
say "Number of PROCESS vars of type Int: ", +@ints;
say "PROCESS vars of type Int add up to ", [+] @ints;</lang>
{{out}}
<pre>123
Number of PROCESS vars of type Int: 1
PROCESS vars of type Int add up to 28785</pre>
Obviously Perl 6 doesn't maintain a lot of global integer variables... <tt>:-)</tt>
 
Nevertheless, you can use similar code to access all the variables in any package you like,
such as the GLOBAL package, which typically has absolutely nothing in it. Since the PROCESS package is even more global than GLOBAL, we used that instead. Go figure...
 
=={{header|Raven}}==
Line 1,946:
'bloop' GLOBAL keys in && 'abs' CORE keys in
if bloop abs print</lang>
 
 
=={{header|Retro}}==
Line 2,107 ⟶ 2,106:
if (bloop.isDefined) bloop.get.abs
}</lang>
 
=={{header|Slate}}==
No version string included inside the system presently.