【发布时间】:2014-10-15 21:39:35
【问题描述】:
我目前正在用 Scheme 编写一个小项目来完成一项任务。好久没用Scheme了,语法不强。
问题是在 if 句中使用“and”。我在日历中有一个约会列表,但我只想要那些在某个时间间隔之间的约会。因此,我需要检查开始和结束时间。
我想要实现的在 C# 中看起来像这样:
List<appointment> appointments = new List<appointment>();
foreach (appointment app in calendar) {
if(app.getstart() >= from-time && app.getend() <= to-time) {
appoinments.add(app);
}
}
我目前在 Scheme 中的内容是这样的:
(define (time-calendar cal from-time to-time)
(map (lambda (app)(if (> from-time (send 'getstart app)) #t #f))
(send 'getappointments cal)))
获取日历“cal”和时间间隔(从时间到时间) 然后我从 cal 获取约会(应用程序)并对其进行迭代。对于他们每个人,我检查从时间是否大于“应用程序”的开始时间。相应地返回真或假。这很好用,但我仍然需要考虑约会是否也在“到时间”之前结束。这应该是添加另一个条件的简单问题,但我根本无法让它工作。
谁能帮助我检查第二个变量的正确语法? 我知道Racket documentation,但我仍然无法解决我的问题。
我尝试将 if 语句更改为 cond。
我也尝试了一堆“和”部分的变体,类似于这个,但无法正确语法:
(define (time-calendar cal from-time to-time)
(map (lambda (app)(if (and((> from-time (send 'getstart app))) (< to-time (send 'getend app))) #t #f))
(send 'getappointments cal)))
【问题讨论】:
标签: if-statement scheme conditional-statements racket