如何在Racket中同时做很多不同的事情?

时间:2017-05-17 07:59:02

标签: functional-programming racket

例如,如何在Racket的同一'else'分支中执行三种不同的操作? 喜欢

(if (equal? temp2 #f)
#f
temp2
(vector-set! cache counter temp2)
(set! counter (+ counter 1)))
)

1 个答案:

答案 0 :(得分:3)

将需要在cond块中顺序执行的表达式放在(if <condition> (begin ; consequent exp1 exp2) (begin ; alternative exp3 exp4)) 块中,或使用隐式使用begin块的(cond (<condition> exp1 ; consequent exp2) (else exp3 ; alternative exp4)) 表达式。像这样:

logits_train, volumes = net(images,volumes)
logits_val, v_volumes = net(v_images, v_volumes)

loss_train = some_loss(logits_train,volumes)
train_optimizer = some_optimizer(loss_train)

甚至更简单:

1. sess.run([train_optimizer]) #It uses training data (Dequeues train data)
2. sess.run([logits_val]) #It uses validation data (Dequeues validation data )