Introspection: Difference between revisions

Content added Content deleted
m (→‎{{header|Retro}}: update for retro12)
Line 1,776: Line 1,776:


=={{header|Retro}}==
=={{header|Retro}}==
This will exit if the minor version is less than 3:
This will exit if the version is less than 2019.6:


<lang Retro>version ^strings'splitAtChar: . drop toNumber 3 < &bye ifTrue</lang>
<lang Retro>@Version #201906 lt+ &bye if</lang>


The existance of functions can be checked using '''d:lookup'''. In this, a helper function is provided to improve readability.
A better way is to check the build number. This will exit if the build is lower than
the 11.0 release:


<lang Retro>build toNumber 1309798464 < &bye ifTrue</lang>
<lang Retro>
Checks for existance of "bloop" and "n:abs"


~~~
The existance of functions can be checked using find. In this, a helper function is provided to improve readability.
: executeByName (s-)

d:lookup [ d:xt fetch ] [ d:class fetch ] bi call ;
<lang Retro>
( Checks for existance of "bloop" and "abs" )
: executeByName ( $- )
find drop [ @d->xt ] [ @d->class ] bi withClass ;


"bloop" "abs" [ find nip ] bi@ and
'bloop 'n:abs [ find nip ] bi@ and
[ "bloop" executeByName "abs" executeByName ] ifTrue</lang>
[ 'bloop executeByName 'n:abs executeByName ] if
~~~</lang>


Retro has no direct way to check for data types of functions. Assuming that a word class is defined for integer variables, we could do something like this:
Retro has no direct way to check for data types of functions. Assuming that a word class is defined for integer variables, we could do something like this:


<lang Retro>
<lang Retro>
0 0 last [ dup @d->class &.integer = [ @d->xt @ + [ 1+ ] dip ] [ drop ] if ] ^types'LIST each@
#0 #0 [ dup d:class fetch &class:integer eq? [ d:xt fetch + [ n:inc ] dip ] [ drop ] choose ] d:for-each
</lang>
</lang>