1/* 2 * varargs - example of a varargs-like use 3 * 4 * Copyright (C) 1999 David I. Bell 5 * 6 * Calc is open software; you can redistribute it and/or modify it under 7 * the terms of the version 2.1 of the GNU Lesser General Public License 8 * as published by the Free Software Foundation. 9 * 10 * Calc is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 13 * Public License for more details. 14 * 15 * A copy of version 2.1 of the GNU Lesser General Public License is 16 * distributed with calc under the filename COPYING-LGPL. You should have 17 * received a copy with calc; if not, write to Free Software Foundation, Inc. 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 * Under source code control: 1991/05/22 21:56:34 21 * File existed as early as: 1991 22 * 23 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ 24 */ 25 26/* 27 * Example program to use 'varargs'. 28 * 29 * Program to sum the cubes of all the specified numbers. 30 */ 31 32 33define sc() 34{ 35 local s, i; 36 37 s = 0; 38 for (i = 1; i <= param(0); i++) { 39 if (!isnum(param(i))) { 40 print "parameter",i,"is not a number"; 41 continue; 42 } 43 s += param(i)^3; 44 } 45 return s; 46} 47 48if (config("resource_debug") & 3) { 49 print "sc(a, b, ...) defined"; 50} 51