无法理解TCL proc输入
嗨,我正在努力理解别人写的代码的一部分。这是过程的定义:无法理解TCL proc输入,tcl,Tcl,嗨,我正在努力理解别人写的代码的一部分。这是过程的定义: proc defState {state_id attribute object_id value place args} { global state_list state_objs state_attr_vals state_attr_id # Build up record of defined states and perform error checking if {[member $state_id $state_l
proc defState {state_id attribute object_id value place args} {
global state_list state_objs state_attr_vals state_attr_id
# Build up record of defined states and perform error checking
if {[member $state_id $state_list]} {
put-error "ERROR: State $state_id is being defined twice"
#exit-steve
}
set state_list "$state_id $state_list"
if {![info exists state_attr_vals(${object_id},${attribute})]} {
set state_objs($object_id) $place
set state_attr_vals(${object_id},${attribute}) $value
} elseif {[member $value $state_attr_vals(${object_id},${attribute})]} {
put-error "WARNING: Multiple states with same object/attribute/value: $state_id"
} else {
set state_attr_vals(${object_id},${attribute}) \
"$value $state_attr_vals(${object_id},${attribute})"
}
set state_attr_id(${object_id},${attribute},${value}) $state_id
defSteveText $state_id goal "this should be generated by NL"
sp "top-ps*elaborate*state*add-to-current-state*$state_id
(state <s> ^problem-space.name top-ps
^current-state <cs>)
-->
(<cs> ^${state_id} <obj> + &, <n-obj> + &)
(<obj> ^id $state_id ^name $state_id
^type state
^polarity positive
^object-id $object_id
^attribute $attribute
^value $value
^negation <n-obj>)
(<n-obj> ^id $state_id ^name $state_id
^type state
^polarity negative
^object-id $object_id
^attribute $attribute
^value $value
^negation <obj>)"
;##### START TEMP GLUE #########
sp "top-ps*elaborate*state*test*goal*$state_id*positive
(state <s> ^problem-space.name top-ps
^current-state <cs>
^io.input-link.perception <p>
^mental-state <m>)
(<cs> ^${state_id} <pos>)
(<pos> ^polarity positive
^negation <neg>)
($place ^${object_id}_$attribute $value)
-->
(<neg> ^satisfied false + <)
(<pos> ^satisfied true + <)"
sp "top-ps*elaborate*state*test*goal*$state_id*negative
(state <s> ^problem-space.name top-ps
^current-state <cs>
^io.input-link.perception <p>
^mental-state <m>)
(<cs> ^${state_id} <neg>)
(<neg> ^polarity negative
^negation <pos>)
($place ^${object_id}_$attribute \{<val> <> $value <> *unknown* \})
-->
(<pos> ^satisfied false + <)
(<neg> ^satisfied true + <)"
sp "top-ps*elaborate*state*test*goal*$state_id*unknown
(state <s> ^problem-space.name top-ps
^current-state <cs>
^io.input-link.perception <p>
^mental-state <m>)
(<cs> ^${state_id} <neg>)
(<neg> ^polarity negative
^negation <pos>)
($place ^${object_id}_$attribute *unknown*)
-->
(<pos> ^satisfied unknown + <)
(<neg> ^satisfied unknown + <)"
global simulator_name
set sim_state ${object_id}_$attribute
if {[send $simulator_name "memberp ${sim_state} \$SceneAttributes"]} {
#echo "$state_sim already defined"
} else {
send $simulator_name "defSceneAttr $sim_state $sim_state symbol"
}
;##### END TEMP GLUE #########
proc defState{state\u id attribute object\u id value place args}{
全局状态\列表状态\对象状态\属性值状态\属性id
#建立定义状态的记录并执行错误检查
如果{[成员$state\u id$state\u list]}{
放置错误“错误:状态$State\u id被定义了两次”
#退出史蒂夫
}
设置状态列表“$state\u id$state\u list”
如果{![info exists state\u attr\u vals(${object\u id},${attribute})]}{
设置state_objs($object_id)$place
设置状态属性值(${object\u id},${attribute})$value
}elseif{[成员$value$state\u attr\u vals(${object\u id},${attribute})]}{
放置错误“警告:具有相同对象/属性/值的多个状态:$state\u id”
}否则{
设置状态属性值(${object\u id},${attribute})\
$value$state\u attr\u vals(${object\u id},${attribute})
}
设置state_attr_id(${object_id},${attribute},${value})$state_id
defSteveText$state_id目标“这应该由NL生成”
sp“顶级ps*精心制作*状态*添加到当前状态*$state\u id”
(状态^PROJECT-space.name top ps
^(当前状态)
-->
(^${state_id}+&,+&)
(^id$state\u id^name$state\u id)
^类型状态
^极性正
^对象id$object\u id
^属性$attribute
^价值$value
^否定)
(^id$state\u id^name$state\u id)
^类型状态
^极性负
^对象id$object\u id
^属性$attribute
^价值$value
^否定“
#######启动临时胶水#########
sp“顶级ps*精心设计*状态*测试*目标*$state\u id*阳性
(状态^PROJECT-space.name top ps
^现状
^io.input-link.perception
^(精神状态)
(^${state_id})
(^极性正
^否定)
($place^${object_id}{$attribute$value)
-->
(^false+好吧,如果这就是过程的全部内容,那么就没有什么进展了
您正在将一些参数传递给proc
,它接受5个“标准”变量:
state\u id
属性
object\u id
值
place
第一个5个变量之上的任何其他变量都将进入args
调用proc
时,将这些字符串传递到上述变量中:
bird-safe
健康状况
bird
健康
:关注点{{sgt 25.0}}:初始化*未知*:概率0.55:模拟对象*无*
当然,由于$args
是一个列表,如果您枚举这些元素,您将得到它们:
:关注点
{sgt 25.0}
:初始化
*未知*
:概率
0.55
:sim卡对象
*无*
因此,在proc
中,我前面列出的变量中将包含上述字符串。如果在proc
中使用put
,则可以看到这些字符串,结果如下:
puts $state_id ;# gives => bird-safe
puts $attribute ;# gives => health
puts $object_id ;# gives => bird
puts $value ;# gives => healthy
puts $place ;# gives => <p>
puts $args ;# gives => :concerns {{sgt 25.0}} :initialize *unknown* :probability 0.55 :sim-object *none*
将变成这样(我添加了;#^^ ^
以显示替换):
sp“顶级ps*精心制作*状态*测试*目标*鸟类安全*阳性
;# ^^^^^^^^^
(状态^PROJECT-space.name top ps
^现状
^io.input-link.perception
^(精神状态)
(^鸟类安全)
;# ^^^^^^^^^
(^极性正
^否定)
($place^ bird_health health)
;# ^^^^ ^^^^^^ ^^^^^^^
-->
(^false+Hi,我添加了更多的defState代码。过程甚至更长,但我觉得没有必要包含整个过程。我基本上是在试图理解#Temp Glue#下的部分,为此我想看看变量是如何传递到“top ps*精心设计*状态*测试*目标*$state_id*阳性
,这是soar代码的一部分。@Yathi好的,我在我的答案中添加了更多内容:)非常感谢Jerry!我理解它,并且能够运行修改后的代码!:)
puts $state_id ;# gives => bird-safe
puts $attribute ;# gives => health
puts $object_id ;# gives => bird
puts $value ;# gives => healthy
puts $place ;# gives => <p>
puts $args ;# gives => :concerns {{sgt 25.0}} :initialize *unknown* :probability 0.55 :sim-object *none*
sp "top-ps*elaborate*state*test*goal*$state_id*positive
(state <s> ^problem-space.name top-ps
^current-state <cs>
^io.input-link.perception <p>
^mental-state <m>)
(<cs> ^${state_id} <pos>)
(<pos> ^polarity positive
^negation <neg>)
($place ^${object_id}_$attribute $value)
-->
(<neg> ^satisfied false + <)
(<pos> ^satisfied true + <)"
sp "top-ps*elaborate*state*test*goal*bird-safe*positive
;# ^^^^^^^^^
(state <s> ^problem-space.name top-ps
^current-state <cs>
^io.input-link.perception <p>
^mental-state <m>)
(<cs> ^bird-safe <pos>)
;# ^^^^^^^^^
(<pos> ^polarity positive
^negation <neg>)
($place ^bird_health healthy)
;# ^^^^ ^^^^^^ ^^^^^^^
-->
(<neg> ^satisfied false + <)
(<pos> ^satisfied true + <)"