3 ms·
The largest n-tuple in Lisp
The following expression defines a function called double which returns twice its argument:
CL-USER 17 : 8 > (defun double (x) (* x 2))
DOUBLE
Having fed this to Lisp, we can call double in other functions, or from the top level:
CL-USER 18 : 8 > (double 1)
2
CL-USER 18 : 8 > (double 2)
4
CL-USER 18 : 8 > (double 4)
8
I experimented and realised that this works with triple too :
CL-USER 21 : 8 > (defun triple (x) (* x 3))
TRIPLE
CL-USER 22 : 8 > (triple 3)
9
CL-USER 23 : 8 > (triple 6)
18
CL-USER 24 : 8 > (triple 1)
3
This works for quadruple too: I can define a function called quadruple which returns four times its argument :
CL-USER 25 : 8 > (defun quadruple (x) (* x 4))
QUADRUPLE
CL-USER 26 : 8 > (quadruple 4)
16
CL-USER 27 : 8 > (quadruple 8)
32
CL-USER 28 : 8 > (quadruple 16)
64
Works for quintuple too ! :
CL-USER 9 : 2 > (defun quintuple (x) (* x 5))
QUINTUPLE
CL-USER 10 : 2 > (quintuple 4)
20
CL-USER 11 : 2 > (quintuple 5)
25
I then tried a far larger n-tuple : centuple and it works as well !
CL-USER 12 : 2 > (defun centuple (x) (* x 100))
CENTUPLE
CL-USER 13 : 2 > (centuple 6)
600
CL-USER 14 : 2 > (centuple 8)
800
Later on, I realised that there is no limit and you can in fact define n-tuples even up to sextillion in Lisp!
- bbcbasic 11y agoI am not familiar with Lisp but these don't look like n-tuples to me. Is it just a function that multiplies a value by a fixed number? As I understand it, a tuple is a collection of typed objects. E.g. in C# the type Tuple<Int,Bool> or Haskell (Int,Bool)
- CaiGengYang 11y agoYup, It is just a function that multiplies a value by a fixed number. I just named it n-tuple because it rhymes : quadruple, centuple, but perhaps it was the wrong way to name it. I was just surprised to realise that there is no limit to the value of n for this type of function that multiplies a value by a fixed number, so I put this on Hackernews. It was a surprising result, at least to me ...
- bbcbasic 11y agoSame in Haskell there is Int for your normal bounded integer (28 bit I think) and there is Integer which is bounded only by the amount of memory you can allocate on the heap.