Clip/Examples
Jump to navigation
Jump to search
Examples for the Clip programming language.
Hello world
"Hello world
Self-explanatory, but note that the closing quotation mark is not needed.
Cat
When compiled, this is expanded to:
[M ]
Thus, the main supplier hits the end of the program, so it asks the user for the next line of input.
Quine
-12.3
A less trivial quine:
F"[Fx{'F\xx`"[Fx{'F\xx`
Or just:
[t+t\t]"[t+t\t]"
Factorial
r*`,On
r .- reduce -. *` .- with multiplication -. , .- the list of numbers from -. O .- 1 to -. n .- the number represented by -. [implicit] the next line of input.
Fibonacci (inefficient)
Fn[Fx?<x3O]+F(xF((x
F .- apply the function F to -. n .- the number represented by -. [implicit] the next line of input [Fx .- define F as a function of x -. ? .- if -. <x3 .- x is less than 3 -. O .- then 1 -. ] .- else -. + .- the sum of -. F .- the function F applied to -. (x .- one less than x -. F .- the function F applied to -. ( .- one less than -. (x .- one less than x -.
Fibonacci (efficient)
FZOn[Fx[y[z?zFy+xy(z]x]}}
F .- apply the function F to -. Z .- 0 -. O .- 1 -. n .- the number represented by -. [implicit] the next line of input [Fx .- define F as a function of x -. [y .- a function of y -. [z .- a function of z -. ? .- if -. z .- z isn't zero -. F .- then apply F to -. y .- y -. +xy .- the sum of x and y -. (z .- one less than z -. ] .- else -. x .- x -. ] .- end if statement -. } .- return function of z -. } .- return function of y -.