Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
3
Task/Undefined-values/00-META.yaml
Normal file
3
Task/Undefined-values/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Undefined_values
|
||||
note: Programming language concepts
|
||||
2
Task/Undefined-values/00-TASK.txt
Normal file
2
Task/Undefined-values/00-TASK.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
For languages which have an explicit notion of an undefined value, identify and exercise those language's mechanisms for identifying and manipulating a variable's value's status as being undefined.
|
||||
<br/><br/>
|
||||
16
Task/Undefined-values/ALGOL-68/undefined-values.alg
Normal file
16
Task/Undefined-values/ALGOL-68/undefined-values.alg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
MODE R = REF BOOL;
|
||||
R r := NIL;
|
||||
|
||||
MODE U = UNION(BOOL, VOID);
|
||||
U u := EMPTY;
|
||||
|
||||
IF r IS R(NIL) THEN
|
||||
print(("r IS NIL", new line))
|
||||
ELSE
|
||||
print(("r ISNT NIL", new line))
|
||||
FI;
|
||||
|
||||
CASE u IN
|
||||
(VOID):print(("u is EMPTY", new line))
|
||||
OUT print(("u isnt EMPTY", new line))
|
||||
ESAC
|
||||
7
Task/Undefined-values/ActionScript/undefined-values.as
Normal file
7
Task/Undefined-values/ActionScript/undefined-values.as
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
var foo; // untyped
|
||||
var bar:*; // explicitly untyped
|
||||
|
||||
trace(foo + ", " + bar); // outputs "undefined, undefined"
|
||||
|
||||
if (foo == undefined)
|
||||
trace("foo is undefined"); // outputs "foo is undefined"
|
||||
23
Task/Undefined-values/Ada/undefined-values.ada
Normal file
23
Task/Undefined-values/Ada/undefined-values.ada
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
pragma Initialize_Scalars;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Invalid_Value is
|
||||
type Color is (Red, Green, Blue);
|
||||
X : Float;
|
||||
Y : Color;
|
||||
begin
|
||||
if not X'Valid then
|
||||
Put_Line ("X is not valid");
|
||||
end if;
|
||||
X := 1.0;
|
||||
if X'Valid then
|
||||
Put_Line ("X is" & Float'Image (X));
|
||||
end if;
|
||||
if not Y'Valid then
|
||||
Put_Line ("Y is not valid");
|
||||
end if;
|
||||
Y := Green;
|
||||
if Y'Valid then
|
||||
Put_Line ("Y is " & Color'Image (Y));
|
||||
end if;
|
||||
end Invalid_Value;
|
||||
3
Task/Undefined-values/Arturo/undefined-values.arturo
Normal file
3
Task/Undefined-values/Arturo/undefined-values.arturo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
undef: null
|
||||
|
||||
print undef
|
||||
8
Task/Undefined-values/BBC-BASIC/undefined-values-1.basic
Normal file
8
Task/Undefined-values/BBC-BASIC/undefined-values-1.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
ok% = TRUE
|
||||
ON ERROR LOCAL IF ERR<>26 REPORT : END ELSE ok% = FALSE
|
||||
IF ok% THEN
|
||||
PRINT variable$
|
||||
ELSE
|
||||
PRINT "Not defined"
|
||||
ENDIF
|
||||
RESTORE ERROR
|
||||
11
Task/Undefined-values/BBC-BASIC/undefined-values-2.basic
Normal file
11
Task/Undefined-values/BBC-BASIC/undefined-values-2.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
PROCtest
|
||||
END
|
||||
|
||||
DEF PROCtest
|
||||
LOCAL array()
|
||||
IF !^array() < 2 PRINT "Array is undefined"
|
||||
DIM array(1,2)
|
||||
IF !^array() > 1 PRINT "Array is defined"
|
||||
|
||||
!^array() = 0 : REM Set array to undefined state
|
||||
ENDPROC
|
||||
15
Task/Undefined-values/C++/undefined-values.cpp
Normal file
15
Task/Undefined-values/C++/undefined-values.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
int undefined;
|
||||
if (undefined == 42)
|
||||
{
|
||||
std::cout << "42";
|
||||
}
|
||||
|
||||
if (undefined != 42)
|
||||
{
|
||||
std::cout << "not 42";
|
||||
}
|
||||
}
|
||||
1
Task/Undefined-values/C-sharp/undefined-values-1.cs
Normal file
1
Task/Undefined-values/C-sharp/undefined-values-1.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string foo = null;
|
||||
1
Task/Undefined-values/C-sharp/undefined-values-2.cs
Normal file
1
Task/Undefined-values/C-sharp/undefined-values-2.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
int i = null;
|
||||
4
Task/Undefined-values/C-sharp/undefined-values-3.cs
Normal file
4
Task/Undefined-values/C-sharp/undefined-values-3.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
int? answer = null;
|
||||
if (answer == null) {
|
||||
answer = 42;
|
||||
}
|
||||
4
Task/Undefined-values/C-sharp/undefined-values-4.cs
Normal file
4
Task/Undefined-values/C-sharp/undefined-values-4.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Nullable<int> answer = new Nullable<int>();
|
||||
if (!answer.HasValue) {
|
||||
answer = new Nullable<int>(42);
|
||||
}
|
||||
16
Task/Undefined-values/C/undefined-values.c
Normal file
16
Task/Undefined-values/C/undefined-values.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int junk, *junkp;
|
||||
|
||||
/* Print an unitialized variable! */
|
||||
printf("junk: %d\n", junk);
|
||||
|
||||
/* Follow a pointer to unitialized memory! */
|
||||
junkp = malloc(sizeof *junkp);
|
||||
if (junkp)
|
||||
printf("*junkp: %d\n", *junkp);
|
||||
return 0;
|
||||
}
|
||||
10
Task/Undefined-values/Common-Lisp/undefined-values-1.lisp
Normal file
10
Task/Undefined-values/Common-Lisp/undefined-values-1.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
;; assumption: none of these variables initially exist
|
||||
|
||||
(defvar *x*) ;; variable exists now, but has no value
|
||||
(defvar *y* 42) ;; variable exists now, and has a value
|
||||
|
||||
(special-variable-p '*x*) -> T ;; Symbol *x* names a special variable
|
||||
(boundp '*x*) -> NIL ;; *x* has no binding
|
||||
(boundp '*y*) -> T
|
||||
|
||||
(special-variable-p '*z*) -> NIL ;; *z* does not name a special variable
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(makunbound '*y*) ;; *y* no longer has a value; it is erroneous to evaluate *y*
|
||||
|
||||
(setf *y* 43) ;; *y* is bound again.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(defvar *dyn*) ;; special, no binding
|
||||
|
||||
(let (*dyn* ;; locally scoped override, value is nil
|
||||
lex) ;; lexical, value is nil
|
||||
(list (boundp '*dyn*) *dyn* (boundp 'lex) lex)) -> (T NIL NIL NIL)
|
||||
|
||||
(boundp '*global*) -> NIL
|
||||
19
Task/Undefined-values/D/undefined-values.d
Normal file
19
Task/Undefined-values/D/undefined-values.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
void main() {
|
||||
// Initialized:
|
||||
int a = 5;
|
||||
double b = 5.0;
|
||||
char c = 'f';
|
||||
int[] d = [1, 2, 3];
|
||||
|
||||
// Default initialized:
|
||||
int aa; // set to 0
|
||||
double bb; // set to double.init, that is a NaN
|
||||
char cc; // set to 0xFF
|
||||
int[] dd; // set to null
|
||||
int[3] ee; // set to [0, 0, 0]
|
||||
|
||||
// Undefined (contain garbage):
|
||||
int aaa = void;
|
||||
double[] bbb = void;
|
||||
int[3] eee = void;
|
||||
}
|
||||
13
Task/Undefined-values/Delphi/undefined-values.delphi
Normal file
13
Task/Undefined-values/Delphi/undefined-values.delphi
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var
|
||||
P: PInteger;
|
||||
begin
|
||||
New(P); //Allocate some memory
|
||||
try
|
||||
If Assigned(P) Then //...
|
||||
begin
|
||||
P^ := 42;
|
||||
end;
|
||||
finally
|
||||
Dispose(P); //Release memory allocated by New
|
||||
end;
|
||||
end;
|
||||
3
Task/Undefined-values/E/undefined-values.e
Normal file
3
Task/Undefined-values/E/undefined-values.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if (foo == bar || (def baz := lookup(foo)) != null) {
|
||||
...
|
||||
}
|
||||
10
Task/Undefined-values/Erlang/undefined-values.erl
Normal file
10
Task/Undefined-values/Erlang/undefined-values.erl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-module( undefined_values ).
|
||||
|
||||
-export( [task/0] ).
|
||||
|
||||
-record( a_record, {member_1, member_2} ).
|
||||
|
||||
task() ->
|
||||
Record = #a_record{member_1=a_value},
|
||||
io:fwrite( "Record member_1 ~p, member_2 ~p~n", [Record#a_record.member_1, Record#a_record.member_2] ),
|
||||
io:fwrite( "Member_2 is undefined ~p~n", [Record#a_record.member_2 =:= undefined] ).
|
||||
1
Task/Undefined-values/Factor/undefined-values-1.factor
Normal file
1
Task/Undefined-values/Factor/undefined-values-1.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
42 . ! 42
|
||||
5
Task/Undefined-values/Factor/undefined-values-2.factor
Normal file
5
Task/Undefined-values/Factor/undefined-values-2.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TUPLE: foo bar ;
|
||||
foo new bar>> . ! f
|
||||
|
||||
TUPLE: my-tuple { n integer } ;
|
||||
my-tuple new n>> . ! 0
|
||||
4
Task/Undefined-values/Factor/undefined-values-3.factor
Normal file
4
Task/Undefined-values/Factor/undefined-values-3.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
SYMBOL: n
|
||||
n get . ! f
|
||||
|
||||
\ + get . ! f
|
||||
4
Task/Undefined-values/Factor/undefined-values-4.factor
Normal file
4
Task/Undefined-values/Factor/undefined-values-4.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[let
|
||||
2 :> n ! There is no other way!
|
||||
0 1 :> ( a b )
|
||||
]
|
||||
1
Task/Undefined-values/Fortran/undefined-values.f
Normal file
1
Task/Undefined-values/Fortran/undefined-values.f
Normal file
|
|
@ -0,0 +1 @@
|
|||
IsNaN(x)
|
||||
8
Task/Undefined-values/FreeBASIC/undefined-values.basic
Normal file
8
Task/Undefined-values/FreeBASIC/undefined-values.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim i As Integer '' initialized to 0 by default
|
||||
Dim j As Integer = 3 '' initialized to 3
|
||||
Dim k As Integer = Any '' left uninitialized (compiler warning but can be ignored)
|
||||
|
||||
Print i, j, k
|
||||
Sleep
|
||||
7
Task/Undefined-values/GAP/undefined-values.gap
Normal file
7
Task/Undefined-values/GAP/undefined-values.gap
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
IsBound(a);
|
||||
# true
|
||||
|
||||
Unbind(a);
|
||||
|
||||
IsBound(a);
|
||||
# false
|
||||
97
Task/Undefined-values/Go/undefined-values.go
Normal file
97
Task/Undefined-values/Go/undefined-values.go
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
s []int
|
||||
p *int
|
||||
f func()
|
||||
i interface{}
|
||||
m map[int]int
|
||||
c chan int
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Exercise nil objects:")
|
||||
status()
|
||||
|
||||
// initialize objects
|
||||
s = make([]int, 1)
|
||||
p = &s[0] // yes, reference element of slice just created
|
||||
f = func() { fmt.Println("function call") }
|
||||
i = user(0) // see user defined type just below
|
||||
m = make(map[int]int)
|
||||
c = make(chan int, 1)
|
||||
|
||||
fmt.Println("\nExercise objects after initialization:")
|
||||
status()
|
||||
}
|
||||
|
||||
type user int
|
||||
|
||||
func (user) m() {
|
||||
fmt.Println("method call")
|
||||
}
|
||||
|
||||
func status() {
|
||||
trySlice()
|
||||
tryPointer()
|
||||
tryFunction()
|
||||
tryInterface()
|
||||
tryMap()
|
||||
tryChannel()
|
||||
}
|
||||
|
||||
func reportPanic() {
|
||||
if x := recover(); x != nil {
|
||||
fmt.Println("panic:", x)
|
||||
}
|
||||
}
|
||||
|
||||
func trySlice() {
|
||||
defer reportPanic()
|
||||
fmt.Println("s[0] =", s[0])
|
||||
}
|
||||
|
||||
func tryPointer() {
|
||||
defer reportPanic()
|
||||
fmt.Println("*p =", *p)
|
||||
}
|
||||
|
||||
func tryFunction() {
|
||||
defer reportPanic()
|
||||
f()
|
||||
}
|
||||
|
||||
func tryInterface() {
|
||||
defer reportPanic()
|
||||
|
||||
// normally the nil identifier accesses a nil value for one of
|
||||
// six predefined types. In a type switch however, nil can be used
|
||||
// as a type. In this case, it matches the nil interface.
|
||||
switch i.(type) {
|
||||
case nil:
|
||||
fmt.Println("i is nil interface")
|
||||
case interface {
|
||||
m()
|
||||
}:
|
||||
fmt.Println("i has method m")
|
||||
}
|
||||
|
||||
// assert type with method and then call method
|
||||
i.(interface {
|
||||
m()
|
||||
}).m()
|
||||
}
|
||||
|
||||
func tryMap() {
|
||||
defer reportPanic()
|
||||
m[0] = 0
|
||||
fmt.Println("m[0] =", m[0])
|
||||
}
|
||||
|
||||
func tryChannel() {
|
||||
defer reportPanic()
|
||||
close(c)
|
||||
fmt.Println("channel closed")
|
||||
}
|
||||
3
Task/Undefined-values/Haskell/undefined-values-1.hs
Normal file
3
Task/Undefined-values/Haskell/undefined-values-1.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main = print $ "Incoming error--" ++ undefined
|
||||
-- When run in GHC:
|
||||
-- "Incoming error--*** Exception: Prelude.undefined
|
||||
1
Task/Undefined-values/Haskell/undefined-values-2.hs
Normal file
1
Task/Undefined-values/Haskell/undefined-values-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
main = print $ length [undefined, undefined, 1 `div` 0]
|
||||
1
Task/Undefined-values/Haskell/undefined-values-3.hs
Normal file
1
Task/Undefined-values/Haskell/undefined-values-3.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
resurrect 0 = error "I'm out of orange smoke!"
|
||||
2
Task/Undefined-values/Haskell/undefined-values-4.hs
Normal file
2
Task/Undefined-values/Haskell/undefined-values-4.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
undefined :: a
|
||||
undefined = error "Prelude.undefined"
|
||||
16
Task/Undefined-values/Haskell/undefined-values-5.hs
Normal file
16
Task/Undefined-values/Haskell/undefined-values-5.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Control.Exception (catch, evaluate, ErrorCall)
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
import Prelude hiding (catch)
|
||||
import Control.DeepSeq (NFData, deepseq)
|
||||
|
||||
scoopError :: (NFData a) => a -> Either String a
|
||||
scoopError x = unsafePerformIO $ catch right left
|
||||
where right = deepseq x $ return $ Right x
|
||||
left e = return $ Left $ show (e :: ErrorCall)
|
||||
|
||||
safeHead :: (NFData a) => [a] -> Either String a
|
||||
safeHead = scoopError . head
|
||||
|
||||
main = do
|
||||
print $ safeHead ([] :: String)
|
||||
print $ safeHead ["str"]
|
||||
3
Task/Undefined-values/J/undefined-values-1.j
Normal file
3
Task/Undefined-values/J/undefined-values-1.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foo=: 3
|
||||
nc;:'foo bar'
|
||||
0 _1
|
||||
7
Task/Undefined-values/J/undefined-values-2.j
Normal file
7
Task/Undefined-values/J/undefined-values-2.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
erase;:'foo bar'
|
||||
1 1
|
||||
nc;:'foo bar'
|
||||
_1 _1
|
||||
bar=:99
|
||||
nc;:'foo bar'
|
||||
_1 0
|
||||
3
Task/Undefined-values/Java/undefined-values-1.java
Normal file
3
Task/Undefined-values/Java/undefined-values-1.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
String string = null; // the variable string is undefined
|
||||
System.out.println(string); //prints "null" to std out
|
||||
System.out.println(string.length()); // dereferencing null throws java.lang.NullPointerException
|
||||
4
Task/Undefined-values/Java/undefined-values-2.java
Normal file
4
Task/Undefined-values/Java/undefined-values-2.java
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
int i = null; // compilation error: incompatible types, required: int, found: <nulltype>
|
||||
if (i == null) { // compilation error: incomparable types: int and <nulltype>
|
||||
i = 1;
|
||||
}
|
||||
4
Task/Undefined-values/Java/undefined-values-3.java
Normal file
4
Task/Undefined-values/Java/undefined-values-3.java
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Integer i = null; // variable i is undefined
|
||||
if (i == null) {
|
||||
i = 1;
|
||||
}
|
||||
13
Task/Undefined-values/JavaScript/undefined-values-1.js
Normal file
13
Task/Undefined-values/JavaScript/undefined-values-1.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var a;
|
||||
|
||||
typeof(a) === "undefined";
|
||||
typeof(b) === "undefined";
|
||||
|
||||
var obj = {}; // Empty object.
|
||||
typeof(obj.c) === "undefined";
|
||||
|
||||
obj.c = 42;
|
||||
|
||||
obj.c === 42;
|
||||
delete obj.c;
|
||||
typeof(obj.c) === "undefined";
|
||||
3
Task/Undefined-values/JavaScript/undefined-values-2.js
Normal file
3
Task/Undefined-values/JavaScript/undefined-values-2.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var a;
|
||||
a === void 0; // true
|
||||
b === void 0; // throws a ReferenceError
|
||||
1
Task/Undefined-values/Jq/undefined-values-1.jq
Normal file
1
Task/Undefined-values/Jq/undefined-values-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}["key"] #=> null
|
||||
1
Task/Undefined-values/Jq/undefined-values-2.jq
Normal file
1
Task/Undefined-values/Jq/undefined-values-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
1/0 == null #=>false
|
||||
1
Task/Undefined-values/Jq/undefined-values-3.jq
Normal file
1
Task/Undefined-values/Jq/undefined-values-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def sum: reduce .[] as $x (null; . + $x);
|
||||
28
Task/Undefined-values/Julia/undefined-values.julia
Normal file
28
Task/Undefined-values/Julia/undefined-values.julia
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
julia> arr = [1, 2, nothing, 3]
|
||||
4-element Array{Union{Nothing, Int64},1}:
|
||||
1
|
||||
2
|
||||
nothing
|
||||
3
|
||||
|
||||
julia> x = arr .+ 5
|
||||
ERROR: MethodError: no method matching +(::Nothing, ::Int64)
|
||||
Closest candidates are:
|
||||
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:502
|
||||
+(::Complex{Bool}, ::Real) at complex.jl:292
|
||||
+(::Missing, ::Number) at missing.jl:93
|
||||
...
|
||||
|
||||
julia> arr = [1, 2, missing, 3]
|
||||
4-element Array{Union{Missing, Int64},1}:
|
||||
1
|
||||
2
|
||||
missing
|
||||
3
|
||||
|
||||
julia> x = arr .+ 5
|
||||
4-element Array{Union{Missing, Int64},1}:
|
||||
6
|
||||
7
|
||||
missing
|
||||
8
|
||||
38
Task/Undefined-values/Kotlin/undefined-values.kotlin
Normal file
38
Task/Undefined-values/Kotlin/undefined-values.kotlin
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// version 1.1.2
|
||||
|
||||
class SomeClass
|
||||
|
||||
class SomeOtherClass {
|
||||
lateinit var sc: SomeClass
|
||||
|
||||
fun initialize() {
|
||||
sc = SomeClass() // not initialized in place or in constructor
|
||||
}
|
||||
|
||||
fun printSomething() {
|
||||
println(sc) // 'sc' may not have been initialized at this point
|
||||
}
|
||||
|
||||
fun someFunc(): String {
|
||||
// for now calls a library function which throws an error and returns Nothing
|
||||
TODO("someFunc not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val soc = SomeOtherClass()
|
||||
|
||||
try {
|
||||
soc.printSomething()
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
println(ex)
|
||||
}
|
||||
|
||||
try {
|
||||
soc.someFunc()
|
||||
}
|
||||
catch (e: Error) {
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
18
Task/Undefined-values/LOLCODE/undefined-values.lol
Normal file
18
Task/Undefined-values/LOLCODE/undefined-values.lol
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
HAI 1.3
|
||||
|
||||
I HAS A foo BTW, INISHULIZD TO NOOB
|
||||
DIFFRINT foo AN FAIL, O RLY?
|
||||
YA RLY, VISIBLE "FAIL != NOOB"
|
||||
OIC
|
||||
|
||||
I HAS A bar ITZ 42
|
||||
bar, O RLY?
|
||||
YA RLY, VISIBLE "bar IZ DEFIND"
|
||||
OIC
|
||||
|
||||
bar R NOOB BTW, UNDEF bar
|
||||
bar, O RLY?
|
||||
YA RLY, VISIBLE "SHUD NEVAR C DIS"
|
||||
OIC
|
||||
|
||||
KTHXBYE
|
||||
9
Task/Undefined-values/Lingo/undefined-values.lingo
Normal file
9
Task/Undefined-values/Lingo/undefined-values.lingo
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
put var
|
||||
-- <Void>
|
||||
put var=VOID
|
||||
-- 1
|
||||
put voidP(var)
|
||||
-- 1
|
||||
var = 23
|
||||
put voidP(var)
|
||||
-- 0
|
||||
19
Task/Undefined-values/Logo/undefined-values.logo
Normal file
19
Task/Undefined-values/Logo/undefined-values.logo
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
; procedures
|
||||
to square :x
|
||||
output :x * :x
|
||||
end
|
||||
|
||||
show defined? "x ; true
|
||||
show procedure? "x ; true (also works for built-in primitives)
|
||||
erase "x
|
||||
show defined? "x ; false
|
||||
show square 3 ; I don't know how to square
|
||||
|
||||
; names
|
||||
|
||||
make "n 23
|
||||
|
||||
show name? "n ; true
|
||||
ern "n
|
||||
show name? "n ; false
|
||||
show :n ; n has no value
|
||||
9
Task/Undefined-values/Lua/undefined-values.lua
Normal file
9
Task/Undefined-values/Lua/undefined-values.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
print( a )
|
||||
|
||||
local b
|
||||
print( b )
|
||||
|
||||
if b == nil then
|
||||
b = 5
|
||||
end
|
||||
print( b )
|
||||
1
Task/Undefined-values/MATLAB/undefined-values-1.m
Normal file
1
Task/Undefined-values/MATLAB/undefined-values-1.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
global var;
|
||||
1
Task/Undefined-values/MATLAB/undefined-values-2.m
Normal file
1
Task/Undefined-values/MATLAB/undefined-values-2.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
isempty(var)
|
||||
1
Task/Undefined-values/MATLAB/undefined-values-3.m
Normal file
1
Task/Undefined-values/MATLAB/undefined-values-3.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
var = [1, 2, NaN, 0/0, inf-inf, 5]
|
||||
1
Task/Undefined-values/MATLAB/undefined-values-4.m
Normal file
1
Task/Undefined-values/MATLAB/undefined-values-4.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
isnan(var)
|
||||
2
Task/Undefined-values/MUMPS/undefined-values.mumps
Normal file
2
Task/Undefined-values/MUMPS/undefined-values.mumps
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
IF $DATA(SOMEVAR)=0 DO UNDEF ; A result of 0 means the value is undefined
|
||||
SET LOCAL=$GET(^PATIENT(RECORDNUM,0)) ;If there isn't a defined item at that location, a null string is returned
|
||||
10
Task/Undefined-values/Mathematica/undefined-values-1.math
Normal file
10
Task/Undefined-values/Mathematica/undefined-values-1.math
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
a
|
||||
-> a
|
||||
a + a
|
||||
-> 2 a
|
||||
ValueQ[a]
|
||||
-> False
|
||||
a = 5
|
||||
-> 5
|
||||
ValueQ[a]
|
||||
-> True
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
ConditionalExpression[a, False]
|
||||
->Undefined
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Sin[Undefined]
|
||||
-> Undefined
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a = Undefined
|
||||
-> Undefined
|
||||
a
|
||||
-> Undefined
|
||||
ValueQ[a]
|
||||
-> True
|
||||
5
Task/Undefined-values/Nim/undefined-values.nim
Normal file
5
Task/Undefined-values/Nim/undefined-values.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var a {.noInit.}: array[1_000_000, int]
|
||||
|
||||
# For a proc, {.noInit.} means that the result is not initialized.
|
||||
proc p(): array[1000, int] {.noInit.} =
|
||||
for i in 0..999: result[i] = i
|
||||
13
Task/Undefined-values/OCaml/undefined-values.ocaml
Normal file
13
Task/Undefined-values/OCaml/undefined-values.ocaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(* There is no undefined value in OCaml,
|
||||
but if you really need this you can use the built-in "option" type.
|
||||
It is defined like this: type 'a option = None | Some of 'a *)
|
||||
|
||||
let inc = function
|
||||
Some n -> Some (n+1)
|
||||
| None -> failwith "Undefined argument";;
|
||||
|
||||
inc (Some 0);;
|
||||
(* - : value = Some 1 *)
|
||||
|
||||
inc None;;
|
||||
(* Exception: Failure "Undefined argument". *)
|
||||
12
Task/Undefined-values/Oz/undefined-values.oz
Normal file
12
Task/Undefined-values/Oz/undefined-values.oz
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
declare X in
|
||||
|
||||
thread
|
||||
if {IsFree X} then {System.showInfo "X is unbound."} end
|
||||
{Wait X}
|
||||
{System.showInfo "Now X is determined."}
|
||||
end
|
||||
|
||||
{System.showInfo "Sleeping..."}
|
||||
{Delay 1000}
|
||||
{System.showInfo "Setting X."}
|
||||
X = 42
|
||||
1
Task/Undefined-values/PARI-GP/undefined-values-1.parigp
Normal file
1
Task/Undefined-values/PARI-GP/undefined-values-1.parigp
Normal file
|
|
@ -0,0 +1 @@
|
|||
v == 'v
|
||||
1
Task/Undefined-values/PARI-GP/undefined-values-2.parigp
Normal file
1
Task/Undefined-values/PARI-GP/undefined-values-2.parigp
Normal file
|
|
@ -0,0 +1 @@
|
|||
is_entry("v") == NULL;
|
||||
33
Task/Undefined-values/PHP/undefined-values.php
Normal file
33
Task/Undefined-values/PHP/undefined-values.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
// Check to see whether it is defined
|
||||
if (!isset($var))
|
||||
echo "var is undefined at first check\n";
|
||||
|
||||
// Give it a value
|
||||
$var = "Chocolate";
|
||||
|
||||
// Check to see whether it is defined after we gave it the
|
||||
// value "Chocolate"
|
||||
if (!isset($var))
|
||||
echo "var is undefined at second check\n";
|
||||
|
||||
// Give the variable an undefined value.
|
||||
unset($var);
|
||||
|
||||
// Check to see whether it is defined after we've explicitly
|
||||
// given it an undefined value.
|
||||
if (!isset($var))
|
||||
echo "var is undefined at third check\n";
|
||||
|
||||
// Give the variable a value of 42
|
||||
$var = 42;
|
||||
|
||||
// Check to see whether the it is defined after we've given it
|
||||
// the value 42.
|
||||
if (!isset($var))
|
||||
echo "var is undefined at fourth check\n";
|
||||
|
||||
// Because most of the output is conditional, this serves as
|
||||
// a clear indicator that the program has run to completion.
|
||||
echo "Done\n";
|
||||
?>
|
||||
35
Task/Undefined-values/Perl/undefined-values.pl
Normal file
35
Task/Undefined-values/Perl/undefined-values.pl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
|
||||
# Declare the variable. It is initialized to the value "undef"
|
||||
our $var;
|
||||
|
||||
# Check to see whether it is defined
|
||||
print "var contains an undefined value at first check\n" unless defined $var;
|
||||
|
||||
# Give it a value
|
||||
$var = "Chocolate";
|
||||
|
||||
# Check to see whether it is defined after we gave it the
|
||||
# value "Chocolate"
|
||||
print "var contains an undefined value at second check\n" unless defined $var;
|
||||
|
||||
# Give the variable the value "undef".
|
||||
$var = undef;
|
||||
# or, equivalently:
|
||||
undef($var);
|
||||
|
||||
# Check to see whether it is defined after we've explicitly
|
||||
# given it an undefined value.
|
||||
print "var contains an undefined value at third check\n" unless defined $var;
|
||||
|
||||
# Give the variable a value of 42
|
||||
$var = 42;
|
||||
|
||||
# Check to see whether the it is defined after we've given it
|
||||
# the value 42.
|
||||
print "var contains an undefined value at fourth check\n" unless defined $var;
|
||||
|
||||
# Because most of the output is conditional, this serves as
|
||||
# a clear indicator that the program has run to completion.
|
||||
print "Done\n";
|
||||
15
Task/Undefined-values/Phix/undefined-values.phix
Normal file
15
Task/Undefined-values/Phix/undefined-values.phix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
-->
|
||||
<span style="color: #004080;">object</span> <span style="color: #000000;">x</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #004080;">object</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"x is an object\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"x is unassigned\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #000000;">test</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #000000;">test</span><span style="color: #0000FF;">()</span>
|
||||
<!--
|
||||
4
Task/Undefined-values/PicoLisp/undefined-values-1.l
Normal file
4
Task/Undefined-values/PicoLisp/undefined-values-1.l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: (myfoo 3 4)
|
||||
!? (myfoo 3 4)
|
||||
myfoo -- Undefined
|
||||
?
|
||||
14
Task/Undefined-values/PicoLisp/undefined-values-2.l
Normal file
14
Task/Undefined-values/PicoLisp/undefined-values-2.l
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
: MyVar
|
||||
-> NIL
|
||||
|
||||
: (default MyVar 7)
|
||||
-> 7
|
||||
|
||||
: MyVar
|
||||
-> 7
|
||||
|
||||
: (default MyVar 8)
|
||||
-> 7
|
||||
|
||||
: MyVar
|
||||
-> 7
|
||||
11
Task/Undefined-values/Pike/undefined-values.pike
Normal file
11
Task/Undefined-values/Pike/undefined-values.pike
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
> zero_type(UNDEFINED);
|
||||
Result: 1
|
||||
> mapping bar = ([ "foo":"hello" ]);
|
||||
> zero_type(bar->foo);
|
||||
Result: 0
|
||||
> zero_type(bar->baz);
|
||||
Result: 1
|
||||
> bar->baz=UNDEFINED;
|
||||
Result: 0
|
||||
> zero_type(bar->baz);
|
||||
Result: 0
|
||||
8
Task/Undefined-values/PowerShell/undefined-values-1.psh
Normal file
8
Task/Undefined-values/PowerShell/undefined-values-1.psh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
if (Get-Variable -Name noSuchVariable -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$true
|
||||
}
|
||||
else
|
||||
{
|
||||
$false
|
||||
}
|
||||
1
Task/Undefined-values/PowerShell/undefined-values-2.psh
Normal file
1
Task/Undefined-values/PowerShell/undefined-values-2.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Get-PSProvider
|
||||
1
Task/Undefined-values/PowerShell/undefined-values-3.psh
Normal file
1
Task/Undefined-values/PowerShell/undefined-values-3.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Test-Path Variable:\noSuchVariable
|
||||
1
Task/Undefined-values/PowerShell/undefined-values-4.psh
Normal file
1
Task/Undefined-values/PowerShell/undefined-values-4.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$noSuchVariable -eq $null
|
||||
21
Task/Undefined-values/PureBasic/undefined-values.basic
Normal file
21
Task/Undefined-values/PureBasic/undefined-values.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
If OpenConsole()
|
||||
|
||||
CompilerIf Defined(var, #PB_Variable)
|
||||
PrintN("var is defined at first check")
|
||||
CompilerElse
|
||||
PrintN("var is undefined at first check")
|
||||
Define var
|
||||
CompilerEndIf
|
||||
|
||||
CompilerIf Defined(var, #PB_Variable)
|
||||
PrintN("var is defined at second check")
|
||||
CompilerElse
|
||||
PrintN("var is undefined at second check")
|
||||
Define var
|
||||
CompilerEndIf
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
|
||||
Input()
|
||||
CloseConsole()
|
||||
|
||||
EndIf
|
||||
28
Task/Undefined-values/Python/undefined-values.py
Normal file
28
Task/Undefined-values/Python/undefined-values.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Check to see whether a name is defined
|
||||
try: name
|
||||
except NameError: print "name is undefined at first check"
|
||||
|
||||
# Create a name, giving it a string value
|
||||
name = "Chocolate"
|
||||
|
||||
# Check to see whether the name is defined now.
|
||||
try: name
|
||||
except NameError: print "name is undefined at second check"
|
||||
|
||||
# Remove the definition of the name.
|
||||
del name
|
||||
|
||||
# Check to see whether it is defined after the explicit removal.
|
||||
try: name
|
||||
except NameError: print "name is undefined at third check"
|
||||
|
||||
# Recreate the name, giving it a value of 42
|
||||
name = 42
|
||||
|
||||
# Check to see whether the name is defined now.
|
||||
try: name
|
||||
except NameError: print "name is undefined at fourth check"
|
||||
|
||||
# Because most of the output is conditional, this serves as
|
||||
# a clear indicator that the program has run to completion.
|
||||
print "Done"
|
||||
1
Task/Undefined-values/R/undefined-values-1.r
Normal file
1
Task/Undefined-values/R/undefined-values-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
exists("x")
|
||||
1
Task/Undefined-values/R/undefined-values-2.r
Normal file
1
Task/Undefined-values/R/undefined-values-2.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
x <- NULL
|
||||
2
Task/Undefined-values/R/undefined-values-3.r
Normal file
2
Task/Undefined-values/R/undefined-values-3.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
y <- c(1, 4, 9, NA, 25)
|
||||
z <- c("foo", NA, "baz")
|
||||
7
Task/Undefined-values/R/undefined-values-4.r
Normal file
7
Task/Undefined-values/R/undefined-values-4.r
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
print_is_missing <- function(x)
|
||||
{
|
||||
print(missing(x))
|
||||
}
|
||||
|
||||
print_is_missing() # TRUE
|
||||
print_is_missing(123) # FALSE
|
||||
20
Task/Undefined-values/REXX/undefined-values.rexx
Normal file
20
Task/Undefined-values/REXX/undefined-values.rexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*REXX program test if a (REXX) variable is defined or not defined. */
|
||||
tlaloc = "rain god of the Aztecs." /*assign a value to the Aztec rain god.*/
|
||||
/*check if the rain god is defined. */
|
||||
y= 'tlaloc'
|
||||
if symbol(y)=="VAR" then say y ' is defined.'
|
||||
else say y "isn't defined."
|
||||
|
||||
/*check if the fire god is defined. */
|
||||
|
||||
y= 'xiuhtecuhtli' /*assign a value to the Aztec file god.*/
|
||||
if symbol(y)=="VAR" then say y ' is defined.'
|
||||
else say y "isn't defined."
|
||||
|
||||
|
||||
drop tlaloc /*un─define the TLALOC REXX variable.*/
|
||||
/*check if the rain god is defined. */
|
||||
y= 'tlaloc'
|
||||
if symbol(y)=="VAR" then say y ' is defined.'
|
||||
else say y "isn't defined."
|
||||
/*stick a fork in it, we're all done. */
|
||||
2
Task/Undefined-values/Racket/undefined-values.rkt
Normal file
2
Task/Undefined-values/Racket/undefined-values.rkt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-> (letrec ([x x]) x)
|
||||
#<undefined>
|
||||
1
Task/Undefined-values/Raku/undefined-values-1.raku
Normal file
1
Task/Undefined-values/Raku/undefined-values-1.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
my $x; $x = 42; $x = Nil; say $x.WHAT; # prints Any()
|
||||
1
Task/Undefined-values/Raku/undefined-values-2.raku
Normal file
1
Task/Undefined-values/Raku/undefined-values-2.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
say Method ~~ Routine; # Bool::True
|
||||
3
Task/Undefined-values/Raku/undefined-values-3.raku
Normal file
3
Task/Undefined-values/Raku/undefined-values-3.raku
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
my $x; say $x.WHAT; # Any()
|
||||
my Int $y; say $y.WHAT; # Int()
|
||||
my Str $z; say $z.WHAT; # Str()
|
||||
6
Task/Undefined-values/Raku/undefined-values-4.raku
Normal file
6
Task/Undefined-values/Raku/undefined-values-4.raku
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
my Int:D $i = 1; # if $i has to be defined you must provide a default value
|
||||
multi sub foo(Int:D $i where * != 0){ (0..100).roll / $i } # we will never divide by 0
|
||||
multi sub foo(Int:U $i){ die 'WELP! $i is undefined' } # because undefinedness is deadly
|
||||
|
||||
with $i { say 'defined' } # as "if" is looking for Bool::True, "with" is looking for *.defined
|
||||
with 0 { say '0 may not divide but it is defined' }
|
||||
17
Task/Undefined-values/Raku/undefined-values-5.raku
Normal file
17
Task/Undefined-values/Raku/undefined-values-5.raku
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
my $is-defined = 1;
|
||||
my $ain't-defined = Any;
|
||||
my $doesn't-matter;
|
||||
my Any:D $will-be-defined = $ain't-defined // $is-defined // $doesn't-matter;
|
||||
|
||||
my @a-mixed-list = Any, 1, Any, 'a';
|
||||
$will-be-defined = [//] @a-mixed-list; # [//] will return the first defined value
|
||||
|
||||
my @a = Any,Any,1,1;
|
||||
my @b = 2,Any,Any,2;
|
||||
my @may-contain-any = @a >>//<< @b; # contains: [2, Any, 1, 1]
|
||||
|
||||
sub f1(){Failure.new('WELP!')};
|
||||
sub f2(){ $_ ~~ Failure }; # orelse will kindly set the topic for us
|
||||
my $s = (f1() orelse f2()); # Please note the parentheses, which are needed because orelse is
|
||||
# much looser then infix:<=> .
|
||||
dd $s; # this be Bool::False
|
||||
8
Task/Undefined-values/Ring/undefined-values.ring
Normal file
8
Task/Undefined-values/Ring/undefined-values.ring
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Project : Undefined values
|
||||
|
||||
test()
|
||||
func test
|
||||
x=10 y=20
|
||||
see islocal("x") + nl +
|
||||
islocal("y") + nl +
|
||||
islocal("z") + nl
|
||||
15
Task/Undefined-values/Ruby/undefined-values.rb
Normal file
15
Task/Undefined-values/Ruby/undefined-values.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Check to see whether it is defined
|
||||
puts "var is undefined at first check" unless defined? var
|
||||
|
||||
# Give it a value
|
||||
var = "Chocolate"
|
||||
|
||||
# Check to see whether it is defined after we gave it the
|
||||
# value "Chocolate"
|
||||
puts "var is undefined at second check" unless defined? var
|
||||
|
||||
# I don't know any way of undefining a variable in Ruby
|
||||
|
||||
# Because most of the output is conditional, this serves as
|
||||
# a clear indicator that the program has run to completion.
|
||||
puts "Done"
|
||||
4
Task/Undefined-values/Rust/undefined-values.rust
Normal file
4
Task/Undefined-values/Rust/undefined-values.rust
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use std::ptr;
|
||||
|
||||
let p: *const i32 = ptr::null();
|
||||
assert!(p.is_null());
|
||||
13
Task/Undefined-values/Sidef/undefined-values.sidef
Normal file
13
Task/Undefined-values/Sidef/undefined-values.sidef
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var x; # declared, but not defined
|
||||
x == nil && say "nil value";
|
||||
defined(x) || say "undefined";
|
||||
|
||||
# Give "x" some value
|
||||
x = 42;
|
||||
|
||||
defined(x) && say "defined";
|
||||
|
||||
# Change "x" back to `nil`
|
||||
x = nil;
|
||||
|
||||
defined(x) || say "undefined";
|
||||
2
Task/Undefined-values/Smalltalk/undefined-values.st
Normal file
2
Task/Undefined-values/Smalltalk/undefined-values.st
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Smalltalk includesKey: #FooBar
|
||||
myNamespace includesKey: #Baz
|
||||
24
Task/Undefined-values/Tcl/undefined-values.tcl
Normal file
24
Task/Undefined-values/Tcl/undefined-values.tcl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Variables are undefined by default and do not need explicit declaration
|
||||
|
||||
# Check to see whether it is defined
|
||||
if {![info exists var]} {puts "var is undefind at first check"}
|
||||
|
||||
# Give it a value
|
||||
set var "Screwy Squirrel"
|
||||
|
||||
# Check to see whether it is defined
|
||||
if {![info exists var]} {puts "var is undefind at second check"}
|
||||
|
||||
# Remove its value
|
||||
unset var
|
||||
|
||||
# Check to see whether it is defined
|
||||
if {![info exists var]} {puts "var is undefind at third check"}
|
||||
|
||||
# Give it a value again
|
||||
set var 12345
|
||||
|
||||
# Check to see whether it is defined
|
||||
if {![info exists var]} {puts "var is undefind at fourth check"}
|
||||
|
||||
puts "Done"
|
||||
3
Task/Undefined-values/UNIX-Shell/undefined-values.sh
Normal file
3
Task/Undefined-values/UNIX-Shell/undefined-values.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
VAR1="VAR1"
|
||||
echo ${VAR1:-"Not set."}
|
||||
echo ${VAR2:-"Not set."}
|
||||
15
Task/Undefined-values/Unicon/undefined-values.unicon
Normal file
15
Task/Undefined-values/Unicon/undefined-values.unicon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
global G1
|
||||
|
||||
procedure main(arglist)
|
||||
local ML1
|
||||
static MS1
|
||||
undeftest()
|
||||
end
|
||||
|
||||
procedure undeftest(P1)
|
||||
static S1
|
||||
local L1,L2
|
||||
every #write all local, parameter, static, and global variable names
|
||||
write((localnames|paramnames|staticnames|globalnames)(¤t,0)) # ... visible in the current co-expression at this calling level (0)
|
||||
return
|
||||
end
|
||||
15
Task/Undefined-values/Wren/undefined-values.wren
Normal file
15
Task/Undefined-values/Wren/undefined-values.wren
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var f = Fn.new {
|
||||
System.print("'f' called.") // note no return value
|
||||
}
|
||||
|
||||
var res = f.call()
|
||||
System.print("The value returned by 'f' is %(res).")
|
||||
|
||||
var m = {} // empty map
|
||||
System.print("m[1] is %(m[1]).")
|
||||
|
||||
var u // declared but not assigned a value
|
||||
System.print("u is %(u).")
|
||||
|
||||
var v = null // explicitly assigned null
|
||||
if (!v) System.print("v is %(v).")
|
||||
3
Task/Undefined-values/Zkl/undefined-values.zkl
Normal file
3
Task/Undefined-values/Zkl/undefined-values.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
println(Void);
|
||||
1+Void
|
||||
if(Void){} else { 23 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue