Functions and their "return" values
Posted: Fri Sep 18, 2009 3:34 am
I want to port a Perl function that does the following:
So I've come up with:
I'm kinda stuck on returning different values depending on the outcome of the "if" statements. I'm getting mixed up with the syntax for functions with that of "if" statements. Any advice?
Being used to imperative languages, I'm finding a functional language a bit of a challenge --- but fun! TIA..
Code: Select all
sub some_function {
declare a local_var
if (some_test) { do something
return local_var}
if (some_other_test) { return something}
else {return 0}
}
Code: Select all
(define (my_func)
(local (my_var)
(if (= "blah" my_var) (do this))
return_something
)
(if (= "blaah" some_var) (return_something_else))
(if none of the above are true (return nil))
)
Being used to imperative languages, I'm finding a functional language a bit of a challenge --- but fun! TIA..