存储函数结果的方案(Let) [英] Scheme storing the result of a function (Let)

查看:49
本文介绍了存储函数结果的方案(Let)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(define [DML vara] 
  (cond
     ((atom? (car vara)) 
      (cond
        ((eqan? (car vara) 'N)
         (display (cdr vara)))
        (else (negate vara)))

   )))

为简便起见,我目前正尝试保存返回内容,我正在测试求反函数,它返回"列表,并且我想保存该函数的结果以进行测试.我如何实际保存取反的列表.有点像(x =(求反vara)),其中x是列表.我在Google和堆栈上查找let,但找不到基本的简单作业.

I'm currently trying to save the content of a return right now for simplicity I was testing the negate function it "returns" a list and I wanted to save the result of that function to do testing. How do I actually save the list return from negate. Kind of like (x = (negate vara)) where x is the list. I look up let on google and in stack over flow but I can't find a very simple basic assignment.

请原谅我在方案上的拙劣语法.从命令式语言过渡到功能并不顺利.

Excuse my poor syntax on scheme I'm just starting..and going from imperative language to function isn't so smooth..

我想打印出(negate vara)的结果表达式,但是由于scheme仅打印出了最后一个递归调用"(请原谅我的措辞不好).我希望它使用来自(求和vara)的结果列表,但仍打印出该列表,例如

I wanted to print out the result expression of (negate vara) but since scheme only prints out the last "recursive call" (pardon my bad wording). I wanted it to use the resulting list from (negate vara) but still print out that list like

say if I had 
(else (test (negate vara)))
...
(define (test vara)
(display "test")
)

I wanted it to display 
'(O a b)) ;list
here

推荐答案

您可以按照建议的步骤进行操作:

You could make a procedure like you proposed:

(define (test var)
  (display var)
  var)
(test (negate (test vara)))) ; prints our argument and return

或者您可以使用DrRacket并使用调试器.使用一次后,您将错过它!

Or you could use DrRacket and use the debugger. You'll miss it after using it once!

这篇关于存储函数结果的方案(Let)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