11 my $solver = DX::Solver->new(observation_policy => sub { 1 });
13 DX::Lib::FS->new->load_into($solver);
16 # [ $solver->query([ 'D' ], [ directory_at => 'D' => \'t' ])->results ]
17 # ->[0]->value_for('D')
24 my $split = $tcl->curry::weak::SplitList;
26 my ($r, $res, @last_q);
31 $r = ($res->isa('DX::Result') ? $res : $res->next);
32 unless ($r) { warn "false\n"; return; }
34 my @act = $_->actions;
35 ((@act ? \@act : ()), $_->all_values);
40 $res = $solver->$last_mode(@last_q);
45 my ($vars, $body) = @_;
46 my @varnames = $split->($vars);
47 return (\@varnames, expand_body($body));
52 local our @Body_Parts;
58 my ($this_mode, undef, undef, undef, $body) = @_;
59 $last_mode = $this_mode;
61 @last_q = expand_body($body);
67 $tcl->CreateCommand('?' => sub { q_command(query => @_) });
68 $tcl->CreateCommand('?!' => sub { q_command(solve => @_) });
69 $tcl->CreateCommand('!?' => sub { q_command(solve => @_) });
70 $tcl->CreateCommand('!' => sub { q_command(ensure => @_) });
72 $tcl->CreateCommand(run => sub {
73 foreach my $ind ($r->independent_actions) {
74 $solver->run_action($ind);
80 $tcl->CreateCommand(dump => sub {
81 my (undef, undef, undef, $to_dump) = @_;
82 my $filter = quote_sub($to_dump);
88 map { $_ =~ /^'(.*)'$/ ? \do { my $x = $1 } : $_ } @args;
92 my (undef, undef, $name, @args) = @_;
93 push our @Body_Parts, [ $name => mangle_args(@args) ];
97 $tcl->CreateCommand(rule => sub {
98 my (undef, undef, undef, $rule, $vars, $body) = @_;
99 $solver->add_rule($rule => expand_def($vars, $body));
100 $tcl->CreateCommand($rule => $rule_sub);
104 foreach my $rule (keys %{$solver->rule_set->rules}) {
106 $tcl->CreateCommand($rule => $rule_sub);
109 $tcl->CreateCommand(foreach => sub {
110 my (undef, undef, undef, $var, $body, $each_body) = @_;
111 push our @Body_Parts, [
112 foreach => $var => map [ expand_body($_) ], $body, $each_body
117 $tcl->CreateCommand(findall => sub {
118 my (undef, undef, undef, $coll_var, $name_var, $body) = @_;
119 push our @Body_Parts, [
120 findall => $coll_var => $name_var => expand_body($body)
125 #$tcl->Eval(q{query D {directory_at D 't'; mode D '0755'; }});
128 $tcl->EvalFile($ARGV[0]);
131 my $rl = Term::ReadLine->new;
135 while (defined(my $line = $rl->readline(length($cmd)?'> ':'$ '))) {
137 if ($tcl->call(info => complete => $cmd)) {
138 unless (eval { $tcl->Eval($cmd); 1 }) {