langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,2 @@
var a = 42
assert(a == 42)

View file

@ -0,0 +1,3 @@
let a = get_some_value () in
assert (a = 42); (* throws Assert_failure when a is not 42 *)
(* evaluate stuff to return here when a is 42 *)

View file

@ -0,0 +1,7 @@
MODULE Assertions;
VAR
a: INTEGER;
BEGIN
a := 40;
ASSERT(a = 42);
END Assertions.

View file

@ -0,0 +1 @@
NSAssert(a == 42, @"Error message");

View file

@ -0,0 +1 @@
NSAssert1(a == 42, @"a is not 42, a is actually %d", a); # has 1 formatting arg, so use NSAssert"1"

View file

@ -0,0 +1,8 @@
declare
proc {PrintNumber N}
N=42 %% assert
{Show N}
end
in
{PrintNumber 42} %% ok
{PrintNumber 11} %% throws

View file

@ -0,0 +1,10 @@
#include <assert.h>
void
test()
{
int a;
// ... input or change a here
assert(a == 42); // Aborts program if a is not 42, unless the NDEBUG macro was defined
}

View file

@ -0,0 +1,18 @@
/* PL/I does not have an assert function as such, */
/* but it is something that can be implemented in */
/* any of several ways. A straight-forward way */
/* raises a user-defined interrupt. */
on condition (assert_failure) snap
put skip list ('Assert failure');
....
if a ^= b then signal condition(assert_failure);
/* Another way is to use the preprocessor, thus: */
%assert: procedure (a, b) returns (character);
return ('if ' || a || '^=' || b ||
' then signal condition(assert_failure);');
%end assert;
%activate assert;
assert(a, 42);

View file

@ -0,0 +1,8 @@
my $a = (1..100).pick;
# with a (non-hygienic) macro
macro assert ($x) { "$x or die 'assertion failed: $x'" }
assert('$a == 42');
# but usually we just say
$a == 42 or die "$x ain't 42";

View file

@ -0,0 +1,8 @@
Macro Assert(TEST,MSG="Assert: ")
CompilerIf #PB_Compiler_Debugger
If Not (TEST)
Debug MSG+" Line="+Str(#PB_Compiler_Line)+" in "+#PB_Compiler_File
CallDebugger
EndIf
CompilerEndIf
EndMacro

View file

@ -0,0 +1,4 @@
A=42
Assert(A=42,"Assert that A=42")
A=42-1
Assert(A=42)

View file

@ -0,0 +1,6 @@
// test if 'a' is 42, and if not stop the execution of the code and print
// some error message
if (a != 42)
{
stop("a is not 42 as expected, therefore I stop until this issue is resolved!");
}

View file

@ -0,0 +1 @@
-# check X = 42;

View file

@ -0,0 +1 @@
-# assert X = 42;

View file

@ -0,0 +1,3 @@
procedure P (X : in out Integer);
--# derives X from *;
--# pre X = 42;

View file

@ -0,0 +1,3 @@
procedure P (X : in out Integer);
--# derives X from *;
--# post X = 42;

View file

@ -0,0 +1,2 @@
X := 7;
--# check X = 42;

View file

@ -0,0 +1,3 @@
load: 'src/lib/assert.slate'.
define: #n -> 7.
assert: n = 42 &description: 'That is not the Answer.'.

View file

@ -0,0 +1,5 @@
sub Assert( boolExpr, strOnFail )
if not boolExpr then
Err.Raise vbObjectError + 99999, , strOnFail
end if
end sub

View file

@ -0,0 +1,3 @@
dim i
i = 43
Assert i=42, "There's got to be more to life than this!"

View file

@ -0,0 +1,2 @@
>cscript "C:\foo\assert.vbs"
C:\foo\assert.vbs(3, 3) (null): There's got to be more to life than this!

View file

@ -0,0 +1,4 @@
int a = 42;
int b = 33;
assert (a == 42);
assert (b == 42); // will break the program with "assertion failed" error

View file

@ -0,0 +1 @@
Debug.Assert i = 42

View file

@ -0,0 +1,10 @@
proc Fatal(Str); \Display error message and terminate program
char Str;
[\return; uncomment this if "assertions" are to be disabled
SetVid(3); \set normal text display if program uses graphics
Text(0, Str); \display error message
ChOut(0, 7); \sound the bell
exit 1; \terminate the program; pass optional error code to DOS
];
if X#42 then Fatal("X#42");