我试图从方案中的字符串列表中获取随机字符串.示例列表("this""that""today""yesterday")因此,基于列表的长度,创建随机数并输出该字.但不断收到错误!
我试过这样的:
;; produces random number that should be input to the random-function
(define (random-num list)
(random-function ((random (length (list))) list)))
;; loops the number of times till random number is 0 and outputs the list value
(define (random-function num list )
(cond
[(zero? num) (car list)]
[else (random-function (- num 1) (cdr list))]))
Run Code Online (Sandbox Code Playgroud)
错误:
procedure application: expected procedure, given:
("this" "that" "today" "yesterday") (no arguments)
Run Code Online (Sandbox Code Playgroud)
当我尝试做的时候:
(random-function (random (length list))
Run Code Online (Sandbox Code Playgroud)
在控制台上我得到一个随机数.
在我的程序里完成时,不明白为什么它会崩溃?
我能以更好的方式做到这一点,而不是循环这么多次.在Java中,我会使用一个数组并直接给出位置.无论如何也要在计划中做到这一点?
我在定义一个与Racket中的拉链功能相同的功能时遇到了麻烦.到目前为止我有这个:
(define (zipper lst1 lst2)
(match* [lst1 lst2]
[{'()'()} '()]
[{(cons hd1 tl1) (cons hd2 tl2)}
(cons (list hd1 d2)
(zipper tl1 tl2))]))
Run Code Online (Sandbox Code Playgroud)
谁能解释我在哪里出错了.我希望它看起来像这样:
> (zipper '(1 2 3 4) '(a b c d))
'((1 a) (2 b) (3 c) (4 d))
Run Code Online (Sandbox Code Playgroud) 所以我正在编写一个bash shell脚本,我的前几行看起来像这样:
if ! [ $# -eq 0 || $# -eq 1 ]; then
echo -e "Usage: myScriptName [\e[3mdir\e[0m] [\e[3m-f file\e[0m]"
exit 1
fi
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它会说"[:missing`]'".我没有看到失踪,除了; 正在触动],所以我错过了什么?
我收到此编译错误:
main.cpp:34:74: error: cannot allocate an object of abstract type ‘HouseClass’
mapEntVec.push_back(new HouseClass(PixelLocationClass(120, 220), 100000));
^
In file included from main.cpp:2:0:
HouseClass.h:17:7: note: because the following virtual functions are pure within ‘HouseClass’:
class HouseClass:public RectangularEntityClass
^
In file included from HouseClass.h:8:0,
from main.cpp:2:
RectangularEntityClass.h:18:20: note: virtual std::string RectangularEntityClass::getType() const
virtual string getType() const = 0;
^
RectangularEntityClass.h:19:17: note: virtual int RectangularEntityClass::getNumRows() const
virtual int getNumRows() const = 0;
^
RectangularEntityClass.h:20:17: note: virtual int RectangularEntityClass::getNumCols() const
virtual int getNumCols() const = …Run Code Online (Sandbox Code Playgroud)