/* prelude.q: standard prelude $Id: prelude.q,v 1.4 2005/07/12 22:15:52 agraef Exp $ */ /* This file is part of the Q programming system. The Q programming system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Q programming system is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ include assert, clib, complex, cond, error, lambda, list, math, sort, stdlib, stdtypes, stream, string, typec; /* Builtin operators. These are already predeclared by the compiler anyway, but we list them here for documentation and sanity-checking purposes. */ public (||) X Y @0, ($) X Y @1; public (<) X Y @2, (<=) X Y @2, (>) X Y @2, (>=) X Y @2, (=) X Y @2, (<>) X Y @2; public (++) X Y @3, (+) X Y @3, (-) X Y @3, (or) X Y @3; public special (or else) ~X Y @3; public (*) X Y @4, (/) X Y @4, (div) X Y @4, (mod) X Y @4, (and) X Y @4; public special (and then) ~X Y @4; public (#) X @5, (not) X @5; public (^) X Y @6, (!) X Y @6; public (.) X Y @7; public special const (') X @9; public (`) X @9, (~) X @9; /* Overloaded successor and predecessor functions on integers. */ pred N:Int = N-1; succ N:Int = N+1; /* Overloaded enumeration operations on numbers. */ enum X:Num Y:Num = nums X Y; [X:Num..Y:Num] = nums X Y; [X:Num,Y:Num..Z:Num] = numsby (Y-X) X Z; /* Equality for lists and tuples, and lexicographic list ordering. */ ([] = []) = true; ([] = [X|Xs]) = false; ([X|Xs] = []) = false; ([X|Xs] = [Y|Ys]) = (X=Y) and then (Xs=Ys); [] <> [] = false; [] <> [X|Xs] = true; [X|Xs] <> [] = true; [X|Xs] <> [Y|Ys] = (X<>Y) or else (Xs<>Ys); [] < [] = false; [] < [X|Xs] = true; [X|Xs] < [] = false; [X|Xs] < [Y|Ys] = (X [] = false; [] > [X|Xs] = false; [X|Xs] > [] = true; [X|Xs] > [Y|Ys] = (X>Y) or else (X=Y) and then (Xs>Ys); [] <= [] = true; [] <= [X|Xs] = true; [X|Xs] <= [] = false; [X|Xs] <= [Y|Ys] = (X= [] = true; [] >= [X|Xs] = false; [X|Xs] >= [] = true; [X|Xs] >= [Y|Ys] = (X>Y) or else (X=Y) and then (Xs>=Ys); (() = ()) = true; (() = (X|Xs)) = false; ((X|Xs) = ()) = false; ((X|Xs) = (Y|Ys)) = (X=Y) and then (Xs=Ys); () <> () = false; () <> (X|Xs) = true; (X|Xs) <> () = true; (X|Xs) <> (Y|Ys) = (X<>Y) or else (Xs<>Ys);