Giter VIP home page Giter VIP logo

Comments (5)

jrincayc avatar jrincayc commented on August 22, 2024 2

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.

jrincayc avatar jrincayc commented on August 22, 2024

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.

jobol avatar jobol commented on August 22, 2024

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.

jrincayc avatar jrincayc commented on August 22, 2024

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.

jobol avatar jobol commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.