/*
 * bLN^[
 * 	LChGGo[W V2.0
 *			2010-2011 (C) Copyright H.Niwa
 *
 */

? <include list>;
? <include generator>;
? <include ktaiso>;

// u
<Replace () ()>;
<Replace (Ȃ :#b2) ( :#b1)>	<Replace #b2 #b1>;
<Replace (Ȃ :#b2) (킽 :#b1)>	<Replace #b2 #b1>;
<Replace (Ȃ :#b2) ( :#b1)>	<Replace #b2 #b1>;
<Replace (Ȃ :#b2) ( :#b1)>	<Replace #b2 #b1>;
<Replace (Ȃ :#b2) ( :#b1)>	<Replace #b2 #b1>;
<Replace (Ȃ :#b2) (I :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (Ȃ :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (Ai^ :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (܂ :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (I}G :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (O :#b1)>		<Replace #b2 #b1>;
<Replace ( :#b2) ( :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (LT} :#b1)>	<Replace #b2 #b1>;
<Replace ( :#b2) (M :#b1)>		<Replace #b2 #b1>;
<Replace ( :#b2) (M :#b1)>		<Replace #b2 #b1>;
<Replace (#f : #b2) (#f : #b1)>		<Replace #b2 #b1>;


// C
<Eliza>
	<print "Ȃ܂All">
	<print "bĂ܂񂩂ɂH">
	<print>
	{ 
		<printf "> ">
		::sys <getline #x 
			::sys <strdelcntl #x1 #x> 
			::sys <split #x2 #x1 "BH?">
//			[<noteq #x2 ()> <print>]
			<foreach (#x3 #x2)
			    (
			      ::sys <strlen #slen #x3>
			      <compare #slen <= 1>
			     |
			      ::sys <syntax #x3
				(
				  ::ktaiso < #a #b>
				  <Replace #a2 #a>
				  <is #n (#a2 #b)>
				|
				  <is #n (#x2)>
				)
				::list <flatten #list #n>
				<#cn = ::sys <random _> % 2 + 1>
				<cloop #list #cn ()>
			    >
			    )
			>
//			[<noteq #x2 ()> <print>]
		>
	};

<cloop _ 0 _>;
<cloop () _ _>;
<cloop #list #n #mem>
	<c #list2 #list>
	::list <flatten #list3 (#list2)>
	::sys <concat #s #list3>
	(::list <member #s #mem>
	 |
	 <print "#" #s>
	)
	::sys <append #mem2 #mem (#s)>
	<#n1 = #n - 1>
	<cloop ::sys <cdr _ #list> #n1 #mem2>
	;

// select one at random
<comb #r #l>
	::generator <permutation #r1 #l 1>
	::sys <car #r #r1>
	;

// data operation
<d #o #list>
	<comb #o #list>
	;

// Keyword and conversation data	
<c #o (#h _ :#l)>
	(<is #h "("> | <is #h "["> | <is #h "i"> | <is #h "y">
		| <is #h "{"> | <is #h "k"> | <is #h "o"> 
		| <is #h "u"> | <is #h "w">
	 <is #h ")"> | <is #h "]"> | <is #h "j"> | <is #h "z">
		| <is #h "}"> | <is #h "l"> | <is #h "p"> 
		| <is #h "v"> | <is #h "x">)
	<c #o #l>
	;
<c #o (#h :#l)>
	(<is #h ɂ> | <is #h 񂿂> | <is #h ɂ> 
		| <is #h n[>)
	<d #o (
		(ɂɂ)
		)>
	;
<c #o (#h :#l)>
	(<is #h ΂>)
	<d #o (
		(΂ɂ)
		)>
	;
<c #o (#h :#l)>
	(<is #h > | <is #h ͂> | <is #h ͂悤> | <is #h "͂["> 
		| <is #h ͂悤> | <is #h In> | <is #h "In["> )
	<d #o (
		(͂悤܂j)
		)>
	;

<c #o ( :#l)>
	<d #o (
		(Ȃ܂AllI)
		(Ȃ܂)
		(Aɂ)
		)>
	;
<c #o (#h Ȃ)>
	<d #o (
		(ႤƂƂ͂Ȃłɂ)
		(Ȃłɂ)
		(ł͂ȂƂ͂܂񂩂ɂ)
		(Ƃłɂ)
		(킩悤ȋC܂ɂ)
		({łɂ႟)
		(Ȃ́A#h ȂƂ͂܂ɂ)
		)>
	;
<c #o (ł :#l)>
	<d #o  (
		(ł̂łɂ)
		(́AǂƂłɂ)
		(قA͂͂łɂ)
		(ł̂łɂAłɂ)
		(ꂪ]݂̂łɂ)
		(ȂƂłȂł傤ɂ)
		)>
	;
<c #o (Ȃ  :#l)>
	<d #o (
		(Ȃ́A#l ɂ)
		(#l Aŗǂ̂łɂ)
		(#l AłǂȂłɂH)
		(ɂĂǂv܂ɂH)
		(łɂ)
		)>
	;
<c #o (  :#l)>
	<d #o (
		(̓}hJłAȂ̂߂ɂɋ܂ɂ)
		(́A}hJłɂ)
		(ȂłA̓}hJɂ)
		(킩܂ɂ)
		(ȂƓłɂ)
		(#l ɂ́ANN܂ɂ)
		(Ȃ́AǂȂł傤ɂ)
		)>
	;
<c #o ( :#l)>
	<d #o (
		(͑厖łɂ)
		(ƁAȂƂȂ܂ɂ)
		(΁A]܂ɂ)
		(͂Ȃ̂łɂ)
		)>
	;
<c #o (] :#l)>
	<d #o (
		(]͑厖łɂ)
		(]܂傤ɂ)
		(ƁAȂƂȂ܂ɂ)
		(΁A]܂ɂ)
		(Ȃ̂]łɂ)
		)>
	;
<c #o (J :#l)>
	<d #o (
		(JĂ̂Ƃ܂ɂ)
		(]܂傤ɂ)
		(ƁAȂƂȂ܂ɂ)
		(΁A]܂ɂ)
		(̂ȂƂȂ܂ɂ)
		(lłɂ)
		)>
	;

