Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
10
Task/Null-object/ALGOL-W/null-object.alg
Normal file
10
Task/Null-object/ALGOL-W/null-object.alg
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
begin
|
||||
% declare a record type - will be accessed via references %
|
||||
record R( integer f1, f2, f3 );
|
||||
% declare a reference to a R instance %
|
||||
reference(R) refR;
|
||||
% assign null to the reference %
|
||||
refR := null;
|
||||
% test for a null reference - will write "refR is null" %
|
||||
if refR = null then write( "refR is null" ) else write( "not null" );
|
||||
end.
|
||||
3
Task/Null-object/Bracmat/null-object.bracmat
Normal file
3
Task/Null-object/Bracmat/null-object.bracmat
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
a:?x*a*?z {assigns 1 to x and to z}
|
||||
a:?x+a+?z {assigns 0 to x and to z}
|
||||
a:?x a ?z {assigns "" (or (), which is equivalent) to x and to z}
|
||||
4
Task/Null-object/Elixir/null-object-1.elixir
Normal file
4
Task/Null-object/Elixir/null-object-1.elixir
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
iex(1)> nil == :nil
|
||||
true
|
||||
iex(2)> is_nil(nil)
|
||||
true
|
||||
2
Task/Null-object/Elixir/null-object-2.elixir
Normal file
2
Task/Null-object/Elixir/null-object-2.elixir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
iex(3)> if nil, do: "not execute"
|
||||
nil
|
||||
|
|
@ -5,3 +5,6 @@ puts "$object is nil" if $object.nil? # global variable, too
|
|||
# It recognizes as the local variable even if it isn't executed.
|
||||
object = 1 if false
|
||||
puts "object is nil" if object.nil?
|
||||
|
||||
# nil itself is an object:
|
||||
puts nil.class # => NilClass
|
||||
|
|
|
|||
20
Task/Null-object/Rust/null-object.rust
Normal file
20
Task/Null-object/Rust/null-object.rust
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// If an option may return null - or nothing - in Rust, it's wrapped
|
||||
// in an Optional which may return either the type of object specified
|
||||
// in <> or None. We can check this using .is_some() and .is_none() on
|
||||
// the Option.
|
||||
|
||||
fn check_number(num: &Option<u8>) {
|
||||
if num.is_none() {
|
||||
println!("Number is: None");
|
||||
} else {
|
||||
println!("Number is: {}", num.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut possible_number: Option<u8> = None;
|
||||
check_number(&possible_number);
|
||||
|
||||
possible_number = Some(31);
|
||||
check_number(&possible_number);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue