add demo docs

This commit is contained in:
nightwing 2013-04-06 12:53:21 +04:00
commit 73f299d3f0
12 changed files with 243 additions and 9 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@
.*
!/.gitignore
.*.gz
*.tmTheme.js
# A handy place to put stuff that git should ignore:
/ignore/

View file

@ -135,7 +135,16 @@ var docs = {
"docs/xml.xml": "XML",
"docs/xquery.xq": "XQuery",
"docs/yaml.yaml": "YAML",
"docs/c9search.c9search_results": "C9 Search Results"
"docs/c9search.c9search_results": "C9 Search Results",
"docs/actionscript.as": "ActionScript",
"docs/erlang/erl": "Erlang",
"docs/forth.frt": "Forth",
"docs/fortran.f95": "Fortran",
"docs/haskell.hs": "Haskell",
"docs/julia.js": "Julia",
"docs/prolog/plg": "Prolog",
"docs/rust.rs": "Rust"
};
var ownSource = {

View 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();
}
}
}

View 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).

View 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
;

View 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)

View 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)

View 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

View 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).

View 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;
}

View file

@ -35,7 +35,6 @@ Mode.prototype.supportsFile = function(filename) {
};
var modesByName = {
abap: ["ABAP" , "abap"],
asciidoc: ["AsciiDoc" , "asciidoc"],
c9search: ["C9Search" , "c9search_results"],
coffee: ["CoffeeScript" , "^Cakefile|coffee|cf|cson"],
@ -100,12 +99,24 @@ var modesByName = {
text: ["Text" , "txt"],
textile: ["Textile" , "textile"],
tmsnippet: ["tmSnippet" , "tmSnippet"],
toml: ["toml" , "toml"],
toml: ["Toml" , "toml"],
typescript: ["Typescript" , "typescript|ts|str"],
vbscript: ["VBScript" , "vbs"],
xml: ["XML" , "xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
xquery: ["XQuery" , "xq"],
yaml: ["YAML" , "yaml"]
yaml: ["YAML" , "yaml"],
abap: ["ABAP" , "abap"],
actionscript: ["ActionScript" ,"as"],
erlang: ["Erlang" ,"erl|hrl"],
forth: ["Forth", ,"frt|fs|ldr"],
fortran_modern: ["Fortran - Modern", ,"f90|F90|f95|F95|f03|F03|f08|F08"],
haskell: ["Haskell", "hs"],
julia: ["Julia", "jl"],
prolog: ["Prolog", "plg|prolog"],
rust: ["Rust", "rs|rc"]
};
for (var name in modesByName) {

View file

@ -63,17 +63,17 @@ var RustHighlightRules = function() {
next: 'pop' },
{ include: '#rust_escaped_character' },
{ defaultToken: 'string.quoted.double.source.rust' } ] },
{ token:
[ 'keyword.source.rust',
'meta.function.source.rust',
'entity.name.function.source.rust',
'meta.function.source.rust' ],
{ token: [ 'keyword.source.rust', 'meta.function.source.rust',
'entity.name.function.source.rust', 'meta.function.source.rust' ],
regex: '\\b(fn)(\\s+)([a-zA-Z_][a-zA-Z0-9_][\\w\\:,+ \\\'<>]*)(\\s*\\()' },
{ token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
{ token: 'keyword.source.rust',
regex: '\\b(?:as|assert|break|claim|const|copy|Copy|do|drop|else|extern|fail|for|if|impl|in|let|log|loop|match|mod|module|move|mut|Owned|priv|pub|pure|ref|return|unchecked|unsafe|use|while|mod|Send|static|trait|class|struct|enum|type)\\b' },
{ token: 'storage.type.source.rust',
regex: '\\b(?:Self|m32|m64|m128|f80|f16|f128|int|uint|float|char|bool|u8|u16|u32|u64|f32|f64|i8|i16|i32|i64|str|option|either|c_float|c_double|c_void|FILE|fpos_t|DIR|dirent|c_char|c_schar|c_uchar|c_short|c_ushort|c_int|c_uint|c_long|c_ulong|size_t|ptrdiff_t|clock_t|time_t|c_longlong|c_ulonglong|intptr_t|uintptr_t|off_t|dev_t|ino_t|pid_t|mode_t|ssize_t)\\b' },
{ token: 'variable.language.source.rust', regex: '\\bself\\b' },
{ token: 'keyword.operator',
regex: '!|\\$|\\*|\\-\\-|\\-|\\+\\+|\\+|-->|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|/=|%=|\\+=|\\-=|&=|\\^=|,|;' },
{ token: 'constant.language.source.rust',
regex: '\\b(?:true|false|Some|None|Left|Right|Ok|Err)\\b' },
{ token: 'support.constant.source.rust',