/*
 * bLN^[
 * 	cfo[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) (Ȃ :#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 "ׂʂɘb킯Ȃ񂾂">
	<print "łAǂĂȂbȂ">
	<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 Ȃ)>
	<d #o (
		(Ⴄ񂶂Ȃ)
		()
		(Ƃ)
		({I)
		(Ȃ́A#h Ȃ)
		)>
	;
<c #o (ł :#l)>
	<d #o  (
		(ł̂)
		(́AǂƂ)
		([)
		(ł́AAI)
		(ꂪ]݂́A{)
		(ȂƂłȂ)
		)>
	;
<c #o (Ȃ  :#l)>
	<d #o (
		(Ȃ́A#l )
		(#l  Aŗǂ)
		(#l AłǂȂ̂H)
		(ǂv̂H)
		()
		)>
	;
<c #o (  :#l)>
	<d #o (
		(̓ZiAȂ̂߂ɂɋ̂)
		(́AZi)
		(A̓Zi Ax킹Ȃł)
		(킩Ȃ)
		(ȂƓ)
		(Ȃ́AǂȂ̂)
		)>
	;
<c #o ( :#l)>
	<d #o (
		(͑厖)
		(ƁAȂƂȂ)
		(΁A]Ă̂)
		(͂Ȃ̂)
		)>
	;
<c #o (] :#l)>
	<d #o (
		(]͑厖)
		(])
		(ƁAȂƂȂ)
		(΁A])
		(Ȃ̂])
		)>
	;
<c #o (J :#l)>
	<d #o (
		(JĂ̂Ƃ)
		(])
		(ƁAȂƂȂ)
		(΁A]̂)
		(̂ȂƂȂ)
		(ʂɁAȂ̂ƂȂ񂩐SzȂ)
		)>
	;

<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 )
		(#t1  #t2 )
		( #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ẮHA͂肵ȂI)
		(#h ͂ǂ)
		(Ȃ #h Ɋ҂ł)
		(炭A #h ̂ƂˁA킩)
		(#h ɂĘb)
		(ӂ #h )
		(łA #h ͖{͂Ȃ̂Ȃ)
		(#l ƂƂ)
		(#h ȂĎvȂ)
		(#h ́A{)
		(#h ̑_͉Hł̂)
		(#h ̖͉H)
		(#h ł)
		(#h ɂ́ANN)
		(#l ɂ́ANN)
		(ȂƁI #l Ƃ́II)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ͂ǂȂ)
		(#h y݁ANN)
		(#h )
		(#h ȂˁAႢȂł)
		(A#h ɂčlAזȂł)
		(͂A#h ͏dv)
		(#h Qlɂ)
		(#h ́A􂵂)
		(#h łAȂقǂ)
		(#h ͂ǂȂ́H)
		(#h CɂȂAmĂȂ狳ȂI)
		(#l ƂƂ)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ɂ͂ǂȖړI)
		(#h Ɋ҂AʂɂȂ̂ƂȂ)
		(#h ͂ǂH)
		(#h ɂ͍)
		(#h ɂ͋Ȃ)
		(#h ȂˁAႢȂł)
		(́A #h )
		(#h ́AzȏゾA{)
		(#h ́Az͈͓)
		(#h ɂ́AVN)
		(#h ͂ǂȂ́H킩Ȃ́H)
		(ȂقǂˁA #l ƂƂ)
		)>
	;
<c #o (#h  :#l)>
	<#rand = ::sys<random _> % 2> <is #rand 1>
	<d #o (
		(#h ɂ͂ǂ̂悤ȖړÍH)
		(|Cg #h )
		(#h ͑؂)
		(#h 𓚂Ă)
		(#h ͊mˁA{ˁH͂茾Ȃ)
		( #h ͊mH)
		(#h ҂)
		(#h ͂ǂȂ́H)
		(#h Ȃ)
		(́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 ɂ́Aǂ̂悤ȖړÍH)
		(#h1  #h2 Advȃ|CgI)
		(|Cg #h1  #h2 )
		(#h1  #h2 ɂĘbĂ)
		(#h1  #h2 ͑؂)
		(#h1  #h2 ɒڂ)
		(#h1  #h2 ͂ǂȂ)
		(#h1  #h2 ɂӂ킵Ȃ)
		(́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)
		()
		(Ȃ)
		(ɂĂˁACC)
		)>
	;
<c #o (  :#l)>
	<d #o (
		(H)
		(H)
		(Ȃ́A #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