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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -