Form character return scheme + *

How can I define in schema language this function returning if x>0 + else *

as:

plus_or_muliti(int x) {
    if (x>0) return +;
    else return *;
}

      

I try this and it doesn't work on the racket:

(define (plus_or_multi x)
  (if (>= x 0) + *))

      

i got this error

+: expected a function call, but there is no open parenthesis before this function

      

+3


source to share


2 answers


This code is great for implementing the complete schema (in this case, Racket), but based on the error you are getting, it looks like you are using the initial learners language, one of several languages ​​that the Racket system comes to with. BSL is designed to help avoid some of the common beginner mistakes when using Schema-based languages, and all teaching languages ​​are designed to be used in tandem with How to Build Programs . In fact, several libraries that ship with Racket are in a module htdp

or htdp2

and are extracted from this book, although they can be used for general purpose applications. In the menu DrRacket Language β†’ Choose Language you can select the full language version, which will allow you to use ... the full language.



0


source


Your code is fine.

$ chibi-scheme
> (define (plus_or_multi x)
(if (>= x 0) + *))
> (plus_or_multi 5)
#<opcode "+">
> (plus_or_multi -2)
#<opcode "*">

      



This is not the Schema interpreter you are using.

-2


source







All Articles