(defn foo [x]
(println (if (string? x) x "Nothing.")))
(foo "Hello, world!")
(foo 42)
void foo<T>(T x)
{
if (x is string s)
{
Console.WriteLine(s);
}
else
{
Console.WriteLine("Nothing.");
}
}
foo("Hello, world!");
foo(42);
void foo(object x)
{
if (x is string s)
{
Console.WriteLine(s);
}
else
{
Console.WriteLine("Nothing.");
}
}
foo("Hello, world!");
foo(42);
foo(x) => print(x is String ? x : 'Nothing.');
foo('Hello, world!');
foo(42);
program main
call foo("Hello, world!")
call foo(42)
contains
subroutine foo(x)
class(*), intent(in) :: x
select type(x)
type is (character(len=*))
write (*,'(A)') x
class default
write (*,'(A)') "Nothing."
end select
end subroutine foo
end program main
func foo(x any) {
if s, ok := x.(string); ok {
fmt.Println(s)
} else {
fmt.Println("Nothing.")
}
}
func main() {
foo("Hello, world!")
foo(42)
}
function foo(x) {
console.log(typeof x == 'string' ? x : 'Nothing.')
}
foo('Hello, world!')
foo(42)
public static void main(String[] args) {
foo("Hello, world!");
foo(42);
}
private static void foo(Object x) {
if (x instanceof String) {
System.out.println(x);
} else {
System.out.println("Nothing.");
}
}
<T> void foo(T x) {
if (x instanceof String) out.println(x);
else out.println("Nothing.");
}
interface F<T> { void set(T x); }
F<Object> foo = x -> {
if (x instanceof String) out.println(x);
else out.println("Nothing.");
};
foo.set("Hello, world!");
foo.set(42);
procedure foo(const x: variant);
begin
case (TVarData(x).vType and varTypeMask) of
varOleStr, varUString, varString: writeln(x);
otherwise writeln('Nothing');
end;
end;
begin
foo('Hello World');
foo(42);
end.
sub foo {
my ($x) = @_;
return 'Nothing' if ref $x ne '' or looks_like_number($x);
return $x;
}
$\ = "\n"; # print with newline
say foo( [] );
say foo( 42 );
say foo( 'Hello World' );
sub foo {
my ($s, $x) = @_;
return 'is undefined' if not defined $x;
return 'is a reference' if ref $x ne '';
return 'is a number' if looks_like_number $s;
return 'is a string';
}
def foo(x):
if isinstance(x, str):
print(x)
else:
print('Nothing.')
return
foo('Hello, world!')
foo(42)
foo = lambda x: \
print(x if type(x) is str else 'Nothing.')
foo('Hello, world!')
foo(42)
def foo(x)
puts x.class == String ? x : "Nothing"
end
foo("Hello, world")
foo(42)
fn foo(x: &dyn Any) {
if let Some(s) = x.downcast_ref::<String>() {
println!("{}", s);
} else {
println!("Nothing")
}
}
fn main() {
foo(&"Hello, world!".to_owned());
foo(&42);
}
(define (foo x)
(displayln
(if (string? x)
x
"Nothing")))
(foo "Hello, world!")
(foo 42)