2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,5 +1,11 @@
|
|||
'''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.
|
||||
'''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.
|
||||
|
||||
|
||||
;Task:
|
||||
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.''
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
note: Basic language learning
|
||||
|
|
|
|||
43
Task/Null-object/COBOL/null-object.cobol
Normal file
43
Task/Null-object/COBOL/null-object.cobol
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
identification division.
|
||||
program-id. null-objects.
|
||||
remarks. test with cobc -x -j null-objects.cob
|
||||
|
||||
data division.
|
||||
working-storage section.
|
||||
01 thing-not-thing usage pointer.
|
||||
|
||||
*> call a subprogram
|
||||
*> with one null pointer
|
||||
*> an omitted parameter
|
||||
*> and expect void return (callee returning omitted)
|
||||
*> and do not touch default return-code (returning nothing)
|
||||
procedure division.
|
||||
call "test-null" using thing-not-thing omitted returning nothing
|
||||
goback.
|
||||
end program null-objects.
|
||||
|
||||
*> Test for pointer to null (still a real thing that takes space)
|
||||
*> and an omitted parameter, (call frame has placeholder)
|
||||
*> and finally, return void, (omitted)
|
||||
identification division.
|
||||
program-id. test-null.
|
||||
|
||||
data division.
|
||||
linkage section.
|
||||
01 thing-one usage pointer.
|
||||
01 thing-two pic x.
|
||||
|
||||
procedure division using
|
||||
thing-one
|
||||
optional thing-two
|
||||
returning omitted.
|
||||
|
||||
if thing-one equal null then
|
||||
display "thing-one pointer to null" upon syserr
|
||||
end-if
|
||||
|
||||
if thing-two omitted then
|
||||
display "no thing-two was passed" upon syserr
|
||||
end-if
|
||||
goback.
|
||||
end program test-null.
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
1 1 0 1#3 4 _ 5
|
||||
1 1 0 1#3 4 _ 5 NB. use bitmask to select numbers
|
||||
3 4 5
|
||||
I.1 1 0 1
|
||||
I.1 1 0 1 NB. get indices for bitmask
|
||||
0 1 3
|
||||
0 1 3 { 3 4 _ 5
|
||||
0 1 3 { 3 4 _ 5 NB. use indices to select numbers
|
||||
3 4 5
|
||||
1 1 0 1 #inv 3 4 5
|
||||
1 1 0 1 #inv 3 4 5 NB. use bitmask to restore original positions
|
||||
3 4 0 5
|
||||
1 1 0 1 #!._ inv 3 4 5
|
||||
1 1 0 1 #!._ inv 3 4 5 NB. specify different fill element
|
||||
3 4 _ 5
|
||||
3 4 5 (0 1 3}) _ _ _ _ NB. use indices to restore original positions
|
||||
3 4 _ 5
|
||||
|
|
|
|||
7
Task/Null-object/Maple/null-object-1.maple
Normal file
7
Task/Null-object/Maple/null-object-1.maple
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
a := NULL;
|
||||
a :=
|
||||
is (NULL = ());
|
||||
true
|
||||
if a = NULL then
|
||||
print (NULL);
|
||||
end if;
|
||||
12
Task/Null-object/Maple/null-object-2.maple
Normal file
12
Task/Null-object/Maple/null-object-2.maple
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
b := Array([1, 2, 3, Integer(undefined), 5]);
|
||||
b := [ 1 2 3 undefined 5 ]
|
||||
numelems(b);
|
||||
5
|
||||
b := Array([1, 2, 3, Float(undefined), 5]);
|
||||
b := [ 1 2 3 Float(undefined) 5 ]
|
||||
numelems(b);
|
||||
5
|
||||
b := Array([1, 2, 3, NULL, 5]);
|
||||
b := [ 1 2 3 5 ]
|
||||
numelems(b);
|
||||
4
|
||||
14
Task/Null-object/Oberon-2/null-object.oberon-2
Normal file
14
Task/Null-object/Oberon-2/null-object.oberon-2
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
MODULE Null;
|
||||
IMPORT
|
||||
Out;
|
||||
TYPE
|
||||
Object = POINTER TO ObjectDesc;
|
||||
ObjectDesc = RECORD
|
||||
END;
|
||||
|
||||
VAR
|
||||
o: Object; (* default initialization to NIL *)
|
||||
|
||||
BEGIN
|
||||
IF o = NIL THEN Out.String("o is NIL"); Out.Ln END
|
||||
END Null.
|
||||
2
Task/Null-object/REBOL/null-object-2.rebol
Normal file
2
Task/Null-object/REBOL/null-object-2.rebol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
unset? get/any 'some-var
|
||||
unset? get 'some-var
|
||||
Loading…
Add table
Add a link
Reference in a new issue