问题描述
这是我迄今为止尝试过的,但我遇到了一些错误并且有点困惑
想要做的是:
例如调用 (sub-list((2 3 4 5 6) 2 3)) 将导致像
这样的递归函数x = 1,(sub-list('(3 4 5 6) 2 3))
x = 2,cons (car ls) (sub-list((4 5 6) 2 3))
x = 3,cons (car ls) (sub-list((5 6) 2 3))
x = 4 ,nil 因为 x 现在大于 to。
它应该回溯以返回 (4 5) 类似的东西
image: node:14.15.4
cache:
paths:
- functions/node_modules/
- project_name/node_modules/
before_script:
- npm i -g firebase-tools
.test_and_deploy:
script:
- cd functions
- npm i
- cd ..
- cd project_name
- npm i
- cd ..
- cd functions
- npm run build
- firebase emulators:exec -P project_name --only firestore "npm run test-once"
- cd ..
- cd project_name
- cp .env.project_name.local .env
- npm run build
- firebase --project project_name deploy
解决方法
作为一般建议,不建议使用全局和特殊变量来跟踪内部状态。
正如@coredump 在评论中指出的那样,Sublist in Lisp 有一个指向正确方向的答案。
为了避免特殊变量,您(原则上)可以更改开始和结束索引(如@ScottHunter 所指出的)。
这意味着您可以将“开始累积”从 (<= *x* from)
改为 (<= from 0)
,将“结束累积”改为 (<= to 0)
。
这还需要将每个递归调用更改为类似 (sub-list (cdr list) (1- from) (1- to))
的内容(并消除初始跳过阶段中的错误,您不增加 *x*
)。