This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on run | |
| sum({1, 2, 3, {1, 2}}) | |
| end run | |
| on sum(arg) | |
| -- 数値リストの総和を求める | |
| -- リストが含まれている場合は再帰的に中身も合計する | |
| if arg is equal to {} then | |
| set result to 0 | |
| else if class of arg's first item is equal to list then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set src to choose folder | |
| set target_files to getFiles(src) | |
| tell application "iTunes" | |
| repeat with f in target_files | |
| try | |
| add f | |
| delay 1 | |
| on error | |
| log f | |
| end try |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let cut l n = | |
| List.fold_left ( | |
| fun prev next -> | |
| if (List.fold_left (fun prev next -> prev + next) 0 prev) + next > n | |
| then prev | |
| else prev @ [next] | |
| ) [] l;; | |
| cut [1;2;3;4;5;6;7;8;9] 18;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use 5.12.0; | |
| my $usage = <<EOS | |
| usage: \$runocaml filename | |
| EOS | |
| ; | |
| my $filename = shift // die "Error: No filename \n$usage"; | |
| -f $filename or die "$filename not found.\n$usage"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let diff xs ys = | |
| let rec internal xs ys ans = | |
| match xs with | |
| | hd::tl -> | |
| if List.mem hd ys then internal tl ys ans | |
| else internal tl ys (ans @ [hd]) | |
| | _ -> ans | |
| in | |
| internal xs ys [];; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec balance (t:'a tree) : int tree = | |
| let rec height t = | |
| match t with | |
| | Br(_,left,right) -> | |
| let (hl, hr) = (height left, height right) in | |
| if (hl > hr) then hl + 1 else hr + 1 | |
| | _ -> 0 | |
| in | |
| match t with | |
| | Br(value, left, right) -> Br(height left - height right, balance left, balance right) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| role Value[::Type] { | |
| has Type $.value; | |
| has @.exp; | |
| multi method new (Type $v, @exp) { | |
| self.bless(*, value => $v, exp => @exp); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| class Settings { | |
| has Int $.port; | |
| has Str $.document_root; | |
| method new(Str $path) { | |
| my @settings = $path.IO.lines; | |
| my $portline = @settings.grep(/port\=<.digit>*$$/)[0]; | |
| my $port = $portline.substr(5).Int; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| grammar Expression { | |
| rule num { \d+ } | |
| rule qexp { '(' <exp> ')' } | |
| rule atom { <exp2> || <num> || <qexp> } | |
| rule ops { <.ws><ops1><.ws> || <.ws><ops2><.ws> } | |
| token ops1 { '+'|'-' } | |
| token ops2{ '*'|'/' } | |
| rule exp { <atom>+ % <ops> } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all: y.tab.c lex.yy.c | |
| cc -DYYERROR_VERBOSE -DYYDEBUG -o Parse y.tab.c lex.yy.c | |
| y.tab.c: | |
| yacc -dv parser.y | |
| lex.yy.c: y.tab.c | |
| lex parser.l |