add demo docs
This commit is contained in:
parent
5d63adb2a7
commit
73f299d3f0
12 changed files with 243 additions and 9 deletions
51
demo/kitchen-sink/docs/actionscript.as
Normal file
51
demo/kitchen-sink/docs/actionscript.as
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package code
|
||||
{
|
||||
/*****************************************
|
||||
* based on textmate actionscript bundle
|
||||
****************************************/
|
||||
|
||||
import fl.events.SliderEvent;
|
||||
|
||||
public class Foo extends MovieClip
|
||||
{
|
||||
//*************************
|
||||
// Properties:
|
||||
|
||||
public var activeSwatch:MovieClip;
|
||||
|
||||
// Color offsets
|
||||
public var c1:Number = 0; // R
|
||||
|
||||
//*************************
|
||||
// Constructor:
|
||||
|
||||
public function Foo()
|
||||
{
|
||||
// Respond to mouse events
|
||||
swatch1_btn.addEventListener(MouseEvent.CLICK,swatchHandler,false,0,false);
|
||||
previewBox_btn.addEventListener(MouseEvent.MOUSE_DOWN,dragPressHandler);
|
||||
|
||||
// Respond to drag events
|
||||
red_slider.addEventListener(SliderEvent.THUMB_DRAG,sliderHandler);
|
||||
|
||||
// Draw a frame later
|
||||
addEventListener(Event.ENTER_FRAME,draw);
|
||||
}
|
||||
|
||||
protected function clickHandler(event:MouseEvent):void
|
||||
{
|
||||
car.transform.colorTransform = new ColorTransform(0,0,0,1,c1,c2,c3);
|
||||
}
|
||||
|
||||
protected function changeRGBHandler(event:Event):void
|
||||
{
|
||||
c1 = Number(c1_txt.text);
|
||||
|
||||
if(!(c1>=0)){
|
||||
c1 = 0;
|
||||
}
|
||||
|
||||
updateSliders();
|
||||
}
|
||||
}
|
||||
}
|
||||
20
demo/kitchen-sink/docs/erlang.erl
Normal file
20
demo/kitchen-sink/docs/erlang.erl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%% A process whose only job is to keep a counter.
|
||||
%% First version
|
||||
-module(counter).
|
||||
-export([start/0, codeswitch/1]).
|
||||
|
||||
start() -> loop(0).
|
||||
|
||||
loop(Sum) ->
|
||||
receive
|
||||
{increment, Count} ->
|
||||
loop(Sum+Count);
|
||||
{counter, Pid} ->
|
||||
Pid ! {counter, Sum},
|
||||
loop(Sum);
|
||||
code_switch ->
|
||||
?MODULE:codeswitch(Sum)
|
||||
% Force the use of 'codeswitch/1' from the latest MODULE version
|
||||
end.
|
||||
|
||||
codeswitch(Sum) -> loop(Sum).
|
||||
41
demo/kitchen-sink/docs/forth.frt
Normal file
41
demo/kitchen-sink/docs/forth.frt
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
: HELLO ( -- ) CR ." Hello, world!" ;
|
||||
|
||||
HELLO <cr>
|
||||
Hello, world!
|
||||
|
||||
: [CHAR] CHAR POSTPONE LITERAL ; IMMEDIATE
|
||||
|
||||
0 value ii 0 value jj
|
||||
0 value KeyAddr 0 value KeyLen
|
||||
create SArray 256 allot \ state array of 256 bytes
|
||||
: KeyArray KeyLen mod KeyAddr ;
|
||||
|
||||
: get_byte + c@ ;
|
||||
: set_byte + c! ;
|
||||
: as_byte 255 and ;
|
||||
: reset_ij 0 TO ii 0 TO jj ;
|
||||
: i_update 1 + as_byte TO ii ;
|
||||
: j_update ii SArray get_byte + as_byte TO jj ;
|
||||
: swap_s_ij
|
||||
jj SArray get_byte
|
||||
ii SArray get_byte jj SArray set_byte
|
||||
ii SArray set_byte
|
||||
;
|
||||
|
||||
: rc4_init ( KeyAddr KeyLen -- )
|
||||
256 min TO KeyLen TO KeyAddr
|
||||
256 0 DO i i SArray set_byte LOOP
|
||||
reset_ij
|
||||
BEGIN
|
||||
ii KeyArray get_byte jj + j_update
|
||||
swap_s_ij
|
||||
ii 255 < WHILE
|
||||
ii i_update
|
||||
REPEAT
|
||||
reset_ij
|
||||
;
|
||||
: rc4_byte
|
||||
ii i_update jj j_update
|
||||
swap_s_ij
|
||||
ii SArray get_byte jj SArray get_byte + as_byte SArray get_byte xor
|
||||
;
|
||||
28
demo/kitchen-sink/docs/fortran.f95
Normal file
28
demo/kitchen-sink/docs/fortran.f95
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
! sum.f90
|
||||
! Performs summations using in a loop using EXIT statement
|
||||
! Saves input information and the summation in a data file
|
||||
|
||||
program summation
|
||||
implicit none
|
||||
integer :: sum, a
|
||||
|
||||
print*, "This program performs summations. Enter 0 to stop."
|
||||
open(unit=10, file="SumData.DAT")
|
||||
|
||||
sum = 0
|
||||
|
||||
do
|
||||
print*, "Add:"
|
||||
read*, a
|
||||
if (a == 0) then
|
||||
exit
|
||||
else
|
||||
sum = sum + a
|
||||
end if
|
||||
write(10,*) a
|
||||
end do
|
||||
|
||||
print*, "Summation =", sum
|
||||
write(10,*) "Summation =", sum
|
||||
close(10)
|
||||
|
||||
20
demo/kitchen-sink/docs/haskell.hs
Normal file
20
demo/kitchen-sink/docs/haskell.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
-- Type annotation (optional)
|
||||
fib :: Int -> Integer
|
||||
|
||||
-- With self-referencing data
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : scanl (+) 1 fibs
|
||||
-- 0,1,1,2,3,5,...
|
||||
|
||||
-- Same, coded directly
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : 1 : next fibs
|
||||
next (a : t@(b:_)) = (a+b) : next t
|
||||
|
||||
-- Similar idea, using zipWith
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
|
||||
|
||||
-- Using a generator function
|
||||
fib n = fibs (0,1) !! n
|
||||
where fibs (a,b) = a : fibs (b,a+b)
|
||||
15
demo/kitchen-sink/docs/julia.jl
Normal file
15
demo/kitchen-sink/docs/julia.jl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
for op = (:+, :*, :&, :|, :$)
|
||||
@eval ($op)(a,b,c) = ($op)(($op)(a,b),c)
|
||||
end
|
||||
|
||||
|
||||
function g(x,y)
|
||||
return x * y
|
||||
x + y
|
||||
end
|
||||
|
||||
cd("data") do
|
||||
open("outfile", "w") do f
|
||||
write(f, data)
|
||||
end
|
||||
end
|
||||
18
demo/kitchen-sink/docs/prolog.plg
Normal file
18
demo/kitchen-sink/docs/prolog.plg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
partition([], _, [], []).
|
||||
partition([X|Xs], Pivot, Smalls, Bigs) :-
|
||||
( X @< Pivot ->
|
||||
Smalls = [X|Rest],
|
||||
partition(Xs, Pivot, Rest, Bigs)
|
||||
; Bigs = [X|Rest],
|
||||
partition(Xs, Pivot, Smalls, Rest)
|
||||
).
|
||||
|
||||
quicksort([]) --> [].
|
||||
quicksort([X|Xs]) -->
|
||||
{ partition(Xs, X, Smaller, Bigger) },
|
||||
quicksort(Smaller), [X], quicksort(Bigger).
|
||||
|
||||
perfect(N) :-
|
||||
between(1, inf, N), U is N // 2,
|
||||
findall(D, (between(1,U,D), N mod D =:= 0), Ds),
|
||||
sumlist(Ds, N).
|
||||
20
demo/kitchen-sink/docs/rust.rs
Normal file
20
demo/kitchen-sink/docs/rust.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use core::rand::RngUtil;
|
||||
|
||||
fn main() {
|
||||
for ["Alice", "Bob", "Carol"].each |&name| {
|
||||
do spawn {
|
||||
let v = rand::Rng().shuffle([1, 2, 3]);
|
||||
for v.each |&num| {
|
||||
print(fmt!("%s says: '%d'\n", name, num + 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
|
||||
let mut accumulator = ~[];
|
||||
for vec::each(vector) |element| {
|
||||
accumulator.push(function(element));
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue