Skip to content

Instantly share code, notes, and snippets.

View leque's full-sized avatar

OOHASHI Daichi leque

View GitHub Profile
(use parser.peg)
(define ($look-ahead parse)
(lambda (s0)
(receive (r v s) (parse s0)
(values r v s0))))
;; #/A*B/ で A, B それぞれの開始文字列に共通部分がない場合
(define (f a b-start b)
($do (h ($many-till a ($look-ahead b-start)))
(use parser.peg)
(define ($look-ahead parse)
(lambda (s0)
(receive (r v s) (parse s0)
(values r v s0))))
@leque
leque / m.scala
Created July 1, 2012 05:12
Direct-Style Monads
trait Monad[M[_]] {
def unit[A](x : A) : M[A]
def bind[A, B](m : M[A], f : A => M[B]) : M[B]
}
implicit object OptionMonad extends Monad[Option] {
def unit[A](x : A) = Some(x)
def bind[A, B](m : Option[A], f : A => Option[B]) = m.flatMap(f)
@leque
leque / jb.md
Last active August 21, 2018 09:40
2012/08/26 Java基礎勉強会 at 名古屋 資料

return の話

  • 無名関数と return で小話を一席

自己紹介

  • Twitter: dico_leque
  • 趣味 Schemer
  • お仕事で Scala とか OCaml とか F# とか Java とか
@leque
leque / Fpm2012.scala
Created September 12, 2012 19:04
Direct-Style Monads
// Direct-Style Monads in Scala
object Fpm2012 {
trait Monad[M[_]] {
def unit[A](x : A) : M[A]
def bind[A, B](m : M[A], f : A => M[B]) : M[B]
}
implicit object OptionMonad extends Monad[Option] {
def unit[A](x : A) = Some(x)
@leque
leque / ddbind.patch
Created January 17, 2013 07:09
Delimited dynamic binding for Gauche. failed on test/error.scm yet. discrepancies found. Errors are: test restart & dynamic-wind: expects (a b c x e f z a b x e f z) => got (a b c x e f z b x e f z)
diff --git a/src/gauche.h b/src/gauche.h
index 9ae7aa2..106b115 100644
--- a/src/gauche.h
+++ b/src/gauche.h
@@ -1456,6 +1456,7 @@ SCM_EXTERN ScmObj Scm_MakeSubr(ScmSubrProc *func,
int required, int optional,
ScmObj info);
SCM_EXTERN ScmObj Scm_NullProc(void);
+SCM_EXTERN ScmObj Scm_BoundaryProc(void);
// origial: https://gist.github.com/koropicot/6265729
// NYSL Version 0.9982
trait Functor[F[_]] {
def fmap[A, B](fa: F[A])(f: A => B): F[B]
}
class Const[A, +B](val value: A)
class Identity[A](val value: A)
;;; pattern guards a la Haskell
;;; 元ネタ: http://d.hatena.ne.jp/gengar/20130909/1378719785
(use util.match)
(define-syntax do-match*
(syntax-rules ()
((_ binds body ...)
(%do-match* #f binds body ...))))
diff --git a/lib/gauche/regexp.scm b/lib/gauche/regexp.scm
index 76cdb44..3ca5c1c 100644
--- a/lib/gauche/regexp.scm
+++ b/lib/gauche/regexp.scm
@@ -190,7 +190,7 @@
[(assert nassert) (apply unparse-assert-like test)]
[else (err "invalid AST in the test part of cpat" test)]))
(seq yes)
- (when no (disp "|") (seq no))
+ (unless (null? no) (disp "|") (seq no))
diff --git a/src/regexp.c b/src/regexp.c
index 7a621fd..58c621e 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -2476,9 +2476,11 @@ static void rex_rec(const unsigned char *code,
case RE_BEGIN: {
int grpno = *code++;
const char *opos = ctx->matches[grpno]->startp;
+ const char *oend = ctx->matches[grpno]->endp;
ctx->matches[grpno]->startp = input;