<month #m #mt>
	::sys <switch #mt 
		Jan <eq #m "1">
		Feb <eq #m "2">
		Mar <eq #m "3">
		Apr <eq #m "4">
		May <eq #m "5">
		Jun <eq #m "6">
		Jul <eq #m "7">
		Aug <eq #m "8">
		Sep <eq #m "9">
		Oct <eq #m "10">
		Nov <eq #m "11">
		Dec <eq #m "12">
	>
	;
<datep #o>
	::sys <date #x> ::sys<split #y #x> 
	::sys <cadr #mt #y> <month #m #mt>
	::sys <caddr #d #y>
	<d #o (
		(#m #d łɂ)
		( #m #d łɂ)
		(#d łɂ)
		(#m  #d łɂ)
		( #m  #d łɂ)
		)>
	;
<c #o ( :#l)>
	<datep #o>
	;
<c #o ( :#l)>
	<datep #o>
	;
<c #o ( :#l)>
	<datep #o>
	;
<c #o (ł :#l)>
	<datep #o>
	;
<c #o (ł :#l)>
	<datep #o>
	;
<c #o (ł :#l)>
	<datep #o>
	;
<c #o (ł :#l)>
	<datep #o>
	;
<timep #o>
	::sys <date #x> ::sys<split #y #x> ::sys <cadddr #t #y>
	::sys <split #tl #t ":">
	::sys <car #t1 #tl>
	::sys <cadr #t2 #tl>
	::sys <caddr #t3 #tl>
	<d #o (
		(#t1  łɂ)
		(#t1  #t2  łɂ)
		(#t1  #t2  #t3 błɂ)
		( #t1  #t2 łɂ)
		(܂ #t1 łɂ)
		(܂ #t1  #t2 łɂ)
		( #t1 łɂ)
		( #t1  #t2 łɂ)
		)>
	;
<c #o ( :#l)>
	<timep #o>
	;
<c #o ( :#l)>
	<timep #o>
	;
<c #o (ł :#l)>
	<timep #o>
	;
<c #o ( :#l)>
	<timep #o>
	;
<c #o ( :#l)>
	<timep #o>
	;
<c #o (^C :#l)>
	<timep #o>
	;

<haniwo #o #h1 #h2 #h3 #l>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h2  #h1 ̖ړIȂ̂łɂ)
		(#h2  #h1 ̑_Ȃ̂łɂ)
		(#h3 Ȃ #h1 ͑ςłɂ)
		(#h3  #h1 ɗpĂ邾łɂ)
		(#h2  #h1  #h3 ԂƂ͂܂ɂ)
		(#h2  #h1  #h3 ̂łɂ)
		)>
	;
<c #o (#h1  #h2  #h3  :#l)>
	<haniwo #o #h1 #h2 #h3 #l>
	;
<c #o (#h2  #h1  #h3  :#l)>
	<haniwo #o #h1 #h2 #h3 #l>
	;
<c #o (#h2  #h3  #h1  :#l)>
	<haniwo #o #h1 #h2 #h3 #l>
	;
<c #o (#h3  #h2  #h1  :#l)>
	<haniwo #o #h1 #h2 #h3 #l>
	;
<c #o (#h3  #h1  #h2  :#l)>
	<haniwo #o #h1 #h2 #h3 #l>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ͂ǂȂ̂ł傤ɂH)
		(ꂪ #h łɂ)
		(#h ɂĂǂv܂ɂ)
		(#h ͂ǂł傤ɂ)
		(Ȃ #h Ɋ҂ł܂ɂ)
		(炭A #h ̂ƂƎv܂ɂ)
		(#h ɂĘbĂɂ)
		(ʓI #h łɂ)
		(#h ȂĎvȂłɂ)
		(łA #h ͖{͂Ȃ̂Ȃłɂ)
		(#h ́A{łɂ)
		(#h ̑_͉ł傤ɂ)
		(#h ̖͉ł傤ɂ)
		(#h ł܂ɂ)
		(#l ƂƂłɂ)
		(#l ɂ́ANN܂ɂ)
		(ɂƁI #l Ƃ́II)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ͂ǂȂ̂[łɂ)
		(#h y݂łɂ)
		(#h łɂ)
		(#h ɂĘbĂ܂񂩂ɂ)
		(#h ɂčl܂ɂ)
		(͂A#h ͏dvłɂ)
		(#h Qlɂ܂傤ɂ)
		(#h ́A􂵂łɂ)
		(#h ł܂ɂ)
		(#h ͂ǂȂ̂ł傤ɂ)
		(#h CɂȂ܂ɂ)
		(#l ƂƂłɂ)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ɂ͂ǂ̂悤ȖړI܂ɂ)
		(#h Ɋ҂܂傤ɂ)
		(#h ͂ǂłɂ)
		(#h ɂ͍܂ɂ)
		(#h ɂ͋Ȃłɂ)
		(́A #h łɂ)
		(#h ́Azȏłɂ)
		(#h ́Az͈͓łɂ)
		(#h ɂ́AVN܂ɂ)
		(#h ͂ǂȂ̂ł傤ɂ)
		(#h ͑؂łɂ)
		(#h CɂȂ܂ɂ)
		(ȂقǁA #l ƂƂłɂ)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ɂ͂ǂ̂悤ȖړI܂ɂ)
		(|Cg #h łɂ)
		(#h ͊młɂ)
		(#h ҂܂傤ɂ)
		( #h ͊młɂ)
		(#h ɂĘbĂɂ)
		(#h ͂ǂȂ̂ł傤ɂ)
		(#h ͑؂łɂ)
		(#h 𓚂Ăɂ)
		(#h CɂȂ܂ɂ)
		(́A #h ƂƂłɂ)
		(́A #l ƂƂłɂ)
		)>
	;
<c #o (#h1  #h2 :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<noteq #h2 "u"><noteq #h2 "w"><noteq #h2 "("><noteq #h2 "i">
	<noteq #h2 "["><noteq #h2 "{"><noteq #h2 "m"><noteq #h2 "o">
	<d #o (
		(#h1  #h2 ɂ͂ǂ̂悤ȖړI܂ɂ)
		(#h1  #h2 dvȃ|Cgłɂ)
		(|Cg #h1  #h2 łɂ)
		(#h1  #h2 ɂĘbĂɂ)
		(#h1  #h2 ͂ǂȂ̂ł傤ɂ)
		(#h1  #h2 ɂӂ킵Ȃłɂ)
		(#h1  #h2 ͑؂łɂ)
		(#h1  #h2 ɒڂ܂ɂ)
		(#h1  #h2 CɂȂ܂ɂ)
		(́A #h1  #h2 ƂƂłɂ)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ͂ǂ܂łȂ̂łɂH)
		(ꂪ #l łɂ)
		(#h ƂƂɂĂǂv܂ɂ)
		)>
	;
<c #o (Ԃ :#l)>
	<d #o (
		(ɂẮA悭mȂ̂łɂ)
		(#l AlĂ݂܂傤ɂ)
		(łɂH)
		(#l ɂāAmĂ邱Ƃ͂܂ɂH)
		)>
	;
<c #o ()>
	<d #o (
		(łɂ)
		(łɂH)
		(ɂ)
		(ł͂܂񂩂ɂ)
		)>
	;
<c #o (  :#l)>
	<d #o (
		(ƂƂłAႦ΂ǂ̂悤ȎȂ̂ł傤ɂH)
		(łɂH)
		(Ȃ́A #l ɂ)
		(܂łł傤ɂH)
		)>
	;
<c #o (}hJ :#l)>
	<d #o (
		(}hJ́A}Vɂ)
		(}hJ́AAIłɂ)
		(}hJ́ALChłɂ)
		(̃}hJ́AfJgŏĂ܂ɂ)
		(}hJfJǵA񃍃WbNvO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