Talk:Function definition

From Rosetta Code
Revision as of 19:56, 1 March 2008 by Ce (talk | contribs) (New section: Lisp, BASIC)

"multiplication" is a somewhat ambiguous mathematical operation depending on the data type. I don't think it's a big deal, I am assuming that the arguments are supposed to be scalars and such, but in a vector language like IDL where one rarely encounters scalars, there is a distinction to be made between "product of the elements of the vectors" or "inner product of the vectors" or "outer product of the vectors" or "matrix multiplication". Just figured I'd mention this somewhere... Sgeier 19:08, 4 December 2007 (MST)

Lisp, BASIC

While I indeed just had overlooked the existing Common Lisp implementation, I don't agree with the change comment:

IMHO Lisp is a language, and Common Lisp is a Lisp dialect.

And of course, Scheme is not Lisp, but a separate (but similar) language, which BTW also has several dialects.

Indeed, the example which I wrote (and which, not surprisingly, turns out to be identical to the Common Lisp example) should work in any Lisp.

OTOH, I'd question that BASIC could be considered a single language. While there's an original BASIC language (although even then there were lots of dialects), the languages which are called "BASIC" today differ far more from original BASIC than e.g. C++ differs from C. BTW, original BASIC didn't have functions in the full meaning of the word, but the closest was GOSUB. For example, an approximation of the task would look like this:

10 LET i = 10 : REM many BASIC dialects allowed to omit the LET
20 LET j = 20
30 GOSUB 100
40 PRINT result
50 END
100 REM This is the "function"
110 LET result = i*j
120 RETURN

However, some BASIC dialects (like the ZX Spectrum's BASIC) allowed to define functions consisting just of one expression, e.g.

10 DEF FN f(x,y)=x*y: REM the ZX Spectrum BASIC only allowed one-letter function names
20 PRINT FN f(2,3)

The QuickBasic language used in the example was already quite far away from the original BASIC language (no line numbers, true functions, named types, user-defined types).