代码之家  ›  专栏  ›  技术社区  ›  S. L.

Postscript测试条件

  •  0
  • S. L.  · 技术社区  · 6 年前

    input encrypt test
    

    其中输入是字符串,encrypt是(我假设)函数,test是(我再次假设)字符串。我对postscript完全不熟悉,但上面的语法是否等同于:

    if encrypt(input) == test:
        return True
    

    谢谢

    2 回复  |  直到 6 年前
        1
  •  0
  •   cdlane    6 年前

    因为没有 input encrypt ,或 test 是PostScript内置的命令,人们无法确定它们是做什么的。考虑到语言的工作方式,以及你的断言 输入 是一个字符串,类似Python的等价物的一些可能性是:

    test(encrypt(input))  % test and encrypt are functions of one argument
    
    test(encrypt, input)  % encrypt is a function with no arguments
    
    encrypt(input); test()  % encrypt returns nothing
    
    encrypt(); test(input)  % encrypt() takes no arguments, returns no values
    
    encrypt(input); next_fn(test)
    
    etc.
    

    但我不明白这是怎么回事:

    if encrypt(input) == test:
    

    给定PostScript基于堆栈的语法,除非序列中还有其他内容:

    input encrypt test eq
    

    然后它可以评估为:

    eq(test, encrypt(input))
    

    符合你的结论。但是自从 eq

        2
  •  0
  •   S. L.    6 年前

    是的,是的。通过调试发现,但可能对其他人有用。

    编辑澄清:就我而言 encrypt test 接受一个字符串作为输入并返回一个布尔值,因此它在我的情况下工作。