Comments (4)
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.
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.
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.
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)
- To eval or not to eval HOT 4
- Kernel not found in Mac OS due to issue with libzmq HOT 5
- Error in installation on Windows 10 - HOT 8
- Optionally start the kernel with a trusted sandbox HOT 4
- Can't use with Rosette, seemingly because it can't start subprocesses HOT 2
- Language "deinprogramm": Record definition does not work HOT 2
- Access disallowed by code inspector to protected variable
- Jupyter notebook app failed to restart KernelRestarter
- libzmq-5 not found on Apple M1 silicon HOT 1
- Cannot find jupyter executable HOT 1
- Rendering HTML in cell output HOT 1
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 iracket.