Discussion:
the FMITE processor
(too old to reply)
B. Pym
2024-07-10 02:37:48 UTC
Permalink
There is no good reason to execute a lambda function after the
parent function has gone out of scope.
The original poster was so ignorant that he knew nothing
whatsoever about Usenet; in fact, he may not have known that
he was posting to Usenet. Consequently, each paragraph in
his post was one gigantic line. I broke his line for him.

In this and other posts he has provided evidence that he
is ignorant about higher-level languages and higher-level
programming concepts. In fact, he has shown that he finds
high-level concepts difficult or impossible to grasp.



(define (make-fib-gen)
(let ((a 1) (b 1))
(lambda ()
(begin0 a
(set!-values (a b) (values b (+ a b)))))))

(define fib0 (make-fib-gen))
(define fib1 (make-fib-gen))

(do ((i 5 (- i 1))) ((zero? i))
(display (fib0)) (display " "))

===>
1 1 2 3 5

(do ((i 6 (- i 1)))
((zero? i))
(display (list (fib0) (fib1)))
(newline))

===>
(8 1)
(13 1)
(21 2)
(34 3)
(55 5)
(89 8)


(define (make-accumulator)
(let ((accum '()))
(lambda xs
(if (null? xs)
(reverse accum)
(set! accum (cons (car xs) accum))))))

(define odds (make-accumulator))
(define evens (make-accumulator))
(define all (make-accumulator))

(do ((i 9 (- i 1)))
((zero? i) (values (all) (odds) (evens)))
(let ((n (fib1)))
((if (odd? n) odds evens) n)
(all n)))

===>
(13 21 34 55 89 144 233 377 610)
(13 21 55 89 233 377)
(34 144 610)

In Forth?
minforth
2024-07-10 10:49:28 UTC
Permalink
MinForth 3.6 (32 bit) (fp matrix)
# m[ 13 21 34 55 89 144 233 377 610 ] ok
# mdup :noname f>s 1 and ; vfilter m. mdrop :noname f>s 1 and 0= ;
vfilter m. mdrop
[ 13 21 55 89 233 377 ]
[ 34 144 610 ] ok
B. Pym
2024-07-22 13:40:07 UTC
Permalink
Post by B. Pym
There is no good reason to execute a lambda function after the
parent function has gone out of scope.
The original poster was so ignorant that he knew nothing
whatsoever about Usenet; in fact, he may not have known that
he was posting to Usenet. Consequently, each paragraph in
his post was one gigantic line. I broke his line for him.
In this and other posts he has provided evidence that he
is ignorant about higher-level languages and higher-level
programming concepts. In fact, he has shown that he finds
high-level concepts difficult or impossible to grasp.
(define (make-fib-gen)
(let ((a 1) (b 1))
(lambda ()
(begin0 a
(set!-values (a b) (values b (+ a b)))))))
(define fib0 (make-fib-gen))
(define fib1 (make-fib-gen))
(do ((i 5 (- i 1))) ((zero? i))
(display (fib0)) (display " "))
===>
1 1 2 3 5
(do ((i 6 (- i 1)))
((zero? i))
(display (list (fib0) (fib1)))
(newline))
===>
(8 1)
(13 1)
(21 2)
(34 3)
(55 5)
(89 8)
(define (make-accumulator)
(let ((accum '()))
(lambda xs
(if (null? xs)
(reverse accum)
(set! accum (cons (car xs) accum))))))
(define odds (make-accumulator))
(define evens (make-accumulator))
(define all (make-accumulator))
(do ((i 9 (- i 1)))
((zero? i) (values (all) (odds) (evens)))
(let ((n (fib1)))
((if (odd? n) odds evens) n)
(all n)))
===>
(13 21 34 55 89 144 233 377 610)
(13 21 55 89 233 377)
(34 144 610)
In Forth?
Gauche Scheme

(use srfi-13) ;; string ops.
(use gauche.generator)

(define (white-space? c) (member c '(#\space #\tab)))

(define (make-token-generator str)
(let ((str str)
(start 0)
(end 0))
(lambda ()
(set! start
(and start end (string-skip str white-space? end)))
(if start
(begin
(set! end (string-index str white-space? start))
(string-copy str start end))
(eof-object)))))

(define (split-on-space str)
(generator->list (make-token-generator str)))

(split-on-space "")
===>
()

(split-on-space " ")
===>
()

(split-on-space "foo")
===>
("foo")

(split-on-space " foo ")
===>
("foo")

(split-on-space " foo bar ")
===>
("foo" "bar")

(split-on-space " 3.14 foo? [bar] ")
===>
("3.14" "foo?" "[bar]")
minforth
2024-07-22 18:12:41 UTC
Permalink
MinForth V3.6 - 32 bit
# : SPLIT-ON-SPACE begin dup while parse-string cr type repeat 2drop ;
ok
# " 314 boo! [bar] " split-on-space
314
boo!
[bar]
ok
#

Loading...