prepress-tips
codeLayouter の記述メモ2
最終更新:
prepress-tips
-
view
最終更新日時: 2010/10/10
改めて codeLayouter 再検討
- アノテーション と コード の記述の方針
- アノテーション で プログラムの構造 を記述する。
- オブジェクト指向風 に記述する。
- アノテーション は アノテーションの世界で 閉じる。
- アノテーション に シンボル と コード を対応させて
全体をプログラムに変換する。- シンボル は 省略してもよい。
- コード は コーディング知識 的に記述する。
- コード は どの場所で記述してもよい。
- アノテーション で プログラムの構造 を記述する。
/name solve wgc problem / wgc_pl.pl
* 処理 /
/ debug - get option
/ message - start
/ state - init ; history - new ; answer - new ; goalseeker - seek
/ answer - message
* 変数 /
? debug //
? state //
? history //
? answer //
* 関数 /
? goalseeker //
/ state - unique
/ if( history - is twice ) { message - twice ; return }
/ if( state - is goal ) { todo - goal ; message - goal ; return }
/ if( state - is no good ) { message - no good ; return }
? possible //
/ possible - at state
/ for( possible ) {
/ history - forward ; possible - take one
/ history - message ; possible - message ; state - message
/? message - pause
/ goalseeker - seek
/ history - backward
/ }
/name solve wgc problem
use strict ;
/ 変数
/ 関数
/ 処理
/name 未指定
/use wgc_pl_detail.txt
* 処理 /
/ debug - get option
/ message - start
/ state - init ; history - new ; answer - new ; goalseeker - seek
/ answer - message
* 変数 /
? debug //
? state //
? history //
? answer //
* 関数 /
? goalseeker //
/ state - unique
/ if( history - is twice ) { message - twice ; return }
/ if( state - is goal ) { todo - goal ; message - goal ; return }
/ if( state - is no good ) { message - no good ; return }
? possible //
/ possible - at state
/ for( possible ) {
/ history - forward ; possible - take one
/ history - message ; possible - message ; state - message
/? message - pause
/ goalseeker - seek
/ history - backward
/ }
/name solve wgc problem
use strict ;
/ 変数
/ 関数
/ 処理
/name 未指定
/use wgc_pl_detail.txt
/? ----------------------------------------------------------
/?- debug , option
* debug // my $debug
* debug - get option /
? option //
/ debug = ( option =~ option - debug ) ;
* option // my $option
$option = @ARGV ? $ARGV[0] : '' ;
* option - debug /
m,d,i
/? ----------------------------------------------------------
/?- message
* message - start /
print '狼・山羊・キャベツの川渡し問題 を解く' . "\x0a" ;
/ if( debug ) { print '途中経過は' . "\x0a" }
* message - twice /
/ if( debug ) { print '--- twice' . "\x0a" }
* message - goal /
/ if( debug ) { print '====== goal ======' . "\x0a" }
* message - no good /
/ if( debug ) { print '--- no good' . "\x0a" }
* message - pause /
/ if( debug ) { `pause` }
/? ----------------------------------------------------------
/?- answer
* answer // my @answer
* answer - new /
@answer = () ;
* answer - message /
print '解は' . "\x0a" ;
for( @answer ) { print $_."\x0a" }
/? ----------------------------------------------------------
/?- goalseeker
* goalseeker // GoalSeek( )
* goalseeker - seek /
/ goalseeker ;
/? ----------------------------------------------------------
/?- history
* history // my %history ; my @history
* history - new /
%history = () ; @history = () ;
* history - is twice /
/ $history{ state }
* todo - goal /
/ push answer , join ' → ' , history , state ;
* history - forward /
/ push history , state ; $history{ state } = 1 ;
* history - message /
/ if( debug ) { print 'history ' , ( join ' → ' , history ) , "\x0a" }
* history - backward /
/ state = pop history ; delete $history{ state } ;
/?- debug , option
* debug // my $debug
* debug - get option /
? option //
/ debug = ( option =~ option - debug ) ;
* option // my $option
$option = @ARGV ? $ARGV[0] : '' ;
* option - debug /
m,d,i
/? ----------------------------------------------------------
/?- message
* message - start /
print '狼・山羊・キャベツの川渡し問題 を解く' . "\x0a" ;
/ if( debug ) { print '途中経過は' . "\x0a" }
* message - twice /
/ if( debug ) { print '--- twice' . "\x0a" }
* message - goal /
/ if( debug ) { print '====== goal ======' . "\x0a" }
* message - no good /
/ if( debug ) { print '--- no good' . "\x0a" }
* message - pause /
/ if( debug ) { `pause` }
/? ----------------------------------------------------------
/?- answer
* answer // my @answer
* answer - new /
@answer = () ;
* answer - message /
print '解は' . "\x0a" ;
for( @answer ) { print $_."\x0a" }
/? ----------------------------------------------------------
/?- goalseeker
* goalseeker // GoalSeek( )
* goalseeker - seek /
/ goalseeker ;
/? ----------------------------------------------------------
/?- history
* history // my %history ; my @history
* history - new /
%history = () ; @history = () ;
* history - is twice /
/ $history{ state }
* todo - goal /
/ push answer , join ' → ' , history , state ;
* history - forward /
/ push history , state ; $history{ state } = 1 ;
* history - message /
/ if( debug ) { print 'history ' , ( join ' → ' , history ) , "\x0a" }
* history - backward /
/ state = pop history ; delete $history{ state } ;
/? ----------------------------------------------------------
/?- state
* state // my $state
* state - init /
/ state = 'fwgc' ;
* state - unique /
/ change - unique
* state - is goal /
/ state eq ''
* state - is no good /
/ ! ( exist - f ?
/ count - wg != 0 && count - gc != 0 :
/ count - wg != 2 && count - gc != 2 )
* state - message /
/ if( debug ) { print 'state ' . state . "\x0a" }
/? ----------------------------------------------------------
/?- possible
* possible // my @possible
@possible = () ;
* possible - at state /
/ if( exist - f ) {
/ push possible , grep { exist - $_ } possible - all
/ }
/ else {
/ push possible , grep { ! ( exist - $_ ) } possible - all
/ }
* possible - take one /
/ if( exist - f ) { change - del f & $_ }
/ else { change - add f & $_ }
* possible - all /
split '' , 'fwgc'
* possible - message /
/ if( debug ) { print 'take ' . $_ . "\x0a" }
/? ----------------------------------------------------------
/?- state --- exist , count , change
* exist - f /
/ state =~ m,f,
* exist - \$_ /
/ state =~ m,$_,
* count - wg /
/ scalar( @{[ state =~ m,[wg],g ]} )
* count - gc /
/ scalar( @{[ state =~ m,[gc],g ]} )
* change - unique /
/ state = join '', sort split '', state ;
* change - del f & \$_ /
/ state =~ s,$_,, ; state =~ s,f,, ;
* change - add f & \$_ /
/ state .= $_ eq 'f' ? $_ : 'f' . $_ ;
/?- state
* state // my $state
* state - init /
/ state = 'fwgc' ;
* state - unique /
/ change - unique
* state - is goal /
/ state eq ''
* state - is no good /
/ ! ( exist - f ?
/ count - wg != 0 && count - gc != 0 :
/ count - wg != 2 && count - gc != 2 )
* state - message /
/ if( debug ) { print 'state ' . state . "\x0a" }
/? ----------------------------------------------------------
/?- possible
* possible // my @possible
@possible = () ;
* possible - at state /
/ if( exist - f ) {
/ push possible , grep { exist - $_ } possible - all
/ }
/ else {
/ push possible , grep { ! ( exist - $_ ) } possible - all
/ }
* possible - take one /
/ if( exist - f ) { change - del f & $_ }
/ else { change - add f & $_ }
* possible - all /
split '' , 'fwgc'
* possible - message /
/ if( debug ) { print 'take ' . $_ . "\x0a" }
/? ----------------------------------------------------------
/?- state --- exist , count , change
* exist - f /
/ state =~ m,f,
* exist - \$_ /
/ state =~ m,$_,
* count - wg /
/ scalar( @{[ state =~ m,[wg],g ]} )
* count - gc /
/ scalar( @{[ state =~ m,[gc],g ]} )
* change - unique /
/ state = join '', sort split '', state ;
* change - del f & \$_ /
/ state =~ s,$_,, ; state =~ s,f,, ;
* change - add f & \$_ /
/ state .= $_ eq 'f' ? $_ : 'f' . $_ ;