Avatar
jespada
f57d8cf57ba293a764cd30f3461ce21b0a3849c5c03533391a1074412602f7c9
https://primal.net/jespada

Here's a simple example in Guile Scheme to demonstrate the concept of transducers. Transducers are composable algorithmic transformations that can be applied to sequences without changing how the sequence is processed. This example will show how to create and compose transducers for mapping and filtering operations.

scheme

;; Define a simple transducer for mapping

(define (mapping f)

(lambda (rf)

(lambda (result input)

(rf result (f input)))))

;; Define a simple transducer for filtering

(define (filtering pred)

(lambda (rf)

(lambda (result input)

(if (pred input)

(rf result input)

result))))

;; A simple reducing function that appends to a list

(define (append-to-list result input)

(cons input result))

;; Helper function to reduce a list using a transducer

(define (transduce transducer coll reducer init)

(let* ((rf (transducer reducer))

(result (fold rf init coll)))

result))

;; Example usage

(let* ((numbers (list 1 2 3 4 5 6))

;; Define our transducers

(double (mapping (lambda (x) (* x 2))))

(even (filtering even?))

;; Compose transducers

(composed-transducer (lambda (rf) (even (double rf))))

;; Use transduce to apply our composed transducer

(result (transduce composed-transducer numbers append-to-list '())))

(display result))

Explanation:

Mapping: The mapping transducer takes a function f and returns a new reducing function that applies f to each input before passing it to the original reducer.

Filtering: The filtering transducer takes a predicate pred and only passes inputs that satisfy the predicate to the reducer.

Transduce: This function applies the transducer to each element in the collection, reducing it with the given initial value and reducing function.

When you run this code, it will double each number in the list and then filter for even numbers, resulting in a list of (12 8 4) because 2 * 6 = 12, 2 * 4 = 8, and 2 * 2 = 4 are the only even results from doubling the numbers from 1 to 6.

#lisp #guile

☀️ eyes till 1M ? #bitcoin

The stack IYKYK #bitcoin #red #coldcard

Is this a flex? primal.net/jespada

nostr:nprofile1qqsyvrp9u6p0mfur9dfdru3d853tx9mdjuhkphxuxgfwmryja7zsvhqpzamhxue69uhhv6t5daezumn0wd68yvfwvdhk6tcpz9mhxue69uhkummnw3ezuamfdejj7qgwwaehxw309ahx7uewd3hkctcscpyug I'm trying to use cdn.satellite.earth as media server, tho I paid , I the the error in the pic below, what am I doing wrong ?

nostr:npub1a00wj229auzjswlq4s77y4u8eqdx5k9ppatgl8rtv8va65f6mwksum9q3h should team up with nostr:npub1xsgymm0ne3vndqpvsvy285qfpu59049t5n5twg9vetmt92cyn95snyzazx and have that as default search

#privacy #bluelightdiet

testing my nostr:npub1dd9znw7585wsam4d8p84ztdmtywwjsrayld6fzk4fvqdn5hpju4st5xe7p

nitric oxide(NO) deficiency in the blood vessels of the

genitals is the primary defect in erectile

dysfunction.

So ☀️ your 🥜

nostr:nprofile1qqswhhhf99z77pfg80s2c00z27rusxn2tzss7450n34krkwa2yadhtgpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhkummnw3ezuerkv36zuer9wcq3vamnwvaz7tmpw5h8yetvv9ukzcnvv5hx7un8lpntld I just got my DC-1, thanks 🙏

Btw what are these for ? :