Comments (5)
How about this way to do mutually recursive:
(define a
(lambda (x)
(define b
(lambda (x) (a (- x 1))))
(if (< x 1) 0
(b (- x 1)))))
(a 3)
from r7rs-pico-spec.
I agree that it could be more clear. From the denotational semantics, if "ε ∈ F" is the only case where a variable is defined in the environment of its evaluation for define
.
What kind of code were you thinking of for this?
The following would be an error is R7RS (not necessarily signaled), but by the denotational semantics (assuming I got them the way I wanted) it should result in a
being 4 in Pico Scheme:
(define a (+ 1 1))
(define a (+ a a))
but this is because a define
put a variable in all statements that are after the define in the body.
from r7rs-pico-spec.
In fact I want to know how to define a recursive function? Is it possible using define in a body?
(define doit (lambda (a b c) (if a b (doit (f a b c) (g a b c) (h a b c)))))
The example you gave in the answer is ambiguous. But I understand that the answer is yes.
from r7rs-pico-spec.
Yes, it is possible to do a recursive function anywhere you can use a define. For what it is worth, there is no straight forward way to do mutually recursive functions (a calls b, b calls a). (I think (define a ...) (define b ...) (define a ...) would work but I am not sure I recommend doing that).
I will look at sections 5.2.1 and 5.2.2 and see if I can make some of this more clear in a pull request.
from r7rs-pico-spec.
I agree that mutually recursive function are not straight forward with pr7 and also agree that your trick is ugly.
While checking for how to improve 5.2.1 and 5.2.2, also mentionning the restriction on mutually recursive functions would help.
from r7rs-pico-spec.
Related Issues (14)
- "Tiny Scheme" name already in use HOT 5
- Bottom Scheme HOT 3
- Fix tiedecs in semantics HOT 1
- Check lamda definition
- eqv? instead of eq? HOT 3
- named let HOT 8
- display HOT 5
- include HOT 3
- Consider adding import HOT 7
- improve number specification HOT 10
- non hygienic rewrite for or HOT 1
- Should `(display <identifier>)` be `(display <expression>)`? HOT 1
- Add (features)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r7rs-pico-spec.