[Solved] Define a scheme function for infix

This can get really complex quite fast. Consider (1 – 2 * 3). If your calculator only supports addition and negation, this is still not trivial. Consider (5 – 5 – 5). If you consider the input as left associative, you’ll get the correct -5, but if you read it as right associative (which is … Read more

[Solved] What is the equivalence in scheme for ‘if’? [closed]

It depends. You really should try to narrow you question further with an actual problem in scheme since the answer will depend on what you are trying to do. In idiomatic Scheme most should be done without side effects so you have (if predicate-expression consequent-expression alternative-expression) ;; alternative is optional but should be used anyway. … Read more

[Solved] Scheme Rswap function [closed]

Try this: (define (rswap lst) ;; Create a helper function to do the recursive work. (define (helper in out) ;; If the input is not a list, simply return it. ;; There is nothing to be done to rswap it. (if (not (list? in)) in ;; If in is an empty list, simply return the … Read more

[Solved] how to do multiply-all function in RACKET

For the simplest solution, use apply for this: (define (multiply-all lst) (apply * lst)) If you need to build the procedure from scratch, just remember that the base case (an empty list) should return 1, and the recursive step should multiply the current value using the standard solution template, like this: (define (multiply-all lst) (if … Read more

[Solved] how to spell a number in racket? (spellNum) [closed]

EDITED: A complete solution has been posted, so I guess it’s ok for me to show you how to write an idiomatic procedure. Notice that number->list uses a technique called tail recursion for efficiently expressing a loop. Although (coming from a Python background) it might be tempting to use an explicit looping construct (as shown … Read more