racket - Using cons, list, append in Scheme -
i need write code take element , add list give input, , return new list instead of old list.. after recurssion , need new list... below code working fine.. try reduce set! because confuse me , sometime take error cannot solve..
how can operation without set! ? try cons, list , append none of them job.
(set! list (cons element list))
thank you..
just (cons element list)
enough.
your code altering contents of list
variable. don't that, in functional style, , way use set!
did.
but return new list, has new element on top of it, call (cons element list)
enough:
... (let ((newlist (cons element oldlist))) ..... ..... use newlist , oldlist needed
Comments
Post a Comment