【发布时间】:2016-11-30 05:42:33
【问题描述】:
这只是 Common Lisp 中的凯撒密码,旋转密钥设置为 5。
我有一些限制
必须以列表的形式递归地读取和处理输入。
不允许使用变量、数组、循环、progn。
输出必须是字符串而不是列表。
程序必须只使用递归。
(defun encode (expr) ; define function funcName (argument)
; Out case when the list is empty
(cond ((null expr) nil) ; conditional (test1 action1)
; Checking if the expression is an atom only then to go encryption
((atom expr) (encrot expr)) ; test2 see if one or less atom
; Adding the result of encrot to the list and
(t(cons (encode(car expr)) (encode(cdr expr)))))) ; will run if all others fail
(defun encrot (expr)
; casts the object and then shifts the char by 5
(string (int-char(encrot2 (+ 5 (char-int(char (string expr) 0)))))))
(defun encrot2 (x)
; Checking to see if the atom is a letter
(cond (( > x 90) (+ 64 ( mod x 90 )))
(( < x 91) x)))
我的理解是函数 cons 将列表的元素显示为字符串。例如(“A”“B”“C”)
作为一个字符串,理论上它应该像这样"A B C"。
我使用 GNU CLISP 2.49 (2010-07-07) http://clisp.cons.org/ 编译。
【问题讨论】:
-
你能举个例子吗(输入+输出)?
-
cons没有显示任何内容。它没有做任何输出。cons只是在构造一个 cons 单元格。
标签: string common-lisp clisp