・正解
一部で盛り上がった? 等差数列の合計を求める的なアレですが、
わたしがきになったのは「これが正解」というような書き方をしていたことです。
それは、出題者が求めていた解答(回答)ではあるでしょうけれども、
それをもって正解というのはいいすぎじゃないかなあと。
まあわたしが気にしすぎなんでしょうが。
・戦う司書DVD
9巻まで発売予定があるということは、2クールものなんでしょうか。
・awk の RS と FS
FS はどのawkでも問題なく正規表現を放り込めますが、RSは違いますよ~。
mawk は使えますけど。
perlsix のアナグラムからつけられた名前なんだとか。
blog | Perlgeek.de :: Sprixel, a 6 compiler powered by JavaScript
Sprixel, a 6 compiler powered by JavaScript
Permanent link
Today I want to announce sprixel, a new Perl 6 compiler in its early stage of
development, written in JavaScript and using the standard Perl 6 grammar STD.pm.
・名前が sprixel という新しい Perl 6 コンパイラー
・まだ開発の初期段階
・JavaScript で記述されている
・Perl 6 の構文として STD.pm を使っている
Sprixel (an anagram of perlsix) development was initiated by Matthew Wilson, aka
diakopter. It traverses the Abstract Syntax Tree as produced by STD.pm, transforms it
into an intermediate JavaScript data structure similar to JSON (but with some
enhancements to handle cyclic structures), and has a small, continuation based runloop
that executes the JavaScript. Currently the only backend is the V8 compiler and
virtual machine - but if/when the STD grammar is implemented, you'll be able to run
Perl 6 in your browser.
・Perl 6のプログラムを ASTに変換し、それをさらにJavaScriptに。
Currently sprixel supports scalar and list variables, numbers (including bigint),
strings, string interpolation, basic control flow, closures, named sub declaration
(with parameters), and map.
・現状でサポートされているもの
Sprixel development is optimized for fun, and already picked up some contributors
(notably, mberends implemented many infix operators, a makefile, and a test harness).
The source code can be found in the pugs repository (but is completely independent of
the pugs compiler project). The main communication medium so far has been the #perl6
IRC channel on irc.freenode.net.
Motivation
Why yet another Perl 6 implementation? you might ask. A few reasons actually:
* Sprixel exercises STD.pm, which so far is mostly tested only for parse successes
or failures. Relying on the underlying AST structure in a real compiler helps to
reveal tricky bugs and unnecessarily difficult interfaces.
* Most existing Perl 6 compilers either implement only a minimal subset of Perl 6,
or rely heavily on a rather large stack of underlying software, thus making
substantial contributions non-trivial.
* Implementing a compiler helps one to understand the language better.
yhara さんが、RがSchemeで実装されるのって本当なのかという疑問を
ついったでつぶやいていたのでちょっと調べてみました。
まずはソースアーカイブを展開して、そこに含まれているファイルの拡張子ごとに数を数えてみます。
>dir /b /s | grep -o -e "\.[^.\\]*$" | sortf | uniq -c | sortf -r
1276 .Rd
718 .R
511 .c
170 .po
167 .h
149 .mo
97 .in
87 .afm
45 .win
45 .f
42 .save
23 .gmo
20 .pot
19 .pdf
18 .enc
14 .html
13 .m4
13 .Snw
12 .lnk
12 .gz
11 .tcl
10 .texi
10 .rc
10 .pm
8 .pl
8 .class
7 .txt
7 .mk
7 .java
6 .tab
6 .eps
5 .sh
5 .jpg
5 .fd
5 .def
5 .R~
4 .isl
4 .css
4 .Rd~
3 .sty
3 .rda
3 .manifest
2 .y
2 .tex
2 .site
2 .sin
2 .sed
2 .hide
2 .header
2 .db
2 .csv
2 .bmp
2 .S
2 .Rin
2 .1
2 .0
2個以上ソースアーカイブ中に現れる拡張子を抜き出してみました。
Scheme っぽいのは見当たらないですねえ。
あと、一位の .Rd ですが
% File src/library/stats/man/ave.Rd
% Part of the R package, http://www.R-project.org
% Copyright 1995-2007 R Core Development Team
% Distributed under GPL 2 or later
\name{ave}
\title{Group Averages Over Level Combinations of Factors}
\usage{
ave(x, \dots, FUN = mean)
}
\alias{ave}
\arguments{
\item{x}{A numeric.}
\item{\dots}{Grouping variables, typically factors, all of the same
\code{length} as \code{x}.}
\item{FUN}{Function to apply for each factor level combination.}
}
\description{
Subsets of \code{x[]} are averaged, where each subset consist of those
observations with the same factor levels.
}
\value{
A numeric vector, say \code{y} of length \code{length(x)}.
If \code{\dots} is \code{g1,g2}, e.g.,
\code{y[i]} is equal to \code{FUN(x[j]}, for all \code{j} with
\code{g1[j] == g1[i]} and \code{g2[j] == g2[i])}.
}
\seealso{\code{\link{mean}}, \code{\link{median}}.}
\examples{
require(graphics)
ave(1:3)# no grouping -> grand mean
attach(warpbreaks)
ave(breaks, wool)
ave(breaks, tension)
ave(breaks, tension, FUN = function(x)mean(x, trim=.1))
plot(breaks, main =
"ave( Warpbreaks ) for wool x tension combinations")
lines(ave(breaks, wool, tension ), type='s', col = "blue")
lines(ave(breaks, wool, tension, FUN=median), type='s', col = "green")
legend(40,70, c("mean","median"), lty=1,col=c("blue","green"), bg="gray90")
detach()
}
\keyword{univar}
ということで、マニュアル向けのドキュメントフォーマットのようです。
そしてソースコードがどんな具合かというと
src/main/apply.c
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 2000-7 the R Development Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, a copy is available at
* http://www.r-project.org/Licenses/
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <Defn.h>
/* .Internal(lapply(X, FUN)) */
/* This is a special, so has unevaluated arguments. It is called from a
closure wrapper, so X and FUN are promises. */
SEXP attribute_hidden do_lapply(SEXP call, SEXP op, SEXP args, SEXP rho)
{
SEXP R_fcall, ans, names, X, XX, FUN;
int i, n;
PROTECT_INDEX px;
checkArity(op, args);
PROTECT_WITH_INDEX(X = CAR(args), &px);
PROTECT(XX = eval(CAR(args), rho));
FUN = CADR(args); /* must be unevaluated for use in e.g. bquote */
n = length(XX);
if (n == NA_INTEGER) error(_("invalid length"));
PROTECT(ans = allocVector(VECSXP, n));
names = getAttrib(XX, R_NamesSymbol);
if(!isNull(names)) setAttrib(ans, R_NamesSymbol, names);
/* The R level code has ensured that XX is a vector.
If it is atomic we can speed things up slightly by
using the evaluated version.
*/
{
SEXP ind, tmp;
/* Build call: FUN(XX[[<ind>]], ...) */
/* Notice that it is OK to have one arg to LCONS do memory
allocation and not PROTECT the result (LCONS does memory
protection of its args internally), but not both of them,
since the computation of one may destroy the other */
PROTECT(ind = allocVector(INTSXP, 1));
if(isVectorAtomic(XX))
PROTECT(tmp = LCONS(R_Bracket2Symbol,
LCONS(XX, LCONS(ind, R_NilValue))));
else
PROTECT(tmp = LCONS(R_Bracket2Symbol,
LCONS(X, LCONS(ind, R_NilValue))));
PROTECT(R_fcall = LCONS(FUN,
LCONS(tmp, LCONS(R_DotsSymbol, R_NilValue))));
for(i = 0; i < n; i++) {
INTEGER(ind)[0] = i + 1;
SET_VECTOR_ELT(ans, i, eval(R_fcall, rho));
}
UNPROTECT(3);
}
UNPROTECT(3); /* X, XX, ans */
return ans;
}
static SEXP do_one(SEXP X, SEXP FUN, SEXP classes, SEXP deflt,
Rboolean replace, SEXP rho)
{
SEXP ans, names, klass, R_fcall;
int i, j, n;
Rboolean matched = FALSE;
/* if X is a list, recurse. Otherwise if it matches classes call f */
if(isNewList(X)) {
n = length(X);
PROTECT(ans = allocVector(VECSXP, n));
names = getAttrib(X, R_NamesSymbol);
/* or copy attributes if replace = TRUE? */
if(!isNull(names)) setAttrib(ans, R_NamesSymbol, names);
for(i = 0; i < n; i++)
SET_VECTOR_ELT(ans, i, do_one(VECTOR_ELT(X, i), FUN, classes,
deflt, replace, rho));
UNPROTECT(1);
return ans;
}
if(strcmp(CHAR(STRING_ELT(classes, 0)), "ANY") == 0) /* ASCII */
matched = TRUE;
else {
PROTECT(klass = R_data_class(X, FALSE));
for(i = 0; i < LENGTH(klass); i++)
for(j = 0; j < length(classes); j++)
if(Seql(STRING_ELT(klass, i), STRING_ELT(classes, j)))
matched = TRUE;
UNPROTECT(1);
}
if(matched) {
/* PROTECT(R_fcall = lang2(FUN, X)); */
PROTECT(R_fcall = lang3(FUN, X, R_DotsSymbol));
ans = eval(R_fcall, rho);
UNPROTECT(1);
return(ans);
} else if(replace) return duplicate(X);
else return duplicate(deflt);
}
確かに Lisp (Scheme)っぽさがところどころにありますが、
Scheme で実装されてるとか、Emacs みたいに二段階(CでLispインタープリターと
最低限のプリミティブを実装、それを使ってエディターを構築)というわけでもなさそうです。