Giter Club home page Giter Club logo

Comments (4)

rmculpepper avatar rmculpepper commented on August 22, 2024

If I paste the code above into a Jupyter notebook cell and run it, there are no errors. There is also no output.

from iracket.

kerwinxu avatar kerwinxu commented on August 22, 2024

If I paste the code above into a Jupyter notebook cell and run it, there are no errors. There is also no output.

sorry , i lose the below

(define (integers-starting-from n)
(cons-stream n (integers-starting-from (+ n 1))))

(define integers
(integers-starting-from 1))

;(display-line (stream-ref integers 0))
(let ((x (stream-subseq integers 10000 10010)))
(display-stream x))

(define odd-numbers
(stream-filter odd? integers))

(display-stream (stream-subseq odd-numbers 50 60))

;(let ((x (cons-stream 1 (cons-stream 2 '(3)))))
; (display-stream x))

(define (stream-add s n)
(stream-map (lambda (x)
(+ x n)) s))

(define (add-streams s1 s2)
(stream-map + s1 s2))

(define fib
(cons-stream 1
(cons-stream 1
(add-streams fib
(stream-cdr fib)))))

(display-stream (stream-subseq fib 150 160))

(define (divisible? x y)
(= (remainder x y) 0))

(divisible? 10 2)

(define (sieve stream)
(cons-stream
(stream-car stream)
(sieve (stream-filter
(lambda (x)
(not (divisible? x (stream-car stream))))
(stream-cdr stream)))))

(define primes
(sieve (integers-starting-from 2)))

(display-stream (stream-subseq primes 1000 1010))

from iracket.

rmculpepper avatar rmculpepper commented on August 22, 2024

I haven't run the new example, but I expect you're running into problem called "the top level is hopeless". Here's a smaller example:

(require racket)
;; range : Real Real -> Real
;; compute the length of an interval
(define (range a b) (if (<= a b) (- b a) (range b a)))
(range 5 10) ;; => 5
(range 10 5) ;; => '(5 6 7 8 9)

If you google "racket the top level is hopeless" you should find some discussions. I'm working on an addition to the IRacket docs that warns about this issue. Meanwhile, the best way to avoid it is to avoid redefinitions --- especially, avoid redefining names imported from modules. You can probably do that here by removing (require racket) and requiring the specific modules that you need.

from iracket.

kerwinxu avatar kerwinxu commented on August 22, 2024

I haven't run the new example, but I expect you're running into problem called "the top level is hopeless". Here's a smaller example:

(require racket)
;; range : Real Real -> Real
;; compute the length of an interval
(define (range a b) (if (<= a b) (- b a) (range b a)))
(range 5 10) ;; => 5
(range 10 5) ;; => '(5 6 7 8 9)

If you google "racket the top level is hopeless" you should find some discussions. I'm working on an addition to the IRacket docs that warns about this issue. Meanwhile, the best way to avoid it is to avoid redefinitions --- especially, avoid redefining names imported from modules. You can probably do that here by removing (require racket) and requiring the specific modules that you need.

thank you for you reply .

the problem is Lazy Evaluation .

  • racket : supported by like syntax-rules () , i can run my example work well .
  • iracket : does not supported , i do not know why, the result is, endless loop .

from iracket.

Related Issues (12)

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.