diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 955becb3..b4972eb7 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -426,6 +426,11 @@ module Linguist # # Returns the extensions Array attr_reader :filenames + + # Public: Return all possible extensions for language + def all_extensions + (extensions + [primary_extension]).uniq + end # Public: Get URL escaped name. # diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0508dcaf..a7383dc2 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -332,8 +332,6 @@ Cirru: # ace_mode: cirru # lexer: Cirru lexer: Text only - extensions: - - .cr Clean: type: programming diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 793b2816..88d7253c 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -88,6 +88,7 @@ ".coffee" ], "Common Lisp": [ + ".cl", ".lisp" ], "Coq": [ @@ -381,6 +382,7 @@ ".fcgi", ".pl", ".pm", + ".pod", ".script!", ".t" ], @@ -426,6 +428,7 @@ ], "R": [ ".R", + ".r", ".rsx", ".script!" ], @@ -582,6 +585,7 @@ "XML": [ ".ant", ".ivy", + ".pluginspec", ".xml" ], "XProc": [ @@ -664,8 +668,8 @@ ".gemrc" ] }, - "tokens_total": 584718, - "languages_total": 699, + "tokens_total": 587528, + "languages_total": 704, "tokens": { "ABAP": { "*/**": 1, @@ -14767,46 +14771,333 @@ "ip.join": 1 }, "Common Lisp": { - ";": 10, - "-": 10, + ";": 152, + "@file": 1, + "macros": 2, + "-": 161, + "advanced.cl": 1, + "@breif": 1, + "Advanced": 1, + "macro": 5, + "practices": 1, + "defining": 1, + "your": 1, + "own": 1, + "Macro": 1, + "definition": 1, + "skeleton": 1, + "(": 365, + "defmacro": 5, + "name": 6, + "parameter*": 1, + ")": 372, + "body": 8, + "form*": 1, + "Note": 2, + "that": 5, + "backquote": 1, + "expression": 2, + "is": 6, + "most": 2, + "often": 1, + "used": 2, + "in": 23, + "the": 35, + "form": 1, + "primep": 4, + "test": 1, + "a": 7, + "number": 2, + "for": 3, + "prime": 12, + "defun": 23, + "n": 8, + "if": 14, + "<": 1, + "return": 3, + "from": 8, + "do": 9, + "i": 8, + "+": 35, + "p": 10, + "t": 7, + "not": 6, + "zerop": 1, + "mod": 1, + "sqrt": 1, + "when": 4, + "next": 11, + "bigger": 1, + "than": 1, + "specified": 2, + "The": 2, + "recommended": 1, + "procedures": 1, + "to": 4, + "writting": 1, + "new": 6, + "are": 2, + "as": 1, + "follows": 1, + "Write": 2, + "sample": 2, + "call": 2, + "and": 12, + "code": 2, + "it": 2, + "should": 1, + "expand": 1, + "into": 2, + "primes": 3, + "format": 3, + "Expected": 1, + "expanded": 1, + "codes": 1, + "generate": 1, + "hardwritten": 1, + "expansion": 2, + "arguments": 1, + "var": 49, + "range": 4, + "&": 8, + "rest": 5, + "let": 6, + "first": 5, + "start": 5, + "second": 3, + "end": 8, + "third": 2, + "@body": 4, + "More": 1, + "concise": 1, + "implementations": 1, + "with": 7, + "synonym": 1, + "also": 1, + "emits": 1, + "more": 1, + "friendly": 1, + "messages": 1, + "on": 1, + "incorrent": 1, + "input.": 1, + "Test": 1, + "result": 1, + "of": 3, + "macroexpand": 2, + "function": 2, + "gensyms": 4, + "value": 8, + "Define": 1, + "note": 1, + "how": 1, + "comma": 1, + "interpolate": 1, + "loop": 2, + "names": 2, + "collect": 1, + "gensym": 1, + "#": 15, + "|": 9, + "ESCUELA": 1, + "POLITECNICA": 1, + "SUPERIOR": 1, + "UNIVERSIDAD": 1, + "AUTONOMA": 1, + "DE": 1, + "MADRID": 1, + "INTELIGENCIA": 1, + "ARTIFICIAL": 1, + "Motor": 1, + "de": 2, + "inferencia": 1, + "Basado": 1, + "en": 2, + "parte": 1, + "Peter": 1, + "Norvig": 1, + "Global": 1, + "variables": 6, + "defvar": 4, + "*hypothesis": 1, + "list*": 7, + "*rule": 4, + "*fact": 2, + "Constants": 1, + "defconstant": 2, + "fail": 10, + "nil": 3, + "no": 6, + "bindings": 45, + "lambda": 4, + "b": 6, + "mapcar": 2, + "man": 3, + "luis": 1, + "pedro": 1, + "woman": 2, + "mart": 1, + "daniel": 1, + "laura": 1, + "facts": 1, + "x": 47, + "aux": 3, + "unify": 12, + "hypothesis": 10, + "list": 9, + "____________________________________________________________________________": 5, + "FUNCTION": 3, + "FIND": 1, + "RULES": 2, + "COMMENTS": 3, + "Returns": 2, + "rules": 5, + "whose": 1, + "THENs": 1, + "term": 1, + "given": 3, + "": 2, + "satisfy": 1, + "this": 1, + "requirement": 1, + "renamed.": 1, + "EXAMPLES": 2, + "setq": 1, + "renamed": 3, + "rule": 17, + "rename": 1, + "then": 7, + "unless": 3, + "null": 1, + "equal": 4, + "VALUE": 1, + "FROM": 1, + "all": 2, + "solutions": 1, + "found": 5, + "using": 1, + "": 1, + ".": 10, + "single": 1, + "can": 4, + "have": 1, + "multiple": 1, + "solutions.": 1, + "mapcan": 1, + "R1": 2, + "pertenece": 3, + "E": 4, + "_": 8, + "R2": 2, + "Xs": 2, + "Then": 1, + "EVAL": 2, + "RULE": 2, + "PERTENECE": 6, + "E.42": 2, + "returns": 4, + "NIL": 3, + "That": 2, + "query": 4, + "be": 2, + "proven": 2, + "binding": 17, + "necessary": 2, + "fact": 4, + "has": 1, + "On": 1, + "other": 1, + "hand": 1, + "E.49": 2, + "XS.50": 2, + "R2.": 1, + "eval": 6, + "ifs": 1, + "NOT": 2, + "question": 1, + "T": 1, + "equality": 2, + "UNIFY": 1, + "Finds": 1, + "general": 1, + "unifier": 1, + "two": 2, + "input": 2, + "expressions": 2, + "taking": 1, + "account": 1, + "": 1, + "In": 1, + "case": 1, + "total": 1, + "unification.": 1, + "Otherwise": 1, + "which": 1, + "constant": 1, + "anonymous": 4, + "make": 4, + "variable": 6, + "Auxiliary": 1, + "Functions": 1, + "cond": 3, + "or": 4, + "get": 5, + "lookup": 5, + "occurs": 5, + "extend": 2, + "symbolp": 2, + "eql": 2, + "char": 2, + "symbol": 2, + "assoc": 1, + "car": 2, + "val": 6, + "cdr": 2, + "cons": 2, + "append": 1, + "eq": 7, + "consp": 2, + "subst": 3, + "listp": 1, + "exp": 1, + "unique": 3, + "find": 6, + "anywhere": 6, + "predicate": 8, + "tree": 11, + "optional": 2, + "so": 4, + "far": 4, + "atom": 3, + "funcall": 2, + "pushnew": 1, + "gentemp": 2, + "quote": 3, + "s/reuse": 1, + "cons/cons": 1, + "expresion": 2, + "some": 1, + "EOF": 1, "*": 2, "lisp": 1, - "(": 14, - "in": 1, "package": 1, "foo": 2, - ")": 14, "Header": 1, "comment.": 4, - "defvar": 1, "*foo*": 1, - "eval": 1, - "when": 1, "execute": 1, "compile": 1, "toplevel": 2, "load": 1, - "defun": 1, "add": 1, - "x": 5, - "&": 3, - "optional": 1, "y": 2, "key": 1, "z": 2, "declare": 1, "ignore": 1, "Inline": 1, - "+": 2, - "or": 1, - "#": 2, - "|": 2, "Multi": 1, "line": 2, - "defmacro": 1, - "body": 1, - "b": 1, - "if": 1, "After": 1 }, "Coq": { @@ -46603,29 +46894,29 @@ "package": 14, "App": 131, "Ack": 136, - ";": 1185, - "use": 76, - "warnings": 16, - "strict": 16, + ";": 1193, + "use": 83, + "warnings": 18, + "strict": 18, "File": 54, "Next": 27, "Plugin": 2, "Basic": 10, - "head1": 31, - "NAME": 5, - "-": 860, + "head1": 36, + "NAME": 6, + "-": 868, "A": 2, "container": 1, - "for": 78, + "for": 83, "functions": 2, - "the": 131, + "the": 143, "ack": 38, "program": 6, "VERSION": 15, "Version": 1, - "cut": 27, + "cut": 28, "our": 34, - "COPYRIGHT": 6, + "COPYRIGHT": 7, "BEGIN": 7, "{": 1121, "}": 1134, @@ -46642,8 +46933,8 @@ "is_cygwin": 6, "is_windows": 12, "Spec": 13, - "(": 919, - ")": 917, + "(": 925, + ")": 923, "Glob": 4, "Getopt": 6, "Long": 6, @@ -46658,27 +46949,27 @@ "actionscript": 2, "[": 159, "qw": 35, - "as": 33, + "as": 37, "mxml": 2, "]": 155, "ada": 4, "adb": 2, "ads": 2, "asm": 4, - "s": 34, + "s": 35, "batch": 2, "bat": 2, "cmd": 2, "binary": 3, "q": 5, "Binary": 2, - "files": 41, + "files": 42, "defined": 54, - "by": 11, - "Perl": 6, + "by": 16, + "Perl": 9, "T": 2, "op": 2, - "default": 16, + "default": 19, "off": 4, "tt": 4, "tt2": 2, @@ -46704,11 +46995,11 @@ "xslt": 2, "ent": 2, "while": 31, - "my": 401, + "my": 404, "type": 69, "exts": 6, "each": 14, - "if": 272, + "if": 276, "ref": 33, "ext": 14, "@": 38, @@ -46716,7 +47007,7 @@ "_": 101, "mk": 2, "mak": 2, - "not": 53, + "not": 54, "t": 18, "p": 9, "STDIN": 2, @@ -46725,36 +47016,36 @@ "/MSWin32/": 2, "quotemeta": 5, "catfile": 4, - "SYNOPSIS": 5, - "If": 14, - "you": 33, - "want": 5, - "to": 86, + "SYNOPSIS": 6, + "If": 15, + "you": 44, + "want": 7, + "to": 95, "know": 4, - "about": 3, + "about": 4, "F": 24, "": 13, - "see": 4, - "file": 40, - "itself.": 2, + "see": 5, + "file": 49, + "itself.": 3, "No": 4, "user": 4, "serviceable": 1, "parts": 1, "inside.": 1, - "is": 62, - "all": 22, - "that": 27, + "is": 69, + "all": 23, + "that": 33, "should": 6, "this.": 1, "FUNCTIONS": 1, - "head2": 32, + "head2": 34, "read_ackrc": 4, "Reads": 1, "contents": 2, - "of": 55, + "of": 64, ".ackrc": 1, - "and": 76, + "and": 85, "returns": 4, "arguments.": 1, "sub": 225, @@ -46772,7 +47063,7 @@ "&&": 83, "e": 20, "open": 7, - "or": 47, + "or": 49, "die": 38, "@lines": 21, "/./": 2, @@ -46787,11 +47078,11 @@ "return": 157, "get_command_line_options": 4, "Gets": 3, - "command": 13, + "command": 14, "line": 20, "arguments": 2, "does": 10, - "specific": 1, + "specific": 2, "tweaking.": 1, "opt": 291, "pager": 19, @@ -46814,9 +47105,9 @@ "column": 4, "#": 99, "ignore": 7, - "this": 18, + "this": 22, "option": 7, - "it": 25, + "it": 28, "handled": 2, "beforehand": 2, "f": 25, @@ -46848,7 +47139,7 @@ "print_version_statement": 2, "exit": 16, "show_help": 3, - "@_": 41, + "@_": 43, "show_help_types": 2, "require": 12, "Pod": 4, @@ -46860,7 +47151,7 @@ "wanted": 4, "no//": 2, "must": 5, - "be": 30, + "be": 36, "later": 2, "exists": 19, "else": 53, @@ -46895,7 +47186,7 @@ "uniq": 4, "@uniq": 2, "sort": 8, - "a": 81, + "a": 85, "<=>": 2, "b": 6, "keys": 15, @@ -46906,24 +47197,24 @@ "Go": 1, "through": 6, "look": 2, - "I": 67, + "I": 68, "<--type-set>": 1, "foo=": 1, "bar": 3, "<--type-add>": 1, "xml=": 1, - ".": 121, + ".": 125, "Remove": 1, "them": 5, - "add": 8, + "add": 9, "supported": 1, "filetypes": 8, "i.e.": 2, "into": 6, - "etc.": 1, + "etc.": 3, "@typedef": 8, "td": 6, - "set": 11, + "set": 12, "Builtin": 4, "cannot": 4, "changed.": 4, @@ -46931,7 +47222,7 @@ "delete_type": 5, "Type": 2, "exist": 4, - "creating": 2, + "creating": 3, "with": 26, "...": 2, "unless": 39, @@ -46943,7 +47234,7 @@ "internal": 1, "structures": 1, "containing": 5, - "information": 1, + "information": 2, "type_wanted.": 1, "Internal": 2, "error": 4, @@ -46952,18 +47243,18 @@ "Standard": 1, "filter": 12, "pass": 1, - "L": 18, + "L": 34, "": 1, "descend_filter.": 1, - "It": 2, + "It": 3, "true": 3, "directory": 8, - "any": 3, + "any": 4, "ones": 1, "we": 7, "ignore.": 1, "path": 28, - "This": 24, + "This": 27, "removes": 1, "trailing": 1, "separator": 4, @@ -46979,18 +47270,18 @@ "For": 5, "example": 5, "": 1, - "The": 20, + "The": 22, "filetype": 1, - "will": 7, - "C": 48, + "will": 9, + "C": 56, "": 1, - "can": 26, + "can": 30, "skipped": 2, - "something": 2, + "something": 3, "avoid": 1, "searching": 6, "even": 4, - "under": 4, + "under": 5, "a.": 1, "constant": 2, "TEXT": 16, @@ -47000,7 +47291,7 @@ "lc_basename": 8, "lc": 5, "r": 14, - "B": 75, + "B": 76, "header": 17, "SHEBANG#!#!": 2, "ruby": 3, @@ -47034,7 +47325,7 @@ "_get_thpppt": 3, "print": 35, "_bar": 3, - "<<": 6, + "<<": 10, "&": 22, "*I": 2, "g": 7, @@ -47044,13 +47335,13 @@ "#I": 6, "#7": 4, "results.": 2, - "on": 24, - "when": 17, - "used": 11, + "on": 25, + "when": 18, + "used": 12, "interactively": 6, - "no": 21, + "no": 22, "Print": 6, - "between": 3, + "between": 4, "results": 8, "different": 2, "files.": 6, @@ -47079,7 +47370,7 @@ "pipe": 4, "finding": 2, "Only": 7, - "found": 9, + "found": 11, "without": 3, "searching.": 2, "PATTERN": 8, @@ -47091,13 +47382,13 @@ "lexically.": 3, "invert": 2, "Print/search": 2, - "handle": 2, - "do": 11, + "handle": 3, + "do": 12, "g/": 2, "G.": 2, "show": 3, "Show": 2, - "which": 6, + "which": 7, "has.": 2, "inclusion/exclusion": 2, "All": 4, @@ -47133,7 +47424,7 @@ "@before": 16, "before_starts_at_line": 10, "after": 18, - "number": 3, + "number": 4, "still": 4, "res": 59, "next_text": 8, @@ -47198,10 +47489,10 @@ "print_count0": 2, "filetypes_supported_set": 9, "True/False": 1, - "are": 24, + "are": 25, "print_files": 4, "iter": 23, - "returned": 2, + "returned": 3, "iterator": 3, "<$regex>": 1, "<$one>": 1, @@ -47209,7 +47500,7 @@ "first.": 1, "<$ors>": 1, "<\"\\n\">": 1, - "defines": 1, + "defines": 2, "what": 14, "filename.": 1, "print_files_with_matches": 4, @@ -47279,24 +47570,24 @@ "pipe.": 1, "exit_from_ack": 5, "Exit": 1, - "application": 10, + "application": 15, "correct": 1, "code.": 2, "otherwise": 2, "handed": 1, - "in": 29, + "in": 36, "argument.": 1, "rc": 11, "LICENSE": 3, "Copyright": 2, "Andy": 2, "Lester.": 2, - "free": 3, + "free": 4, "software": 3, - "redistribute": 3, - "and/or": 3, - "modify": 3, - "terms": 3, + "redistribute": 4, + "and/or": 4, + "modify": 4, + "terms": 4, "Artistic": 2, "License": 2, "v2.0.": 2, @@ -47312,8 +47603,8 @@ "unspecified": 1, "fib": 4, "N": 2, - "SEE": 3, - "ALSO": 3, + "SEE": 4, + "ALSO": 4, "": 1, "SHEBANG#!perl": 5, "MAIN": 1, @@ -47334,7 +47625,7 @@ "Resource": 5, "file_matching": 2, "check_regex": 2, - "like": 12, + "like": 13, "finder": 1, "options": 7, "FILE...": 1, @@ -47353,7 +47644,7 @@ "By": 2, "prints": 2, "also": 7, - "would": 3, + "would": 5, "actually": 1, "let": 1, "take": 5, @@ -47371,12 +47662,12 @@ "specified": 3, "line.": 4, "default.": 2, - "item": 42, + "item": 44, "": 11, "paths": 3, "included": 1, "search.": 1, - "entire": 2, + "entire": 3, "matched": 1, "against": 1, "shell": 4, @@ -47385,7 +47676,7 @@ "<-w>": 2, "<-v>": 3, "<-Q>": 4, - "apply": 2, + "apply": 3, "relative": 1, "convenience": 1, "shortcut": 2, @@ -47431,7 +47722,7 @@ "include": 1, "<--ignore-dir=data>": 1, "<--noignore-dir>": 1, - "allows": 2, + "allows": 4, "normally": 1, "perhaps": 1, "research": 1, @@ -47443,17 +47734,17 @@ "": 1, "NOT": 1, "supported.": 1, - "You": 3, - "need": 3, + "You": 4, + "need": 5, "specify": 1, "<--ignore-dir=foo>": 1, - "then": 3, + "then": 4, "foo": 6, "taken": 1, "account": 1, "explicitly": 1, "": 2, - "file.": 2, + "file.": 3, "Multiple": 1, "<--line>": 1, "comma": 1, @@ -47494,9 +47785,9 @@ "they": 1, "expression.": 1, "Highlighting": 1, - "work": 1, + "work": 3, "though": 1, - "so": 3, + "so": 4, "highlight": 1, "seeing": 1, "tail": 1, @@ -47509,9 +47800,9 @@ "usual": 1, "newline.": 1, "dealing": 1, - "contain": 2, + "contain": 3, "whitespace": 1, - "e.g.": 1, + "e.g.": 2, "html": 1, "xargs": 2, "rm": 1, @@ -47532,7 +47823,7 @@ "<--smart-case>": 1, "<--no-smart-case>": 1, "strings": 1, - "contains": 1, + "contains": 2, "uppercase": 1, "characters.": 1, "similar": 1, @@ -47543,7 +47834,7 @@ "<--sort-files>": 1, "Sorts": 1, "Use": 6, - "your": 13, + "your": 20, "listings": 1, "deterministic": 1, "runs": 1, @@ -47557,7 +47848,7 @@ "Bill": 1, "Cat": 1, "logo.": 1, - "Note": 4, + "Note": 5, "exact": 1, "spelling": 1, "<--thpppppt>": 1, @@ -47566,7 +47857,7 @@ "perl": 8, "php": 2, "python": 1, - "looks": 1, + "looks": 2, "location.": 1, "variable": 1, "specifies": 1, @@ -47610,7 +47901,7 @@ "See": 1, "": 1, "specifications.": 1, - "such": 5, + "such": 6, "": 1, "": 1, "": 1, @@ -47623,7 +47914,7 @@ "understands": 1, "sequences.": 1, "never": 1, - "back": 3, + "back": 4, "ACK": 2, "OTHER": 1, "TOOLS": 1, @@ -47646,8 +47937,8 @@ "Phil": 1, "Jackson": 1, "put": 1, - "together": 1, - "an": 11, + "together": 2, + "an": 16, "": 1, "extension": 1, "": 1, @@ -47660,13 +47951,13 @@ "Code": 1, "greater": 1, "normal": 1, - "code": 7, + "code": 8, "<$?=256>": 1, "": 1, "backticks.": 1, "errors": 1, "used.": 1, - "at": 3, + "at": 4, "least": 1, "returned.": 1, "DEBUGGING": 1, @@ -47688,7 +47979,7 @@ "big": 1, "codesets": 1, "more": 2, - "create": 2, + "create": 3, "tree": 2, "ideal": 1, "sending": 1, @@ -47735,7 +48026,7 @@ "tips": 1, "here.": 1, "FAQ": 1, - "Why": 2, + "Why": 3, "isn": 1, "doesn": 8, "behavior": 3, @@ -47757,17 +48048,17 @@ "those": 2, "well": 2, "returning": 1, - "things": 1, + "things": 2, "great": 1, "did": 1, "replace": 3, "read": 6, "only.": 1, - "has": 2, + "has": 3, "perfectly": 1, "good": 2, "way": 2, - "using": 2, + "using": 5, "<-p>": 1, "<-n>": 1, "switches.": 1, @@ -47782,7 +48073,7 @@ "<.xyz>": 1, "already": 2, "program/package": 1, - "called": 3, + "called": 4, "ack.": 2, "Yes": 1, "know.": 1, @@ -47837,7 +48128,7 @@ "hash": 11, "badkey": 1, "caller": 2, - "start": 6, + "start": 7, "dh": 4, "opendir": 1, "@newfiles": 5, @@ -47847,7 +48138,7 @@ "catdir": 3, "closedir": 1, "": 1, - "these": 1, + "these": 4, "updated": 1, "update": 1, "message": 1, @@ -47882,7 +48173,7 @@ "seek": 4, "readline": 1, "nexted": 3, - "CGI": 5, + "CGI": 6, "Fast": 3, "XML": 2, "Hash": 11, @@ -47931,6 +48222,113 @@ "Foo": 11, "Bar": 1, "@array": 1, + "pod": 1, + "Catalyst": 10, + "PSGI": 10, + "How": 1, + "": 3, + "specification": 3, + "interface": 1, + "web": 8, + "servers": 2, + "based": 2, + "applications": 2, + "frameworks.": 1, + "supports": 1, + "writing": 1, + "portable": 1, + "run": 1, + "various": 2, + "methods": 4, + "standalone": 1, + "server": 2, + "mod_perl": 3, + "FastCGI": 2, + "": 3, + "implementation": 1, + "running": 1, + "applications.": 1, + "Engine": 1, + "XXXX": 1, + "classes": 2, + "environments": 1, + "been": 1, + "changed": 1, + "done": 2, + "implementing": 1, + "possible": 2, + "manually": 2, + "": 1, + "root": 1, + "application.": 1, + "write": 2, + "own": 4, + ".psgi": 7, + "Writing": 2, + "alternate": 1, + "": 1, + "extensions": 1, + "implement": 2, + "": 1, + "": 1, + "": 1, + "simplest": 1, + "<.psgi>": 1, + "": 1, + "TestApp": 5, + "app": 2, + "psgi_app": 3, + "middleware": 2, + "components": 2, + "automatically": 2, + "": 1, + "applied": 1, + "psgi": 2, + "yourself.": 2, + "Details": 1, + "below.": 1, + "Additional": 1, + "": 1, + "What": 1, + "generates": 2, + "": 1, + "setting": 2, + "wrapped": 1, + "": 1, + "some": 1, + "engine": 1, + "fixes": 1, + "uniform": 1, + "behaviour": 2, + "contained": 1, + "over": 2, + "": 1, + "": 1, + "override": 1, + "providing": 2, + "none": 1, + "call": 2, + "MyApp": 1, + "Thus": 1, + "functionality": 1, + "ll": 1, + "An": 1, + "apply_default_middlewares": 2, + "method": 8, + "supplied": 1, + "wrap": 1, + "middlewares": 1, + "means": 3, + "auto": 1, + "generated": 1, + "": 1, + "": 1, + "AUTHORS": 2, + "Contributors": 1, + "Catalyst.pm": 1, + "library": 2, + "software.": 1, + "same": 2, "Plack": 25, "_001": 1, "HTTP": 16, @@ -47943,7 +48341,6 @@ "Escape": 6, "_deprecated": 8, "alt": 1, - "method": 7, "carp": 2, "croak": 3, "required": 2, @@ -48032,7 +48429,6 @@ "_make_upload": 2, "__END__": 2, "Portable": 2, - "PSGI": 6, "app_or_middleware": 1, "req": 28, "finalize": 5, @@ -48042,19 +48438,14 @@ "API": 2, "objects": 2, "across": 1, - "web": 5, - "server": 1, "environments.": 1, "CAVEAT": 1, "module": 2, "intended": 1, - "middleware": 1, "developers": 3, "framework": 2, "rather": 2, - "Writing": 1, "directly": 1, - "possible": 1, "recommended": 1, "yet": 1, "too": 1, @@ -48072,7 +48463,6 @@ "PSGI.": 1, "METHODS": 2, "Some": 1, - "methods": 3, "earlier": 1, "versions": 1, "deprecated": 1, @@ -48110,7 +48500,6 @@ "Unlike": 1, "": 1, "allow": 1, - "setting": 1, "modifying": 1, "@values": 1, "@params": 1, @@ -48135,7 +48524,6 @@ "": 1, "": 1, "store": 1, - "means": 2, "plain": 2, "": 1, "scalars": 1, @@ -48149,7 +48537,6 @@ "dispatch": 1, "route": 1, "actions": 1, - "based": 1, "sure": 1, "": 1, "virtual": 1, @@ -48157,7 +48544,6 @@ "how": 1, "mounted.": 1, "hosted": 1, - "mod_perl": 1, "scripts": 1, "multiplexed": 1, "tools": 1, @@ -48174,7 +48560,6 @@ "": 1, "empty.": 1, "older": 1, - "call": 1, "instead.": 1, "Cookie": 2, "handling": 1, @@ -48192,10 +48577,8 @@ "Simple": 1, "longer": 1, "have": 2, - "write": 1, "wacky": 1, "simply": 1, - "AUTHORS": 1, "Tatsuhiko": 2, "Miyagawa": 2, "Kazuhiro": 1, @@ -48204,8 +48587,6 @@ "Matsuno": 2, "": 1, "": 1, - "library": 1, - "same": 1, "Util": 3, "Accessor": 1, "status": 17, @@ -48271,7 +48652,6 @@ "response": 5, "psgi_handler": 1, "API.": 1, - "over": 1, "Sets": 2, "gets": 2, "": 1, @@ -51202,36 +51582,73 @@ "socket.EAI_NONAME": 1 }, "R": { + "df.residual.mira": 1, + "<": 24, + "-": 27, + "function": 7, + "(": 60, + "object": 9, + "...": 4, + ")": 60, + "{": 7, + "fit": 2, + "analyses": 1, + "[": 10, + "]": 10, + "return": 7, + "df.residual": 2, + "}": 7, + "df.residual.lme": 1, + "fixDF": 1, + "df.residual.mer": 1, + "sum": 1, + "object@dims": 1, + "*": 2, + "c": 5, + "+": 3, + "df.residual.default": 1, + "q": 2, + "df": 3, + "if": 3, + "is.null": 1, + "mk": 2, + "try": 2, + "coef": 1, + "silent": 2, + "TRUE": 5, + "mn": 2, + "f": 5, + "fitted": 1, + "inherits": 2, + "|": 3, + "NULL": 2, + "n": 3, + "ifelse": 1, + "is.data.frame": 1, + "is.matrix": 1, + "nrow": 1, + "length": 2, + "k": 3, + "max": 1, "SHEBANG#!Rscript": 1, "ParseDates": 2, - "<": 12, - "-": 12, - "function": 3, - "(": 29, "lines": 4, - ")": 29, - "{": 3, "dates": 3, "matrix": 2, "unlist": 2, "strsplit": 2, "ncol": 2, "byrow": 2, - "TRUE": 3, "days": 2, - "[": 4, - "]": 4, "times": 2, "hours": 2, "all.days": 2, - "c": 2, "all.hours": 2, "data.frame": 1, "Day": 2, "factor": 2, "levels": 2, "Hour": 2, - "}": 3, "Main": 2, "system": 1, "intern": 1, @@ -51243,7 +51660,6 @@ "aes": 2, "y": 1, "x": 1, - "+": 2, "geom_point": 1, "size": 1, "Freq": 1, @@ -59856,12 +60272,12 @@ }, "XML": { "": 4, - "version=": 6, + "version=": 10, "": 1, - "name=": 223, + "name=": 227, "xmlns": 2, "ea=": 2, - "": 2, + "": 3, "This": 21, "easyant": 3, "module.ant": 1, @@ -59879,7 +60295,7 @@ "own": 2, "specific": 8, "target.": 1, - "": 2, + "": 3, "": 2, "": 2, "my": 2, @@ -59908,7 +60324,7 @@ "this": 77, "a": 128, "module.ivy": 1, - "for": 59, + "for": 60, "java": 1, "standard": 1, "application": 2, @@ -59924,14 +60340,14 @@ "description=": 2, "": 1, "": 1, - "": 1, + "": 4, "org=": 1, "rev=": 1, "conf=": 1, "default": 9, "junit": 2, "test": 7, - "-": 49, + "-": 50, "/": 6, "": 1, "": 1, @@ -59957,9 +60373,9 @@ "used": 19, "both": 2, "Changing": 5, - "(": 52, + "(": 53, "i.e.": 23, - ")": 45, + ")": 46, "Changed": 4, "Observables.": 2, "In": 6, @@ -59975,7 +60391,7 @@ "changes.": 2, "": 121, "": 120, - "The": 74, + "The": 75, "object": 42, "has": 16, "raised": 1, @@ -60155,7 +60571,7 @@ "string": 13, "distinguish": 12, "arbitrarily": 2, - "by": 13, + "by": 14, "client.": 2, "Listen": 4, "provides": 6, @@ -60213,7 +60629,7 @@ "allows": 15, "log": 2, "attached.": 1, - "data": 1, + "data": 2, "structure": 1, "representation": 1, "memoizing": 2, @@ -60680,7 +61096,35 @@ "English": 1, "Ingl": 1, "": 1, - "": 1 + "": 1, + "": 1, + "compatVersion=": 1, + "": 1, + "FreeMedForms": 1, + "": 1, + "": 1, + "C": 1, + "Eric": 1, + "MAEKER": 1, + "MD": 1, + "": 1, + "": 1, + "GPLv3": 1, + "": 1, + "": 1, + "Patient": 1, + "": 1, + "XML": 1, + "form": 1, + "loader/saver": 1, + "FreeMedForms.": 1, + "": 1, + "http": 1, + "//www.freemedforms.com/": 1, + "": 1, + "": 1, + "": 1, + "": 1 }, "XProc": { "": 1, @@ -61212,7 +61656,7 @@ "Clojure": 510, "COBOL": 90, "CoffeeScript": 2951, - "Common Lisp": 103, + "Common Lisp": 2186, "Coq": 18259, "Creole": 134, "Crystal": 1506, @@ -61301,7 +61745,7 @@ "Parrot Internal Representation": 5, "Pascal": 30, "PAWN": 3263, - "Perl": 17497, + "Perl": 17979, "Perl6": 372, "PHP": 20724, "Pod": 658, @@ -61313,7 +61757,7 @@ "Protocol Buffer": 63, "PureScript": 1652, "Python": 5715, - "R": 195, + "R": 392, "Racket": 331, "Ragel in Ruby Host": 593, "RDoc": 279, @@ -61354,7 +61798,7 @@ "Volt": 388, "wisp": 1363, "XC": 24, - "XML": 5737, + "XML": 5785, "XProc": 22, "XQuery": 801, "XSLT": 44, @@ -61386,7 +61830,7 @@ "Clojure": 7, "COBOL": 4, "CoffeeScript": 9, - "Common Lisp": 1, + "Common Lisp": 3, "Coq": 12, "Creole": 1, "Crystal": 3, @@ -61475,7 +61919,7 @@ "Parrot Internal Representation": 1, "Pascal": 1, "PAWN": 1, - "Perl": 14, + "Perl": 15, "Perl6": 3, "PHP": 9, "Pod": 1, @@ -61487,7 +61931,7 @@ "Protocol Buffer": 1, "PureScript": 4, "Python": 7, - "R": 3, + "R": 4, "Racket": 2, "Ragel in Ruby Host": 3, "RDoc": 1, @@ -61528,7 +61972,7 @@ "Volt": 1, "wisp": 1, "XC": 1, - "XML": 4, + "XML": 5, "XProc": 1, "XQuery": 1, "XSLT": 1, @@ -61536,5 +61980,5 @@ "YAML": 2, "Zephir": 2 }, - "md5": "5cbb8fcefc5e9c773796d772fe48907d" + "md5": "b9aa45f19260304867415084d0c02a0e" } \ No newline at end of file diff --git a/samples/Common Lisp/macros-advanced.cl b/samples/Common Lisp/macros-advanced.cl new file mode 100644 index 00000000..b746d769 --- /dev/null +++ b/samples/Common Lisp/macros-advanced.cl @@ -0,0 +1,82 @@ +;; @file macros-advanced.cl +;; +;; @breif Advanced macro practices - defining your own macros +;; +;; Macro definition skeleton: +;; (defmacro name (parameter*) +;; "Optional documentation string" +;; body-form*) +;; +;; Note that backquote expression is most often used in the `body-form` +;; + +; `primep` test a number for prime +(defun primep (n) + "test a number for prime" + (if (< n 2) (return-from primep)) + (do ((i 2 (1+ i)) (p t (not (zerop (mod n i))))) + ((> i (sqrt n)) p) + (when (not p) (return)))) +; `next-prime` return the next prime bigger than the specified number +(defun next-prime (n) + "return the next prime bigger than the speicified number" + (do ((i (1+ n) (1+ i))) + ((primep i) i))) +; +; The recommended procedures to writting a new macro are as follows: +; 1. Write a sample call to the macro and the code it should expand into +(do-primes (p 0 19) + (format t "~d " p)) +; Expected expanded codes +(do ((p (next-prime (- 0 1)) (next-prime p))) + ((> p 19)) + (format t "~d " p)) +; 2. Write code that generate the hardwritten expansion from the arguments in +; the sample call +(defmacro do-primes (var-and-range &rest body) + (let ((var (first var-and-range)) + (start (second var-and-range)) + (end (third var-and-range))) + `(do ((,var (next-prime (- ,start 1)) (next-prime ,var))) + ((> ,var ,end)) + ,@body))) +; 2-1. More concise implementations with the 'parameter list destructuring' and +; '&body' synonym, it also emits more friendly messages on incorrent input. +(defmacro do-primes ((var start end) &body body) + `(do ((,var (next-prime (- ,start 1)) (next-prime ,var))) + ((> ,var ,end)) + ,@body)) +; 2-2. Test the result of macro expansion with the `macroexpand-1` function +(macroexpand-1 '(do-primes (p 0 19) (format t "~d " p))) +; 3. Make sure the macro abstraction does not "leak" +(defmacro do-primes ((var start end) &body body) + (let ((end-value-name (gensym))) + `(do ((,var (next-prime (- ,start 1)) (next-prime ,var)) + (,end-value-name ,end)) + ((> ,var ,end-value-name)) + ,@body))) +; 3-1. Rules to observe to avoid common and possible leaks +; a. include any subforms in the expansion in positions that will be evaluated +; in the same order as the subforms appear in the macro call +; b. make sure subforms are evaluated only once by creating a variable in the +; expansion to hold the value of evaluating the argument form, and then +; using that variable anywhere else the value is needed in the expansion +; c. use `gensym` at macro expansion time to create variable names used in the +; expansion +; +; Appendix I. Macro-writting macros, 'with-gensyms', to guranttee that rule c +; gets observed. +; Example usage of `with-gensyms` +(defmacro do-primes-a ((var start end) &body body) + "do-primes implementation with macro-writting macro 'with-gensyms'" + (with-gensyms (end-value-name) + `(do ((,var (next-prime (- ,start 1)) (next-prime ,var)) + (,end-value-name ,end)) + ((> ,var ,end-value-name)) + ,@body))) +; Define the macro, note how comma is used to interpolate the value of the loop +; expression +(defmacro with-gensyms ((&rest names) &body body) + `(let ,(loop for n in names collect `(,n (gensym))) + ,@body) +) \ No newline at end of file diff --git a/samples/Common Lisp/motor-inferencia.cl b/samples/Common Lisp/motor-inferencia.cl new file mode 100644 index 00000000..6a2a97ea --- /dev/null +++ b/samples/Common Lisp/motor-inferencia.cl @@ -0,0 +1,475 @@ +#| +ESCUELA POLITECNICA SUPERIOR - UNIVERSIDAD AUTONOMA DE MADRID +INTELIGENCIA ARTIFICIAL + +Motor de inferencia +Basado en parte en "Paradigms of AI Programming: Case Studies +in Common Lisp", de Peter Norvig, 1992 +|# + + +;;;;;;;;;;;;;;;;;;;;; +;;;; Global variables +;;;;;;;;;;;;;;;;;;;;; + + +(defvar *hypothesis-list*) +(defvar *rule-list*) +(defvar *fact-list*) + +;;;;;;;;;;;;;;;;;;;;; +;;;; Constants +;;;;;;;;;;;;;;;;;;;;; + +(defconstant +fail+ nil "Indicates unification failure") + +(defconstant +no-bindings+ '((nil)) + "Indicates unification success, with no variables.") + +(defconstant *mundo-abierto* nil) + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; Functions for the user +;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +;; Resets *fact-list* to NIL +(defun erase-facts () (setq *fact-list* nil)) + +(defun set-hypothesis-list (h) (setq *hypothesis-list* h)) + + +;; Returns a list of solutions, each one satisfying all the hypothesis contained +;; in *hypothesis-list* +(defun motor-inferencia () + (consulta *hypothesis-list*)) + + + +;;;;;;;;;;;;;;;;;;;;;;;; +;;;; Auxiliary functions +;;;;;;;;;;;;;;;;;;;;;;;; + +#|____________________________________________________________________________ +FUNCTION: CONSULTA + +COMMENTS: +CONSULTA receives a list of hypothesis (variable ), and returns +a list of binding lists (each binding list being a solution). + +EXAMPLES: +hypotheses is: +((brothers ?x ?y) (neighbours juan ?x)). + +That is, we are searching the brothers of the possible neighbors of Juan. + +The function can return in this case: + +(((?x . sergio) (?y . javier)) ((?x . julian) (?y . mario)) ((?x . julian) (?y . pedro))). +That is, the neighbors of Juan (Sergio and Julian) have 3 brothers in total(Javier, Mario, Pedro) +____________________________________________________________________________|# + +(defun consulta (hypotheses) + (if (null hypotheses) (list +no-bindings+) + (mapcan #'(lambda (b) + (mapcar #'(lambda (x) (une-bindings-con-bindings b x)) + (consulta (subst-bindings b (rest hypotheses))))) + (find-hypothesis-value (first hypotheses))))) + + + +#|____________________________________________________________________________ +FUNCTION: FIND-HYPOTHESIS-VALUE + +COMMENTS: +This function manages the query a single query (only one hypothesis) given a binding list. +It tries (in the following order) to: +- Answer the query from *fact-list* +- Answer the query from the rules in *rule-list* +- Ask the user + +The function returns a list of solutions (list of binding lists). + +EXAMPLES: +If hypothesis is (brothers ?x ?y) +and the function returns: +(((?x . sergio) (?y . javier)) ((?x . julian) (?y . maria)) ((?x . alberto) (?y . pedro))). + +Means that Sergio and Javier and brothers, Julian and Mario are brothers, and Alberto and Pedro are brothers. +____________________________________________________________________________|# + +(defun find-hypothesis-value (hypothesis) + (let (rules) + (cond + ((equality? hypothesis) + (value-from-equality hypothesis)) + ((value-from-facts hypothesis)) + ((setq good-rules (find-rules hypothesis)) + (value-from-rules hypothesis good-rules)) + (t (ask-user hypothesis))))) + + + +; une-bindings-con-bindings takes two binding lists and returns a binding list +; Assumes that b1 and b2 are not +fail+ +(defun une-bindings-con-bindings (b1 b2) + (cond + ((equal b1 +no-bindings+) b2) + ((equal b2 +no-bindings+) b1) + (T (append b1 b2)))) + + + +#|____________________________________________________________________________ +FUNCTION: VALUE-FROM-FACTS + +COMMENTS: +Returns all the solutions of obtained directly from *fact-list* + +EXAMPLES: +> (setf *fact-list* '((man luis) (man pedro)(woman mart)(man daniel)(woman laura))) + +> (value-from-facts '(man ?x)) +returns: + +(((?X . LUIS)) ((?X . PEDRO)) ((?X . DANIEL))) +____________________________________________________________________________|# + +(defun value-from-facts (hypothesis) + (mapcan #'(lambda(x) (let ((aux (unify hypothesis x))) + (when aux (list aux)))) *fact-list*)) + + + + +#|____________________________________________________________________________ +FUNCTION: FIND-RULES + +COMMENTS: +Returns the rules in *rule-list* whose THENs unify with the term given in +The variables in the rules that satisfy this requirement are renamed. + +EXAMPLES: +> (setq *rule-list* + '((R1 (pertenece ?E (?E . ?_))) + (R2 (pertenece ?E (?_ . ?Xs)) :- ((pertenece ?E ?Xs))))) + +Then: +> (FIND-RULES (PERTENECE 1 (2 5))) +returns: +((R2 (PERTENECE ?E.1 (?_ . ?XS.2)) :- ((PERTENECE ?E.1 ?XS.2)))) +That is, only the THEN of rule R2 unify with + +However, +> (FIND-RULES (PERTENECE 1 (1 6 7))) + +returns: +((R1 (PERTENECE ?E.6 (?E.6 . ?_))) + (R2 (PERTENECE ?E.7 (?_ . ?XS.8)) :- ((PERTENECE ?E.7 ?XS.8)))) +So the THEN of both rules unify with +____________________________________________________________________________|# + +(defun find-rules (hypothesis) + (mapcan #'(lambda(b) (let ((renamed-rule (rename-variables b))) + (when (in-then? hypothesis renamed-rule) + (list renamed-rule)))) *rule-list*)) + +(defun in-then? (hypothesis rule) + (unless (null (rule-then rule)) + (not (equal +fail+ (unify hypothesis (rule-then rule)))))) + + + +#|____________________________________________________________________________ +FUNCTION: VALUE-FROM-RULES + +COMMENTS: +Returns all the solutions to found using all the rules given in +the list . Note that a single rule can have multiple solutions. +____________________________________________________________________________|# +(defun value-from-rules (hypothesis rules) + (mapcan #'(lambda (r) (eval-rule hypothesis r)) rules)) + +(defun limpia-vinculos (termino bindings) + (unify termino (subst-bindings bindings termino))) + + +#|____________________________________________________________________________ +FUNCTION: EVAL-RULE + +COMMENTS: +Returns all the solutions found using the rule given as input argument. + +EXAMPLES: +> (setq *rule-list* + '((R1 (pertenece ?E (?E . ?_))) + (R2 (pertenece ?E (?_ . ?Xs)) :- ((pertenece ?E ?Xs))))) +Then: +> (EVAL-RULE + (PERTENECE 1 (1 6 7)) + (R1 (PERTENECE ?E.42 (?E.42 . ?_)))) +returns: +(((NIL))) +That is, the query (PERTENECE 1 (1 6 7)) can be proven from the given rule, and +no binding in the variables in the query is necessary (in fact, the query has no variables). +On the other hand: +> (EVAL-RULE + (PERTENECE 1 (7)) + (R2 (PERTENECE ?E.49 (?_ . ?XS.50)) :- ((PERTENECE ?E.49 ?XS.50)))) +returns: +NIL +That is, the query can not be proven from the rule R2. +____________________________________________________________________________|# + +(defun eval-rule (hypothesis rule) + (let ((bindings-then + (unify (rule-then rule) hypothesis))) + (unless (equal +fail+ bindings-then) + (if (rule-ifs rule) + (mapcar #'(lambda(b) (limpia-vinculos hypothesis (append bindings-then b))) + (consulta (subst-bindings bindings-then (rule-ifs rule)))) + (list (limpia-vinculos hypothesis bindings-then)))))) + + +(defun ask-user (hypothesis) + (let ((question hypothesis)) + (cond + ((variables-in question) +fail+) + ((not-in-fact-list? question) +fail+) + (*mundo-abierto* + (format t "~%Es cierto el hecho ~S? (T/nil)" question) + (cond + ((read) (add-fact question) +no-bindings+) + (T (add-fact (list 'NOT question)) +fail+))) + (T +fail+)))) + + +; value-from-equality: +(defun value-from-equality (hypothesis) + (let ((new-bindings (unify (second hypothesis) (third hypothesis)))) + (if (not (equal +fail+ new-bindings)) + (list new-bindings)))) + + + +#|____________________________________________________________________________ +FUNCTION: UNIFY + +COMMENTS: +Finds the most general unifier of two input expressions, taking into account the +bindings specified in the input +In case the two expressions can unify, the function returns the total bindings necessary +for that unification. Otherwise, returns +fail+ + +EXAMPLES: +> (unify '1 '1) +((NIL)) ;; which is the constant +no-bindings+ +> (unify 1 '2) +nil ;; which is the constant +fail+ +> (unify '?x 1) +((?x . 1)) +> (unify '(1 1) ?x) +((? x 1 1)) +> (unify '?_ '?x) +((NIL)) +> (unify '(p ?x 1 2) '(p ?y ?_ ?_)) +((?x . ?y)) +> (unify '(?a . ?_) '(1 2 3)) +((?a . 1)) +> (unify '(?_ ?_) '(1 2)) +((nil)) +> (unify '(?a . ?b) '(1 2 3)) +((?b 2 3) (?a . 1)) +> (unify '(?a . ?b) '(?v . ?d)) +((?b . ?d) (?a . ?v)) +> (unify '(?eval (+ 1 1)) '1) +nil +> (unify '(?eval (+ 1 1)) '2) +(nil)) +____________________________________________________________________________|# + +(defun unify (x y &optional (bindings +no-bindings+)) + "See if x and y match with given bindings. If they do, + return a binding list that would make them equal [p 303]." + (cond ((eq bindings +fail+) +fail+) + ((eql x y) bindings) + ((eval? x) (unify-eval x y bindings)) + ((eval? y) (unify-eval y x bindings)) + ((variable? x) (unify-var x y bindings)) + ((variable? y) (unify-var y x bindings)) + ((and (consp x) (consp y)) + (unify (rest x) (rest y) + (unify (first x) (first y) bindings))) + (t +fail+))) + + +;; rename-variables: renombra ?X por ?X.1, ?Y por ?Y.2 etc. salvo ?_ que no se renombra +(defun rename-variables (x) + "Replace all variables in x with new ones. Excepto ?_" + (sublis (mapcar #'(lambda (var) + (if (anonymous-var? var) + (make-binding var var) + (make-binding var (new-variable var)))) + (variables-in x)) + x)) + + + +;;;; Auxiliary Functions + +(defun unify-var (var x bindings) + "Unify var with x, using (and maybe extending) bindings [p 303]." + (cond ((or (anonymous-var? var)(anonymous-var? x)) bindings) + ((get-binding var bindings) + (unify (lookup var bindings) x bindings)) + ((and (variable? x) (get-binding x bindings)) + (unify var (lookup x bindings) bindings)) + ((occurs-in? var x bindings) + +fail+) + (t (extend-bindings var x bindings)))) + +(defun variable? (x) + "Is x a variable (a symbol starting with ?)?" + (and (symbolp x) (eql (char (symbol-name x) 0) #\?))) + +(defun get-binding (var bindings) + "Find a (variable . value) pair in a binding list." + (assoc var bindings)) + +(defun binding-var (binding) + "Get the variable part of a single binding." + (car binding)) + +(defun binding-val (binding) + "Get the value part of a single binding." + (cdr binding)) + +(defun make-binding (var val) (cons var val)) + +(defun lookup (var bindings) + "Get the value part (for var) from a binding list." + (binding-val (get-binding var bindings))) + +(defun extend-bindings (var val bindings) + "Add a (var . value) pair to a binding list." + (append + (unless (eq bindings +no-bindings+) bindings) + (list (make-binding var val)))) + +(defun occurs-in? (var x bindings) + "Does var occur anywhere inside x?" + (cond ((eq var x) t) + ((and (variable? x) (get-binding x bindings)) + (occurs-in? var (lookup x bindings) bindings)) + ((consp x) (or (occurs-in? var (first x) bindings) + (occurs-in? var (rest x) bindings))) + (t nil))) + +(defun subst-bindings (bindings x) + "Substitute the value of variables in bindings into x, + taking recursively bound variables into account." + (cond ((eq bindings +fail+) +fail+) + ((eq bindings +no-bindings+) x) + ((and (listp x) (eq '?eval (car x))) + (subst-bindings-quote bindings x)) + ((and (variable? x) (get-binding x bindings)) + (subst-bindings bindings (lookup x bindings))) + ((atom x) x) + (t (cons (subst-bindings bindings (car x)) ;; s/reuse-cons/cons + (subst-bindings bindings (cdr x)))))) + +(defun unifier (x y) + "Return something that unifies with both x and y (or fail)." + (subst-bindings (unify x y) x)) + +(defun variables-in (exp) + "Return a list of all the variables in EXP." + (unique-find-anywhere-if #'variable? exp)) + +(defun unique-find-anywhere-if (predicate tree &optional found-so-far) + "Return a list of leaves of tree satisfying predicate, + with duplicates removed." + (if (atom tree) + (if (funcall predicate tree) + (pushnew tree found-so-far) + found-so-far) + (unique-find-anywhere-if + predicate + (first tree) + (unique-find-anywhere-if predicate (rest tree) + found-so-far)))) + +(defun find-anywhere-if (predicate tree) + "Does predicate apply to any atom in the tree?" + (if (atom tree) + (funcall predicate tree) + (or (find-anywhere-if predicate (first tree)) + (find-anywhere-if predicate (rest tree))))) + +(defun new-variable (var) + "Create a new variable. Assumes user never types variables of form ?X.9" + (gentemp (format nil "~S." var))) +; (gentemp "?") ) +;;; + +(defun anonymous-var? (x) + (eq x '?_)) + +(defun subst-bindings-quote (bindings x) + "Substitute the value of variables in bindings into x, + taking recursively bound variables into account." + (cond ((eq bindings +fail+) +fail+) + ((eq bindings +no-bindings+) x) + ((and (variable? x) (get-binding x bindings)) + (if (variable? (lookup x bindings)) + (subst-bindings-quote bindings (lookup x bindings)) + (subst-bindings-quote bindings (list 'quote (lookup x bindings))) + ) + ) + ((atom x) x) + (t (cons (subst-bindings-quote bindings (car x)) ;; s/reuse-cons/cons + (subst-bindings-quote bindings (cdr x)))))) + +(defun eval? (x) + (and (consp x) (eq (first x) '?eval))) + +(defun unify-eval (x y bindings) + (let ((exp (subst-bindings-quote bindings (second x)))) + (if (variables-in exp) + +fail+ + (unify (eval exp) y bindings)))) + + + +(defun rule-ifs (rule) (fourth rule)) +(defun rule-then (rule) (second rule)) + + +(defun equality? (term) + (and (consp term) (eql (first term) '?=))) + + +(defun in-fact-list? (expresion) + (some #'(lambda(x) (equal x expresion)) *fact-list*)) + +(defun not-in-fact-list? (expresion) + (if (eq (car expresion) 'NOT) + (in-fact-list? (second expresion)) + (in-fact-list? (list 'NOT expresion)))) + + +;; add-fact: + +(defun add-fact (fact) + (setq *fact-list* (cons fact *fact-list*))) + + +(defun variable? (x) + "Is x a variable (a symbol starting with ?) except ?eval and ?=" + (and (not (equal x '?eval)) (not (equal x '?=)) + (symbolp x) (eql (char (symbol-name x) 0) #\?))) + + +;; EOF \ No newline at end of file diff --git a/samples/Perl/PSGI.pod b/samples/Perl/PSGI.pod new file mode 100644 index 00000000..a05e0023 --- /dev/null +++ b/samples/Perl/PSGI.pod @@ -0,0 +1,111 @@ +=pod + +=head1 NAME + +Catalyst::PSGI - How Catalyst and PSGI work together + +=head1 SYNOPSIS + +The L specification defines an interface between web servers and +Perl-based web applications and frameworks. It supports the writing of +portable applications that can be run using various methods (as a +standalone server, or using mod_perl, FastCGI, etc.). L is an +implementation of the PSGI specification for running Perl applications. + +Catalyst used to contain an entire set of C<< Catalyst::Engine::XXXX >> +classes to handle various web servers and environments (e.g. CGI, +FastCGI, mod_perl) etc. + +This has been changed in Catalyst 5.9 so that all of that work is done +by Catalyst implementing the L specification, using L's +adaptors to implement that functionality. + +This means that we can share common code, and share fixes for specific +web servers. + +=head1 I already have an application + +If you already have a Catalyst application, then you should be able to +upgrade to the latest release with little or no trouble (see the notes +in L for specifics about your web server +deployment). + +=head1 Writing your own PSGI file. + +=head2 What is a .psgi file? + +A C<< .psgi >> file lets you control how your application code reference +is built. Catalyst will automatically handle this for you, but it's +possible to do it manually by creating a C file in the root +of your application. + +=head2 Why would I want to write my own .psgi file? + +Writing your own .psgi file allows you to use the alternate L command +to start your application, and allows you to add classes and extensions +that implement L, such as L +or L. + +The simplest C<.psgi> file for an application called C would be: + + use strict; + use warnings; + use TestApp; + + my $app = TestApp->psgi_app(@_); + +Note that Catalyst will apply a number of middleware components for you +automatically, and these B be applied if you manually create a +psgi file yourself. Details of these components can be found below. + +Additional information about psgi files can be found at: +L + +=head2 What is in the .psgi file Catalyst generates by default? + +Catalyst generates an application which, if the C +setting is on, is wrapped in L, and +contains some engine-specific fixes for uniform behaviour, as contained +in: + +=over + +=item L + +=item L + +=back + +If you override the default by providing your own C<< .psgi >> file, +then none of these things will be done automatically for you by the PSGI +application returned when you call C<< MyApp->psgi_app >>. Thus, if you +need any of this functionality, you'll need to implement this in your +C<< .psgi >> file yourself. + +An apply_default_middlewares method is supplied to wrap your application +in the default middlewares if you want this behaviour and you are providing +your own .psgi file. + +This means that the auto-generated (no .psgi file) code looks something +like this: + + use strict; + use warnings; + use TestApp; + + my $app = TestApp->apply_default_middlewares(TestApp->psgi_app(@_)); + +=head1 SEE ALSO + +L, L, L, L. + +=head1 AUTHORS + +Catalyst Contributors, see Catalyst.pm + +=head1 COPYRIGHT + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/samples/R/df.residual.r b/samples/R/df.residual.r new file mode 100644 index 00000000..a7a00686 --- /dev/null +++ b/samples/R/df.residual.r @@ -0,0 +1,29 @@ + +df.residual.mira <- function(object, ...) { + fit <- object$analyses[[1]] + return(df.residual(fit)) +} + +df.residual.lme <- function(object, ...) { + return(object$fixDF[["X"]][1]) +} + +df.residual.mer <- function(object, ...) { + return(sum(object@dims[2:4] * c(1, -1, -1)) + 1) +} + +df.residual.default <- function(object, q = 1.3, ...) { + df <- object$df.residual + if (!is.null(df)) + return(df) + + mk <- try(c <- coef(object), silent = TRUE) + mn <- try(f <- fitted(object), silent = TRUE) + if (inherits(mk, "try-error") | inherits(mn, "try-error")) + return(NULL) + n <- ifelse(is.data.frame(f) | is.matrix(f), nrow(f), length(f)) + k <- length(c) + if (k == 0 | n == 0) + return(NULL) + return(max(1, n - q * k)) +} diff --git a/samples/XML/XmlIO.pluginspec b/samples/XML/XmlIO.pluginspec new file mode 100644 index 00000000..8e02e760 --- /dev/null +++ b/samples/XML/XmlIO.pluginspec @@ -0,0 +1,13 @@ + + FreeMedForms + (C) 2008-2012 by Eric MAEKER, MD + GPLv3 + Patient data + The XML form loader/saver for FreeMedForms. + http://www.freemedforms.com/ + + + + + + diff --git a/test/test_samples.rb b/test/test_samples.rb index 5073f7b8..e0130282 100644 --- a/test/test_samples.rb +++ b/test/test_samples.rb @@ -1,7 +1,7 @@ require 'linguist/samples' +require 'linguist/language' require 'tempfile' require 'yajl' - require 'test/unit' class TestSamples < Test::Unit::TestCase @@ -35,4 +35,22 @@ class TestSamples < Test::Unit::TestCase assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c } assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } } end + + # If a language extension isn't globally unique then make sure there are samples + def test_presence + Linguist::Language.all.each do |language| + language.all_extensions.each do |extension| + language_matches = Language.find_by_filename("foo#{extension}") + + # If there is more than one language match for a given extension + # then check that there are examples for that language with the extension + if language_matches.length > 1 + language_matches.each do |language| + assert File.directory?("samples/#{language.name}"), "#{language.name} is missing a samples directory" + assert Dir.glob("samples/#{language.name}/*#{extension}").any?, "#{language.name} is missing samples for extension #{extension}" + end + end + end + end + end end