chez-scheme

Why does my lazy filtered list in scheme consume so much memory?

雨燕双飞 提交于 2021-02-10 21:54:10
问题 I'm currently learning to use some slightly more advanced features of scheme, and I've hit a road-block with lazy lists. Basically, I'm trying to create an infinite, lazily generated list, and apply a lazy filter on it, and only take a single element. My hope was that this would consume very little memory: the filter looks at only one element at a time, and there's no need to store the previous entries. Here is my attempt at this: (define lazy-inf-seq (lambda (start next) (delay (cons start

(Chez) Scheme macro for hiding lambdas

廉价感情. 提交于 2020-05-13 14:35:56
问题 I would like to write a macro to create shorthand syntax for hiding more verbose lambda expressions, but I'm struggling to understand how to write macros (which I realize is an argument against using them). Given this example: (define alist-example '((x 1 2 3) (y 4 5 6) (z 7 8 9))) (define ($ alist name) (cdr (assoc name alist))) ((lambda (a) (map (lambda (x y z) (+ x y z)) ($ a 'x) ($ a 'y) ($ a 'z))) alist-example) ((lambda (a) (map (lambda (y) (/ y (apply max ($ a 'y)))) ($ a 'y))) alist

(Chez) Scheme macro for hiding lambdas

社会主义新天地 提交于 2020-05-13 14:34:12
问题 I would like to write a macro to create shorthand syntax for hiding more verbose lambda expressions, but I'm struggling to understand how to write macros (which I realize is an argument against using them). Given this example: (define alist-example '((x 1 2 3) (y 4 5 6) (z 7 8 9))) (define ($ alist name) (cdr (assoc name alist))) ((lambda (a) (map (lambda (x y z) (+ x y z)) ($ a 'x) ($ a 'y) ($ a 'z))) alist-example) ((lambda (a) (map (lambda (y) (/ y (apply max ($ a 'y)))) ($ a 'y))) alist

How to implement asynchronous code that looks synchronous mimicking async / await?

僤鯓⒐⒋嵵緔 提交于 2020-01-16 05:28:10
问题 Otherwise said, I want to rely on epoll (or similar) to write asynchronous network code that looks like regular code that is without relying on callbacks. The code must look like synchronous code but unlike synchronous code instead of blocking to wait for network io, it must suspend the current coroutine and restart it when the file descriptor is ready. 回答1: My initial thought to achieve that was relying on generators and yield . But this was a mistake that was partly mis-guided by the fact