SRFI 197: Threading Macros
Arthur A. Gleckler
(09 Jun 2020 03:41 UTC)
|
First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 06:48 UTC)
|
Re: First comments
Linus Björnstam
(09 Jun 2020 07:27 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 08:30 UTC)
|
Re: First comments
Adam Nelson
(09 Jun 2020 13:25 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 14:06 UTC)
|
Re: First comments
Lassi Kortela
(09 Jun 2020 14:12 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 15:28 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 16:05 UTC)
|
Re: First comments
Adam Nelson
(09 Jun 2020 16:15 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 16:22 UTC)
|
Re: First comments
Arne Babenhauserheide
(09 Jun 2020 17:03 UTC)
|
Re: First comments
Adam Nelson
(09 Jun 2020 17:16 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 17:22 UTC)
|
Re: First comments
Lassi Kortela
(09 Jun 2020 17:31 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 17:40 UTC)
|
Re: First comments
Arne Babenhauserheide
(09 Jun 2020 22:19 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(10 Jun 2020 06:16 UTC)
|
Re: First comments
Linus Björnstam
(10 Jun 2020 07:17 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(10 Jun 2020 07:38 UTC)
|
Re: First comments
Linus Björnstam
(10 Jun 2020 08:21 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(10 Jun 2020 08:42 UTC)
|
Re: First comments
Linus Björnstam
(15 Jun 2020 19:50 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(15 Jun 2020 20:09 UTC)
|
Re: First comments
Linus Björnstam
(16 Jun 2020 11:39 UTC)
|
Re: First comments
Arne Babenhauserheide
(10 Jun 2020 07:53 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(10 Jun 2020 08:04 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 17:44 UTC)
|
Re: First comments
Adam Nelson
(09 Jun 2020 17:46 UTC)
|
Re: First comments
Marc Nieper-Wißkirchen
(09 Jun 2020 17:49 UTC)
|
Re: First comments
Arvydas Silanskas
(09 Jun 2020 07:40 UTC)
|
Named procedure; RE: SRFI 197: Threading Macros
Arne Babenhauserheide
(09 Jun 2020 13:40 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Adam Nelson
(09 Jun 2020 13:48 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 14:09 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
hga@xxxxxx
(09 Jun 2020 14:16 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Lassi Kortela
(09 Jun 2020 14:42 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 14:48 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
hga@xxxxxx
(09 Jun 2020 15:10 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 15:25 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Arne Babenhauserheide
(09 Jun 2020 15:47 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 15:58 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Adam Nelson
(09 Jun 2020 16:21 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 16:46 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Adam Nelson
(09 Jun 2020 17:13 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 17:35 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
John Cowan
(11 Jun 2020 00:59 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
hga@xxxxxx
(09 Jun 2020 16:58 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Lassi Kortela
(09 Jun 2020 17:00 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Arne Babenhauserheide
(09 Jun 2020 17:00 UTC)
|
Re: Named procedure; RE: SRFI 197: Threading Macros
Marc Nieper-Wißkirchen
(09 Jun 2020 15:17 UTC)
|
Usecase: chaining operations after "optionals"
Arne Babenhauserheide
(09 Jun 2020 17:18 UTC)
|
Re: Usecase: chaining operations after "optionals"
Adam Nelson
(09 Jun 2020 17:24 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(09 Jun 2020 17:48 UTC)
|
Re: Usecase: chaining operations after "optionals"
Adam Nelson
(09 Jun 2020 17:55 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(09 Jun 2020 19:11 UTC)
|
Re: Usecase: chaining operations after "optionals" Arne Babenhauserheide (09 Jun 2020 22:08 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(10 Jun 2020 06:11 UTC)
|
Re: Usecase: chaining operations after "optionals"
Arne Babenhauserheide
(10 Jun 2020 08:03 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(10 Jun 2020 08:10 UTC)
|
Association list utilities
Lassi Kortela
(10 Jun 2020 08:24 UTC)
|
Re: Association list utilities
Marc Nieper-Wißkirchen
(10 Jun 2020 08:30 UTC)
|
Re: Association list utilities
Lassi Kortela
(10 Jun 2020 08:49 UTC)
|
Re: Association list utilities
Marc Nieper-Wißkirchen
(10 Jun 2020 09:29 UTC)
|
Re: Association list utilities
Lassi Kortela
(10 Jun 2020 09:59 UTC)
|
Re: Association list utilities
Marc Nieper-Wißkirchen
(10 Jun 2020 10:09 UTC)
|
Re: Association list utilities
Lassi Kortela
(10 Jun 2020 10:37 UTC)
|
Re: Association list utilities
Arne Babenhauserheide
(10 Jun 2020 10:33 UTC)
|
Re: Usecase: chaining operations after "optionals"
Arne Babenhauserheide
(10 Jun 2020 09:16 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(10 Jun 2020 09:19 UTC)
|
Re: Usecase: chaining operations after "optionals"
Lassi Kortela
(10 Jun 2020 09:29 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(10 Jun 2020 09:42 UTC)
|
More on association lists (and other key-value collections)
Lassi Kortela
(10 Jun 2020 10:16 UTC)
|
Re: More on association lists (and other key-value collections)
Marc Nieper-Wißkirchen
(10 Jun 2020 10:42 UTC)
|
Re: More on association lists (and other key-value collections)
Arne Babenhauserheide
(11 Jun 2020 00:41 UTC)
|
Re: More on association lists (and other key-value collections)
Marc Nieper-Wißkirchen
(11 Jun 2020 10:07 UTC)
|
Re: Usecase: chaining operations after "optionals"
Arne Babenhauserheide
(10 Jun 2020 10:28 UTC)
|
Re: Usecase: chaining operations after "optionals"
Marc Nieper-Wißkirchen
(10 Jun 2020 10:32 UTC)
|
Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> writes: > Am Di., 9. Juni 2020 um 19:55 Uhr schrieb Adam Nelson <xxxxxx@nels.onl>: > >> (cond ((assoc 'foo '((foo . bar))) => (lambda (x) (symbol->string (cdr >> x)))) (else #f)) >> >> (Not that your examples are all missing a `cdr', I think.) That was my mistake, sorry. >> As we can see, R7RS-small already provides all we need. :) And it's >> even quite idiomatic. >> >> It's also 1.5x as long as the other examples and contains extra structure (`lambda`, `else`) that makes it harder to tell what it's doing at a glance, reinforcing the point that the purpose of threading macros is brevity. Or, in this case, preventing you from needing to write a utility function if you do this several times in a program. > > Without the `cdr', you can drop the lambda and several characters ;) > > Sure, with more procedures it becomes a bit longer. > >> Using the `chain` syntax, and separating more parts of this expression out into the pipeline, it can be made much clearer: >> >> (and-chain '((foo . bar)) (assoc 'foo) (cdr) (symbol->string)) Let’s use the synatx again, but add one more point: receiving the 'foo from somewhere (this is what I often see in Java streams). Please correct me if I got SRFI 2 wrong. SRFI 2: (and-let* ((name (read-name)) (cons-cel (assoc name '((foo . bar)))) (value (cdr cons-cel))) (symbol->string value)) Options: (and=> (read-name) (assoc '((foo . bar))) (cdr) (symbol->string)) (and-chain (read-name) (assoc '((foo . bar))) (cdr) (symbol->string)) (and-chain (read-name) (assoc <> '((foo . bar))) (cdr <>) (symbol->string <>)) (and-bind (read-name) (cut assoc <> '((foo . bar))) (cut cdr <>) (cut symbol->string <>)) > Personally, I would choose `and-let*', which works in all cases > (regardless of the position of the arguments). and-let* looks unexpectedly nice, yes. It is much longer, but explicit. For my most common case (need cdr after assoc), the difference is significantly in favor of the new syntax, though. It would make using assoc-style #f-or-cons-cel returns more usable. For more complex chains, and-let* might actually win, though. Best wishes, Arne -- Unpolitisch sein heißt politisch sein ohne es zu merken