What is the “return” in scheme?
up vote
2
down vote
favorite
I am trying to translate some python code to scheme.
def test(x):
if x > 1:
do something
if x > 10:
return
if x == 4:
do something
test(11)
I did not find the "return" in scheme. I want to quit from the test function when x >10.
How can I simulate the "return" in scheme?
(I am using guile)
Thanks
scheme
add a comment |
up vote
2
down vote
favorite
I am trying to translate some python code to scheme.
def test(x):
if x > 1:
do something
if x > 10:
return
if x == 4:
do something
test(11)
I did not find the "return" in scheme. I want to quit from the test function when x >10.
How can I simulate the "return" in scheme?
(I am using guile)
Thanks
scheme
So in your exampledo something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.
– Sylwester
Apr 28 '14 at 22:41
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to translate some python code to scheme.
def test(x):
if x > 1:
do something
if x > 10:
return
if x == 4:
do something
test(11)
I did not find the "return" in scheme. I want to quit from the test function when x >10.
How can I simulate the "return" in scheme?
(I am using guile)
Thanks
scheme
I am trying to translate some python code to scheme.
def test(x):
if x > 1:
do something
if x > 10:
return
if x == 4:
do something
test(11)
I did not find the "return" in scheme. I want to quit from the test function when x >10.
How can I simulate the "return" in scheme?
(I am using guile)
Thanks
scheme
scheme
edited Apr 27 '14 at 19:31
asked Apr 27 '14 at 19:24
scot
1613
1613
So in your exampledo something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.
– Sylwester
Apr 28 '14 at 22:41
add a comment |
So in your exampledo something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.
– Sylwester
Apr 28 '14 at 22:41
So in your example
do something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.– Sylwester
Apr 28 '14 at 22:41
So in your example
do something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.– Sylwester
Apr 28 '14 at 22:41
add a comment |
5 Answers
5
active
oldest
votes
up vote
2
down vote
In Scheme there isn't an explicit return
keyword - it's a lot simpler than that, the value of the last expression in a sequence of expressions is the one that gets returned. For example, your Python code will translate to this, and notice that the (> x 10)
case had to be moved to the bottom, so if it's true it can exit the function immediately with a #f
value.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something))
(if (> x 10)
#f))
(test 11)
=> #f
In fact, after reordering the conditions we can remove the last one, but beware: an unspecified value will be returned if x
is not 4
, according to Guile's documentation - in other words, you should always return a value in each case, and an if
expression should have both consequent and alternative parts.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something)))
(test 11)
=> unspecified
And by the way, I believe the logic in the Python code is a bit off. The first condition will always be evaluated whenever a value of x
greater than 1
is passed, but if it is less than or equal to 1
the returned value in Python will be None
and in Scheme is unspecified. Also the original function isn't explicitly returning a value - in Python this means that None
will be returned, in Scheme the returned value will be either (do-something)
if x
happens to be 4
, or unspecified in any other case.
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
A more faithful translation would be(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, sinceif (x) return; {block}
is equivalent toif (!x) {block}
.
– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could usecall/cc
here for an escape continuation :)
– leppie
Apr 28 '14 at 5:01
add a comment |
up vote
2
down vote
In Racket the most literal translation is:
#lang racket
(define (test x)
(let/ec return
(when (> x 1)
(do-something))
(when (> x 10)
(return 42))
(when (= x 4)
(do-something))))
(define (do-something)
(display "!"))
(test 11)
The let/ec
is short for let/escape-continuation. Look up the equivalent control structure in the manual for your Scheme implementation of choice.
The example displays one ! and then returns 42.
It is a Scheme question, not a Racket question. How difficult is it to replacelet/ec
withcall/cc
to help the OP directly?
– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
add a comment |
up vote
1
down vote
The implicit return
of Scheme can be illustrated by comparing how you can implement a simple function, such as square
, in Python and scheme.
In Python:
def square(x):
return x*x;
In Scheme:
(define (square x)
(* x x))
add a comment |
up vote
1
down vote
As others have said, the last expression's value in a function is its return value, so you just have to arrange for exclusive execution pathways in your code, to achieve this effect.
(if <test> <consequent> <alternative>)
is the basic branching operation in Scheme:
(define (test x)
(if (> x 1)
(do_something)
#f)
(if (> x 10)
#f ; return #f
;; else:
(if (= x 4)
(do_something)
;; else:
#f)))
(test 11)
Or we could use cond
to avoid the needlessly nested structure in the code:
(define (test x)
(if (> x 1)
(do_something)
#f)
(cond
( (> x 10) #f)
( (= x 4) (do_something))
( else #f)))
add a comment |
up vote
0
down vote
You may use call/cc
(define (test x) (call/cc (lambda (k)
(if x
(k x)
(k))
(display "never displayed"))))
> (test 3)
3
> (test #f)
>
You can return no value using (k)
.
Read about Continuations.
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
In Scheme there isn't an explicit return
keyword - it's a lot simpler than that, the value of the last expression in a sequence of expressions is the one that gets returned. For example, your Python code will translate to this, and notice that the (> x 10)
case had to be moved to the bottom, so if it's true it can exit the function immediately with a #f
value.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something))
(if (> x 10)
#f))
(test 11)
=> #f
In fact, after reordering the conditions we can remove the last one, but beware: an unspecified value will be returned if x
is not 4
, according to Guile's documentation - in other words, you should always return a value in each case, and an if
expression should have both consequent and alternative parts.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something)))
(test 11)
=> unspecified
And by the way, I believe the logic in the Python code is a bit off. The first condition will always be evaluated whenever a value of x
greater than 1
is passed, but if it is less than or equal to 1
the returned value in Python will be None
and in Scheme is unspecified. Also the original function isn't explicitly returning a value - in Python this means that None
will be returned, in Scheme the returned value will be either (do-something)
if x
happens to be 4
, or unspecified in any other case.
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
A more faithful translation would be(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, sinceif (x) return; {block}
is equivalent toif (!x) {block}
.
– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could usecall/cc
here for an escape continuation :)
– leppie
Apr 28 '14 at 5:01
add a comment |
up vote
2
down vote
In Scheme there isn't an explicit return
keyword - it's a lot simpler than that, the value of the last expression in a sequence of expressions is the one that gets returned. For example, your Python code will translate to this, and notice that the (> x 10)
case had to be moved to the bottom, so if it's true it can exit the function immediately with a #f
value.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something))
(if (> x 10)
#f))
(test 11)
=> #f
In fact, after reordering the conditions we can remove the last one, but beware: an unspecified value will be returned if x
is not 4
, according to Guile's documentation - in other words, you should always return a value in each case, and an if
expression should have both consequent and alternative parts.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something)))
(test 11)
=> unspecified
And by the way, I believe the logic in the Python code is a bit off. The first condition will always be evaluated whenever a value of x
greater than 1
is passed, but if it is less than or equal to 1
the returned value in Python will be None
and in Scheme is unspecified. Also the original function isn't explicitly returning a value - in Python this means that None
will be returned, in Scheme the returned value will be either (do-something)
if x
happens to be 4
, or unspecified in any other case.
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
A more faithful translation would be(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, sinceif (x) return; {block}
is equivalent toif (!x) {block}
.
– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could usecall/cc
here for an escape continuation :)
– leppie
Apr 28 '14 at 5:01
add a comment |
up vote
2
down vote
up vote
2
down vote
In Scheme there isn't an explicit return
keyword - it's a lot simpler than that, the value of the last expression in a sequence of expressions is the one that gets returned. For example, your Python code will translate to this, and notice that the (> x 10)
case had to be moved to the bottom, so if it's true it can exit the function immediately with a #f
value.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something))
(if (> x 10)
#f))
(test 11)
=> #f
In fact, after reordering the conditions we can remove the last one, but beware: an unspecified value will be returned if x
is not 4
, according to Guile's documentation - in other words, you should always return a value in each case, and an if
expression should have both consequent and alternative parts.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something)))
(test 11)
=> unspecified
And by the way, I believe the logic in the Python code is a bit off. The first condition will always be evaluated whenever a value of x
greater than 1
is passed, but if it is less than or equal to 1
the returned value in Python will be None
and in Scheme is unspecified. Also the original function isn't explicitly returning a value - in Python this means that None
will be returned, in Scheme the returned value will be either (do-something)
if x
happens to be 4
, or unspecified in any other case.
In Scheme there isn't an explicit return
keyword - it's a lot simpler than that, the value of the last expression in a sequence of expressions is the one that gets returned. For example, your Python code will translate to this, and notice that the (> x 10)
case had to be moved to the bottom, so if it's true it can exit the function immediately with a #f
value.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something))
(if (> x 10)
#f))
(test 11)
=> #f
In fact, after reordering the conditions we can remove the last one, but beware: an unspecified value will be returned if x
is not 4
, according to Guile's documentation - in other words, you should always return a value in each case, and an if
expression should have both consequent and alternative parts.
(define (test x)
(if (> x 1)
(do-something))
(if (= x 4)
(do-something)))
(test 11)
=> unspecified
And by the way, I believe the logic in the Python code is a bit off. The first condition will always be evaluated whenever a value of x
greater than 1
is passed, but if it is less than or equal to 1
the returned value in Python will be None
and in Scheme is unspecified. Also the original function isn't explicitly returning a value - in Python this means that None
will be returned, in Scheme the returned value will be either (do-something)
if x
happens to be 4
, or unspecified in any other case.
edited Apr 28 '14 at 1:01
answered Apr 27 '14 at 19:36
Óscar López
173k22223318
173k22223318
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
A more faithful translation would be(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, sinceif (x) return; {block}
is equivalent toif (!x) {block}
.
– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could usecall/cc
here for an escape continuation :)
– leppie
Apr 28 '14 at 5:01
add a comment |
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
A more faithful translation would be(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, sinceif (x) return; {block}
is equivalent toif (!x) {block}
.
– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could usecall/cc
here for an escape continuation :)
– leppie
Apr 28 '14 at 5:01
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
This isn't really a faithful translation of the python code, which would have performed the actions for part 1 and 2.
– amalloy
Apr 27 '14 at 23:42
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
@amalloy you're right, I updated my answer with a direct translation
– Óscar López
Apr 28 '14 at 0:25
1
1
A more faithful translation would be
(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, since if (x) return; {block}
is equivalent to if (!x) {block}
.– Adam Rosenfield
Apr 28 '14 at 0:29
A more faithful translation would be
(define (test x) (if (> x 1) (do-something)) (if (not (> x 10)) (if (= x 4) (do-something))))
, since if (x) return; {block}
is equivalent to if (!x) {block}
.– Adam Rosenfield
Apr 28 '14 at 0:29
@amalloy: Well, you could use
call/cc
here for an escape continuation :)– leppie
Apr 28 '14 at 5:01
@amalloy: Well, you could use
call/cc
here for an escape continuation :)– leppie
Apr 28 '14 at 5:01
add a comment |
up vote
2
down vote
In Racket the most literal translation is:
#lang racket
(define (test x)
(let/ec return
(when (> x 1)
(do-something))
(when (> x 10)
(return 42))
(when (= x 4)
(do-something))))
(define (do-something)
(display "!"))
(test 11)
The let/ec
is short for let/escape-continuation. Look up the equivalent control structure in the manual for your Scheme implementation of choice.
The example displays one ! and then returns 42.
It is a Scheme question, not a Racket question. How difficult is it to replacelet/ec
withcall/cc
to help the OP directly?
– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
add a comment |
up vote
2
down vote
In Racket the most literal translation is:
#lang racket
(define (test x)
(let/ec return
(when (> x 1)
(do-something))
(when (> x 10)
(return 42))
(when (= x 4)
(do-something))))
(define (do-something)
(display "!"))
(test 11)
The let/ec
is short for let/escape-continuation. Look up the equivalent control structure in the manual for your Scheme implementation of choice.
The example displays one ! and then returns 42.
It is a Scheme question, not a Racket question. How difficult is it to replacelet/ec
withcall/cc
to help the OP directly?
– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
add a comment |
up vote
2
down vote
up vote
2
down vote
In Racket the most literal translation is:
#lang racket
(define (test x)
(let/ec return
(when (> x 1)
(do-something))
(when (> x 10)
(return 42))
(when (= x 4)
(do-something))))
(define (do-something)
(display "!"))
(test 11)
The let/ec
is short for let/escape-continuation. Look up the equivalent control structure in the manual for your Scheme implementation of choice.
The example displays one ! and then returns 42.
In Racket the most literal translation is:
#lang racket
(define (test x)
(let/ec return
(when (> x 1)
(do-something))
(when (> x 10)
(return 42))
(when (= x 4)
(do-something))))
(define (do-something)
(display "!"))
(test 11)
The let/ec
is short for let/escape-continuation. Look up the equivalent control structure in the manual for your Scheme implementation of choice.
The example displays one ! and then returns 42.
answered Apr 28 '14 at 9:00
soegaard
23.7k43774
23.7k43774
It is a Scheme question, not a Racket question. How difficult is it to replacelet/ec
withcall/cc
to help the OP directly?
– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
add a comment |
It is a Scheme question, not a Racket question. How difficult is it to replacelet/ec
withcall/cc
to help the OP directly?
– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
It is a Scheme question, not a Racket question. How difficult is it to replace
let/ec
with call/cc
to help the OP directly?– GoZoner
Apr 28 '14 at 22:28
It is a Scheme question, not a Racket question. How difficult is it to replace
let/ec
with call/cc
to help the OP directly?– GoZoner
Apr 28 '14 at 22:28
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
As far as I knwow Guile also has let/ec.
– soegaard
Apr 29 '14 at 16:21
add a comment |
up vote
1
down vote
The implicit return
of Scheme can be illustrated by comparing how you can implement a simple function, such as square
, in Python and scheme.
In Python:
def square(x):
return x*x;
In Scheme:
(define (square x)
(* x x))
add a comment |
up vote
1
down vote
The implicit return
of Scheme can be illustrated by comparing how you can implement a simple function, such as square
, in Python and scheme.
In Python:
def square(x):
return x*x;
In Scheme:
(define (square x)
(* x x))
add a comment |
up vote
1
down vote
up vote
1
down vote
The implicit return
of Scheme can be illustrated by comparing how you can implement a simple function, such as square
, in Python and scheme.
In Python:
def square(x):
return x*x;
In Scheme:
(define (square x)
(* x x))
The implicit return
of Scheme can be illustrated by comparing how you can implement a simple function, such as square
, in Python and scheme.
In Python:
def square(x):
return x*x;
In Scheme:
(define (square x)
(* x x))
answered Apr 28 '14 at 4:50
R Sahu
163k1291184
163k1291184
add a comment |
add a comment |
up vote
1
down vote
As others have said, the last expression's value in a function is its return value, so you just have to arrange for exclusive execution pathways in your code, to achieve this effect.
(if <test> <consequent> <alternative>)
is the basic branching operation in Scheme:
(define (test x)
(if (> x 1)
(do_something)
#f)
(if (> x 10)
#f ; return #f
;; else:
(if (= x 4)
(do_something)
;; else:
#f)))
(test 11)
Or we could use cond
to avoid the needlessly nested structure in the code:
(define (test x)
(if (> x 1)
(do_something)
#f)
(cond
( (> x 10) #f)
( (= x 4) (do_something))
( else #f)))
add a comment |
up vote
1
down vote
As others have said, the last expression's value in a function is its return value, so you just have to arrange for exclusive execution pathways in your code, to achieve this effect.
(if <test> <consequent> <alternative>)
is the basic branching operation in Scheme:
(define (test x)
(if (> x 1)
(do_something)
#f)
(if (> x 10)
#f ; return #f
;; else:
(if (= x 4)
(do_something)
;; else:
#f)))
(test 11)
Or we could use cond
to avoid the needlessly nested structure in the code:
(define (test x)
(if (> x 1)
(do_something)
#f)
(cond
( (> x 10) #f)
( (= x 4) (do_something))
( else #f)))
add a comment |
up vote
1
down vote
up vote
1
down vote
As others have said, the last expression's value in a function is its return value, so you just have to arrange for exclusive execution pathways in your code, to achieve this effect.
(if <test> <consequent> <alternative>)
is the basic branching operation in Scheme:
(define (test x)
(if (> x 1)
(do_something)
#f)
(if (> x 10)
#f ; return #f
;; else:
(if (= x 4)
(do_something)
;; else:
#f)))
(test 11)
Or we could use cond
to avoid the needlessly nested structure in the code:
(define (test x)
(if (> x 1)
(do_something)
#f)
(cond
( (> x 10) #f)
( (= x 4) (do_something))
( else #f)))
As others have said, the last expression's value in a function is its return value, so you just have to arrange for exclusive execution pathways in your code, to achieve this effect.
(if <test> <consequent> <alternative>)
is the basic branching operation in Scheme:
(define (test x)
(if (> x 1)
(do_something)
#f)
(if (> x 10)
#f ; return #f
;; else:
(if (= x 4)
(do_something)
;; else:
#f)))
(test 11)
Or we could use cond
to avoid the needlessly nested structure in the code:
(define (test x)
(if (> x 1)
(do_something)
#f)
(cond
( (> x 10) #f)
( (= x 4) (do_something))
( else #f)))
answered Apr 29 '14 at 18:29
Will Ness
42.2k467118
42.2k467118
add a comment |
add a comment |
up vote
0
down vote
You may use call/cc
(define (test x) (call/cc (lambda (k)
(if x
(k x)
(k))
(display "never displayed"))))
> (test 3)
3
> (test #f)
>
You can return no value using (k)
.
Read about Continuations.
add a comment |
up vote
0
down vote
You may use call/cc
(define (test x) (call/cc (lambda (k)
(if x
(k x)
(k))
(display "never displayed"))))
> (test 3)
3
> (test #f)
>
You can return no value using (k)
.
Read about Continuations.
add a comment |
up vote
0
down vote
up vote
0
down vote
You may use call/cc
(define (test x) (call/cc (lambda (k)
(if x
(k x)
(k))
(display "never displayed"))))
> (test 3)
3
> (test #f)
>
You can return no value using (k)
.
Read about Continuations.
You may use call/cc
(define (test x) (call/cc (lambda (k)
(if x
(k x)
(k))
(display "never displayed"))))
> (test 3)
3
> (test #f)
>
You can return no value using (k)
.
Read about Continuations.
edited Nov 19 at 7:03
Will Ness
42.2k467118
42.2k467118
answered Mar 9 '15 at 5:06
Karl Lee
1
1
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23327911%2fwhat-is-the-return-in-scheme%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So in your example
do something
does something that result in a side effect? Perhaps if you said what the function was suppose to do we could make a more idiomatic Scheme version for you to look at. The answers so far try to mimic you code and is pretty bad Scheme.– Sylwester
Apr 28 '14 at 22:41