tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
5
Task/Null-object/0DESCRIPTION
Normal file
5
Task/Null-object/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
'''Null''' (or '''nil''') is the computer science concept of an undefined or unbound object. Some languages have an explicit way to access the null object, and some don't. Some languages distinguish the null object from [[undefined values]], and some don't.
|
||||
|
||||
Show how to access null in your language by checking to see if an object is equivalent to the null object.
|
||||
|
||||
''This task is not about whether a variable is defined. The task is about "null"-like values in various languages, which may or may not be related to the defined-ness of variables in your language.''
|
||||
2
Task/Null-object/1META.yaml
Normal file
2
Task/Null-object/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Basic language learning
|
||||
19
Task/Null-object/ALGOL-68/null-object.alg
Normal file
19
Task/Null-object/ALGOL-68/null-object.alg
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
REF STRING no result = NIL;
|
||||
STRING result := "";
|
||||
|
||||
IF no result :=: NIL THEN print(("no result :=: NIL", new line)) FI;
|
||||
IF result :/=: NIL THEN print(("result :/=: NIL", new line)) FI;
|
||||
|
||||
IF no result IS NIL THEN print(("no result IS NIL", new line)) FI;
|
||||
IF result ISNT NIL THEN print(("result ISNT NIL", new line)) FI;
|
||||
|
||||
COMMENT using the UNESCO/IFIP/WG2.1 ALGOL 68 character set
|
||||
result := °;
|
||||
IF REF STRING(result) :≠: ° THEN print(("result ≠ °", new line)) FI;
|
||||
END COMMENT
|
||||
|
||||
# Note the following gotcha: #
|
||||
|
||||
REF STRING var := NIL;
|
||||
IF var ISNT NIL THEN print(("The address of var ISNT NIL",new line)) FI;
|
||||
IF var IS REF STRING(NIL) THEN print(("The address of var IS REF STRING(NIL)",new line)) FI
|
||||
2
Task/Null-object/ActionScript/null-object.as
Normal file
2
Task/Null-object/ActionScript/null-object.as
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
if (object == null)
|
||||
trace("object is null");
|
||||
5
Task/Null-object/Ada/null-object.ada
Normal file
5
Task/Null-object/Ada/null-object.ada
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
with Ada.Text_Io;
|
||||
|
||||
if Object = null then
|
||||
Ada.Text_Io.Put_line("object is null");
|
||||
end if;
|
||||
5
Task/Null-object/AmigaE/null-object.amiga
Normal file
5
Task/Null-object/AmigaE/null-object.amiga
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
DEF x : PTR TO object
|
||||
-> ...
|
||||
IF object <> NIL
|
||||
-> ...
|
||||
ENDIF
|
||||
7
Task/Null-object/AppleScript/null-object.applescript
Normal file
7
Task/Null-object/AppleScript/null-object.applescript
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
if x is missing value then
|
||||
display dialog "x is missing value"
|
||||
end if
|
||||
|
||||
if x is null then
|
||||
display dialog "x is null"
|
||||
end if
|
||||
2
Task/Null-object/AutoHotkey/null-object.ahk
Normal file
2
Task/Null-object/AutoHotkey/null-object.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
If (object == null)
|
||||
MsgBox, object is null
|
||||
13
Task/Null-object/BBC-BASIC/null-object.bbc
Normal file
13
Task/Null-object/BBC-BASIC/null-object.bbc
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
PROCtestobjects
|
||||
END
|
||||
|
||||
DEF PROCtestobjects
|
||||
PRIVATE a(), b(), s{}, t{}
|
||||
DIM a(123)
|
||||
DIM s{a%, b#, c$}
|
||||
|
||||
IF !^a() <= 1 PRINT "a() is null" ELSE PRINT "a() is not null"
|
||||
IF !^b() <= 1 PRINT "b() is null" ELSE PRINT "b() is not null"
|
||||
IF !^s{} <= 1 PRINT "s{} is null" ELSE PRINT "s{} is not null"
|
||||
IF !^t{} <= 1 PRINT "t{} is null" ELSE PRINT "t{} is not null"
|
||||
ENDPROC
|
||||
1
Task/Null-object/Babel/null-object.pb
Normal file
1
Task/Null-object/Babel/null-object.pb
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ nil { nil? } { "Whew!\n" } { "Something is terribly wrong!\n" } ifte << }
|
||||
5
Task/Null-object/C++/null-object-1.cpp
Normal file
5
Task/Null-object/C++/null-object-1.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
if (object == 0) {
|
||||
std::cout << "object is null";
|
||||
}
|
||||
12
Task/Null-object/C++/null-object-2.cpp
Normal file
12
Task/Null-object/C++/null-object-2.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include <boost/optional.hpp>
|
||||
#include <iostream>
|
||||
|
||||
boost::optional<int> maybeInt()
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::optional<int> maybe = maybeInt();
|
||||
|
||||
if(!maybe)
|
||||
std::cout << "object is null\n";
|
||||
}
|
||||
11
Task/Null-object/C/null-object.c
Normal file
11
Task/Null-object/C/null-object.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char *object = 0;
|
||||
|
||||
if (object == NULL) {
|
||||
puts("object is null");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
2
Task/Null-object/Clojure/null-object-1.clj
Normal file
2
Task/Null-object/Clojure/null-object-1.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(let [x nil]
|
||||
(println "Object is" (if (nil? x) "nil" "not nil")))
|
||||
1
Task/Null-object/Clojure/null-object-2.clj
Normal file
1
Task/Null-object/Clojure/null-object-2.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(find (ns-interns *ns*) 'foo)
|
||||
1
Task/Null-object/Clojure/null-object-3.clj
Normal file
1
Task/Null-object/Clojure/null-object-3.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(ns-unmap *ns* 'foo)
|
||||
1
Task/Null-object/Common-Lisp/null-object-1.lisp
Normal file
1
Task/Null-object/Common-Lisp/null-object-1.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(if (condition) (do-this))
|
||||
5
Task/Null-object/Common-Lisp/null-object-2.lisp
Normal file
5
Task/Null-object/Common-Lisp/null-object-2.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defmethod car* ((arg cons))
|
||||
(car arg))
|
||||
|
||||
(defmethod car* ((arg null))
|
||||
nil)
|
||||
2
Task/Null-object/Common-Lisp/null-object-3.lisp
Normal file
2
Task/Null-object/Common-Lisp/null-object-3.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defmethod car* ((arg t)) ;; can just be written (defmethod car* (arg) ...)
|
||||
(error "CAR*: ~s is neither a cons nor nil" arg))
|
||||
17
Task/Null-object/Component-Pascal/null-object.component
Normal file
17
Task/Null-object/Component-Pascal/null-object.component
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
MODULE ObjectNil;
|
||||
IMPORT StdLog;
|
||||
TYPE
|
||||
Object = POINTER TO ObjectDesc;
|
||||
ObjectDesc = RECORD
|
||||
END;
|
||||
VAR
|
||||
x: Object; (* default initialization to NIL *)
|
||||
|
||||
PROCEDURE DoIt*;
|
||||
BEGIN
|
||||
IF x = NIL THEN
|
||||
StdLog.String("x is NIL");StdLog.Ln
|
||||
END
|
||||
END DoIt;
|
||||
|
||||
END ObjectNil.
|
||||
12
Task/Null-object/D/null-object.d
Normal file
12
Task/Null-object/D/null-object.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import std.stdio;
|
||||
|
||||
class K {}
|
||||
|
||||
void main() {
|
||||
K k;
|
||||
if (k is null)
|
||||
writeln("k is null");
|
||||
k = new K;
|
||||
if (k !is null)
|
||||
writeln("Now k is not null");
|
||||
}
|
||||
6
Task/Null-object/Delphi/null-object.delphi
Normal file
6
Task/Null-object/Delphi/null-object.delphi
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// the following are equivalent
|
||||
if lObject = nil then
|
||||
...
|
||||
|
||||
if not Assigned(lObject) then
|
||||
...
|
||||
1
Task/Null-object/E/null-object.e
Normal file
1
Task/Null-object/E/null-object.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
object == null
|
||||
1
Task/Null-object/Factor/null-object.factor
Normal file
1
Task/Null-object/Factor/null-object.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
: is-f? ( obj -- ? ) f = ;
|
||||
7
Task/Null-object/Fantom/null-object.fantom
Normal file
7
Task/Null-object/Fantom/null-object.fantom
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fansh> x := null
|
||||
fansh> x == null
|
||||
true
|
||||
fansh> x = 1
|
||||
1
|
||||
fansh> x == null
|
||||
false
|
||||
21
Task/Null-object/Go/null-object.go
Normal file
21
Task/Null-object/Go/null-object.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
s []int // slice type
|
||||
p *int // pointer type
|
||||
f func() // function type
|
||||
i interface{} // interface type
|
||||
m map[int]int // map type
|
||||
c chan int // channel type
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(s == nil)
|
||||
fmt.Println(p == nil)
|
||||
fmt.Println(f == nil)
|
||||
fmt.Println(i == nil)
|
||||
fmt.Println(m == nil)
|
||||
fmt.Println(c == nil)
|
||||
}
|
||||
3
Task/Null-object/Haskell/null-object-1.hs
Normal file
3
Task/Null-object/Haskell/null-object-1.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
undefined -- undefined value provided by the standard library
|
||||
error "oops" -- another undefined value
|
||||
head [] -- undefined, you can't take the head of an empty list
|
||||
1
Task/Null-object/Haskell/null-object-2.hs
Normal file
1
Task/Null-object/Haskell/null-object-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
data Maybe a = Nothing | Just a
|
||||
3
Task/Null-object/Haskell/null-object-3.hs
Normal file
3
Task/Null-object/Haskell/null-object-3.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
case thing of
|
||||
Nothing -> "It's Nothing. Or null, whatever."
|
||||
Just v -> "It's not Nothing; it is " ++ show v ++ "."
|
||||
10
Task/Null-object/Icon/null-object.icon
Normal file
10
Task/Null-object/Icon/null-object.icon
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
procedure main()
|
||||
nulltest("a",a) # unassigned variables are null by default
|
||||
nulltest("b",b := &null) # explicit assignment is possible
|
||||
nulltest("c",c := "anything")
|
||||
nulltest("c",c := &null) # varibables can't be undefined
|
||||
end
|
||||
|
||||
procedure nulltest(name,var)
|
||||
return write(name, if /var then " is" else " is not"," null.")
|
||||
end
|
||||
1
Task/Null-object/Io/null-object.io
Normal file
1
Task/Null-object/Io/null-object.io
Normal file
|
|
@ -0,0 +1 @@
|
|||
if(object == nil, "object is nil" println)
|
||||
1
Task/Null-object/J/null-object-1.j
Normal file
1
Task/Null-object/J/null-object-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
isUndefined=: _1 = nc@boxxopen
|
||||
5
Task/Null-object/J/null-object-2.j
Normal file
5
Task/Null-object/J/null-object-2.j
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
isUndefined 'foo'
|
||||
1
|
||||
foo=:9
|
||||
isUndefined 'foo'
|
||||
0
|
||||
10
Task/Null-object/J/null-object-3.j
Normal file
10
Task/Null-object/J/null-object-3.j
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
1 1 0 1#3 4 _ 5
|
||||
3 4 5
|
||||
I.1 1 0 1
|
||||
0 1 3
|
||||
0 1 3 { 3 4 _ 5
|
||||
3 4 5
|
||||
1 1 0 1 #inv 3 4 5
|
||||
3 4 0 5
|
||||
1 1 0 1 #!._ inv 3 4 5
|
||||
3 4 _ 5
|
||||
4
Task/Null-object/Java/null-object.java
Normal file
4
Task/Null-object/Java/null-object.java
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// here "object" is a reference
|
||||
if (object == null) {
|
||||
System.out.println("object is null");
|
||||
}
|
||||
6
Task/Null-object/JavaScript/null-object.js
Normal file
6
Task/Null-object/JavaScript/null-object.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
if (object === null) {
|
||||
alert("object is null");
|
||||
// The object is nothing
|
||||
}
|
||||
|
||||
typeof null === "object"; // This stands since the beginning of JavaScript
|
||||
6
Task/Null-object/K/null-object.k
Normal file
6
Task/Null-object/K/null-object.k
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(1;;2) ~ (1 ; _n ; 2) / ~ is ''identical to'' or ''match'' .
|
||||
1
|
||||
_n ~' ( 1 ; ; 2 ) / ''match each''
|
||||
0 1 0
|
||||
|
||||
additional properties : _n@i and _n?i are i; _n`v is _n
|
||||
6
Task/Null-object/Logo/null-object.logo
Normal file
6
Task/Null-object/Logo/null-object.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
to test :thing
|
||||
if empty? :thing [print [list or word is empty]]
|
||||
end
|
||||
|
||||
print empty? [] ; true
|
||||
print empty? "|| ; true
|
||||
2
Task/Null-object/Lua/null-object.lua
Normal file
2
Task/Null-object/Lua/null-object.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
isnil = (object == nil)
|
||||
print(isnil)
|
||||
1
Task/Null-object/MAXScript/null-object.maxscript
Normal file
1
Task/Null-object/MAXScript/null-object.maxscript
Normal file
|
|
@ -0,0 +1 @@
|
|||
if obj == undefined then print "Obj is undefined"
|
||||
18
Task/Null-object/MUMPS/null-object.mumps
Normal file
18
Task/Null-object/MUMPS/null-object.mumps
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
CACHE>WRITE $DATA(VARI)
|
||||
0
|
||||
CACHE>SET VARI="HELLO" WRITE $DATA(VARI)
|
||||
1
|
||||
CACHE>NEW VARI WRITE $DATA(VARI) ;Change to a new scope
|
||||
0
|
||||
CACHE 1S1>SET VARI(1,2)="DOWN" WRITE $DATA(VARI)
|
||||
10
|
||||
CACHE 1S1>WRITE $DATA(VARI(1))
|
||||
10
|
||||
CACHE 1S1>WRITE $D(VARI(1,2))
|
||||
1
|
||||
CACHE 1S1>SET VARI(1)="UP" WRITE $DATA(VARI(1))
|
||||
11
|
||||
<CACHE 1S1>QUIT ;Leave the scope
|
||||
|
||||
<CACHE>W $DATA(VARI)," ",VARI
|
||||
1 HELLO
|
||||
1
Task/Null-object/Mathematica/null-object-1.math
Normal file
1
Task/Null-object/Mathematica/null-object-1.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
x=Null;
|
||||
3
Task/Null-object/Mathematica/null-object-2.math
Normal file
3
Task/Null-object/Mathematica/null-object-2.math
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
x =.
|
||||
x = (1 + 2;)
|
||||
FullForm[x]
|
||||
1
Task/Null-object/Mathematica/null-object-3.math
Normal file
1
Task/Null-object/Mathematica/null-object-3.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
SameQ[x,Null]
|
||||
1
Task/Null-object/Mathematica/null-object-4.math
Normal file
1
Task/Null-object/Mathematica/null-object-4.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
x===Null
|
||||
4
Task/Null-object/Mathematica/null-object-5.math
Normal file
4
Task/Null-object/Mathematica/null-object-5.math
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
x =.;
|
||||
ValueQ[x]
|
||||
x = 3;
|
||||
ValueQ[x]
|
||||
2
Task/Null-object/Mathematica/null-object-6.math
Normal file
2
Task/Null-object/Mathematica/null-object-6.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
False
|
||||
True
|
||||
1
Task/Null-object/Modula-3/null-object-1.mod3
Normal file
1
Task/Null-object/Modula-3/null-object-1.mod3
Normal file
|
|
@ -0,0 +1 @@
|
|||
VAR foo := NIL
|
||||
1
Task/Null-object/Modula-3/null-object-2.mod3
Normal file
1
Task/Null-object/Modula-3/null-object-2.mod3
Normal file
|
|
@ -0,0 +1 @@
|
|||
VAR foo: REF INTEGER := NIL;
|
||||
3
Task/Null-object/Modula-3/null-object-3.mod3
Normal file
3
Task/Null-object/Modula-3/null-object-3.mod3
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
IF foo = NIL THEN
|
||||
IO.Put("Object is nil.\n");
|
||||
END;
|
||||
6
Task/Null-object/NetRexx/null-object.netrexx
Normal file
6
Task/Null-object/NetRexx/null-object.netrexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
robject = Rexx -- create an object for which the value is undefined
|
||||
say String.valueOf(robject) -- will report the text "null"
|
||||
if robject = null then say 'Really, it''s "null"!'
|
||||
1
Task/Null-object/OCaml/null-object-1.ocaml
Normal file
1
Task/Null-object/OCaml/null-object-1.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
type 'a option = None | Some of 'a
|
||||
3
Task/Null-object/OCaml/null-object-2.ocaml
Normal file
3
Task/Null-object/OCaml/null-object-2.ocaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
match v with
|
||||
| None -> "unbound value"
|
||||
| Some _ -> "bounded value"
|
||||
4
Task/Null-object/Objeck/null-object.objeck
Normal file
4
Task/Null-object/Objeck/null-object.objeck
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# here "object" is a reference
|
||||
if(object = Nil) {
|
||||
"object is null"->PrintLine();
|
||||
};
|
||||
4
Task/Null-object/Objective-C/null-object-1.m
Normal file
4
Task/Null-object/Objective-C/null-object-1.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// here "object" is an object pointer
|
||||
if (object == nil) {
|
||||
NSLog("object is nil");
|
||||
}
|
||||
1
Task/Null-object/Objective-C/null-object-2.m
Normal file
1
Task/Null-object/Objective-C/null-object-2.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
[nil fooBar];
|
||||
4
Task/Null-object/Oz/null-object-1.oz
Normal file
4
Task/Null-object/Oz/null-object-1.oz
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare
|
||||
X
|
||||
in
|
||||
{Show X+2} %% blocks
|
||||
4
Task/Null-object/Oz/null-object-2.oz
Normal file
4
Task/Null-object/Oz/null-object-2.oz
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare
|
||||
X = {Value.failed dontTouchMe}
|
||||
in
|
||||
{Wait X} %% throws dontTouchMe
|
||||
6
Task/Null-object/Oz/null-object-3.oz
Normal file
6
Task/Null-object/Oz/null-object-3.oz
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
declare
|
||||
X = just("Data")
|
||||
in
|
||||
case X of nothing then skip
|
||||
[] just(Result) then {Show Result}
|
||||
end
|
||||
1
Task/Null-object/PARI-GP/null-object.pari
Normal file
1
Task/Null-object/PARI-GP/null-object.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
foo!='foo
|
||||
3
Task/Null-object/PHP/null-object.php
Normal file
3
Task/Null-object/PHP/null-object.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$x = NULL;
|
||||
if (is_null($x))
|
||||
echo "\$x is null\n";
|
||||
7
Task/Null-object/PL-I/null-object.pli
Normal file
7
Task/Null-object/PL-I/null-object.pli
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
declare x fixed decimal (10);
|
||||
...
|
||||
if ^valid(x) then signal error;
|
||||
|
||||
declare y picture 'A9XAAA9';
|
||||
...
|
||||
if ^valid(y) then signal error;
|
||||
8
Task/Null-object/Perl-6/null-object-1.pl6
Normal file
8
Task/Null-object/Perl-6/null-object-1.pl6
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
my $var;
|
||||
say $var.WHAT; # Any()
|
||||
$var = 42;
|
||||
say $var.WHAT; # Int()
|
||||
say $var.defined; # True
|
||||
$var = Nil;
|
||||
say $var.WHAT; # Any()
|
||||
say $var.defined # False
|
||||
4
Task/Null-object/Perl-6/null-object-2.pl6
Normal file
4
Task/Null-object/Perl-6/null-object-2.pl6
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my Mu $junction;
|
||||
say $junction.WHAT; # Mu()
|
||||
$junction = 1 | 2 | 3;
|
||||
say $junction.WHAT; # Junction()
|
||||
5
Task/Null-object/Perl-6/null-object-3.pl6
Normal file
5
Task/Null-object/Perl-6/null-object-3.pl6
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
my Str $str;
|
||||
say $str.WHAT; # Str()
|
||||
$str = "I am a string.";
|
||||
say $str.WHAT; # Str()
|
||||
$str = 42; # (fails)
|
||||
1
Task/Null-object/Perl/null-object-1.pl
Normal file
1
Task/Null-object/Perl/null-object-1.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
print defined($x) ? 'Defined' : 'Undefined', ".\n";
|
||||
1
Task/Null-object/Perl/null-object-2.pl
Normal file
1
Task/Null-object/Perl/null-object-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
say $number // "unknown";
|
||||
2
Task/Null-object/PicoLisp/null-object-1.l
Normal file
2
Task/Null-object/PicoLisp/null-object-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(if (not MyNewVariable)
|
||||
(handle value-is-NIL) )
|
||||
2
Task/Null-object/PicoLisp/null-object-2.l
Normal file
2
Task/Null-object/PicoLisp/null-object-2.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(unless MyNewVariable
|
||||
(handle value-is-NIL) )
|
||||
12
Task/Null-object/Pike/null-object.pike
Normal file
12
Task/Null-object/Pike/null-object.pike
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
> mapping bar;
|
||||
> bar;
|
||||
Result: 0
|
||||
> bar = ([ "foo":0 ]);
|
||||
> bar->foo;
|
||||
Result 0;
|
||||
> zero_type(bar->foo);
|
||||
Result: 0
|
||||
> bar->baz;
|
||||
Result: 0
|
||||
> zero_type(bar->baz);
|
||||
Result: 1
|
||||
3
Task/Null-object/PowerShell/null-object.psh
Normal file
3
Task/Null-object/PowerShell/null-object.psh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if ($null -eq $object) {
|
||||
...
|
||||
}
|
||||
3
Task/Null-object/PureBasic/null-object.purebasic
Normal file
3
Task/Null-object/PureBasic/null-object.purebasic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
If variable = #Null
|
||||
Debug "Variable has no value"
|
||||
EndIf
|
||||
5
Task/Null-object/Python/null-object.py
Normal file
5
Task/Null-object/Python/null-object.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x = None
|
||||
if x is None:
|
||||
print "x is None"
|
||||
else:
|
||||
print "x is not None"
|
||||
6
Task/Null-object/R/null-object.r
Normal file
6
Task/Null-object/R/null-object.r
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
is.null(NULL) # TRUE
|
||||
is.null(123) # FALSE
|
||||
is.null(NA) # FALSE
|
||||
123==NULL # Empty logical value, with a warning
|
||||
foo <- function(){} # function that does nothing
|
||||
foo() # returns NULL
|
||||
3
Task/Null-object/REBOL/null-object.rebol
Normal file
3
Task/Null-object/REBOL/null-object.rebol
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
x: none
|
||||
|
||||
print ["x" either none? x ["is"]["isn't"] "none."]
|
||||
13
Task/Null-object/REXX/null-object.rexx
Normal file
13
Task/Null-object/REXX/null-object.rexx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/*REXX program demonstrates null strings, and also undefined values. */
|
||||
|
||||
if symbol('ABC')=="VAR" then say 'variable ABC is defined, value='abc"<<<"
|
||||
else say "variable ABC isn't defined."
|
||||
xyz=47
|
||||
if symbol('XYZ')=="VAR" then say 'variable XYZ is defined, value='xyz"<<<"
|
||||
else say "variable XYZ isn't defined."
|
||||
drop xyz
|
||||
if symbol('XYZ')=="VAR" then say 'variable XYZ is defined, value='xyz"<<<"
|
||||
else say "variable XYZ isn't defined."
|
||||
cat=''
|
||||
if symbol('CAT')=="VAR" then say 'variable CAT is defined, value='cat"<<<"
|
||||
else say "variable CAT isn't defined."
|
||||
1
Task/Null-object/Ruby/null-object.rb
Normal file
1
Task/Null-object/Ruby/null-object.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
puts "object is null" if object.nil?
|
||||
22
Task/Null-object/Scala/null-object.scala
Normal file
22
Task/Null-object/Scala/null-object.scala
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
scala> Nil
|
||||
res0: scala.collection.immutable.Nil.type = List()
|
||||
|
||||
scala> Nil == List()
|
||||
res1: Boolean = true
|
||||
|
||||
scala> Null
|
||||
<console>:8: error: not found: value Null
|
||||
Null
|
||||
^
|
||||
|
||||
scala> null
|
||||
res3: Null = null
|
||||
|
||||
scala> None
|
||||
res4: None.type = None
|
||||
|
||||
scala> Unit
|
||||
res5: Unit.type = object scala.Unit
|
||||
|
||||
scala> val a = println()
|
||||
a: Unit = ()
|
||||
1
Task/Null-object/Scheme/null-object.ss
Normal file
1
Task/Null-object/Scheme/null-object.ss
Normal file
|
|
@ -0,0 +1 @@
|
|||
(null? object)
|
||||
1
Task/Null-object/Slate/null-object.slate
Normal file
1
Task/Null-object/Slate/null-object.slate
Normal file
|
|
@ -0,0 +1 @@
|
|||
Nil isNil = True.
|
||||
6
Task/Null-object/Smalltalk/null-object-1.st
Normal file
6
Task/Null-object/Smalltalk/null-object-1.st
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
object isNil ifTrue: [ "true block" ]
|
||||
ifFalse: [ "false block" ].
|
||||
nil isNil ifTrue: [ 'true!' displayNl ]. "output: true!"
|
||||
foo isNil ifTrue: [ 'ouch' displayNl ].
|
||||
x := (foo == nil).
|
||||
x := foo isNil
|
||||
6
Task/Null-object/Smalltalk/null-object-2.st
Normal file
6
Task/Null-object/Smalltalk/null-object-2.st
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
foo := nil.
|
||||
foo class. "-> UndefinedObject"
|
||||
foo respondsTo: #'bar'. "asking if a message is implemented"
|
||||
|
||||
foo class compile:'fancyOperation ^ 123'.
|
||||
foo fancyOperation "->123"
|
||||
1
Task/Null-object/Standard-ML/null-object-1.ml
Normal file
1
Task/Null-object/Standard-ML/null-object-1.ml
Normal file
|
|
@ -0,0 +1 @@
|
|||
datatype 'a option = NONE | SOME of 'a
|
||||
2
Task/Null-object/Standard-ML/null-object-2.ml
Normal file
2
Task/Null-object/Standard-ML/null-object-2.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
case v of NONE => "unbound value"
|
||||
| SOME _ => "bounded value"
|
||||
1
Task/Null-object/Tcl/null-object-1.tcl
Normal file
1
Task/Null-object/Tcl/null-object-1.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
if {$value eq ""} ...
|
||||
3
Task/Null-object/Tcl/null-object-2.tcl
Normal file
3
Task/Null-object/Tcl/null-object-2.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if {![info exist nullvar]} ...
|
||||
if {![info exists arr(nullval)]} ...
|
||||
if {![dict exists $dic nullval]} ...
|
||||
Loading…
Add table
Add a link
Reference in a new issue