
Has general racket got a reduce function? I can only find map and filter.

Somewhere. I often use for/fold instead.

I think there is one in srfi–1.

Ah ok, I was looking for a function called reduce but could only find one in rebellion.

I’ll have a look ay for/fold.


foldl
and foldr
are there in racket/base
alongside for/fold
, in case you haven’t seen them yet

@rokitna I’ll check them out. I’ve used for/list
at the moment.

There’s also for/foldr
which was recently added, in case you need the foldr
variant in the for
form.

I think you want to avoid the with-syntax, but also avoid constructing the submodule at read time

@jestarray append*
will “unwrap one level” if you give it a list as its only/last argument.

Ok, I think I’m seeing how I’m blending reader and expander passes. Is this in the right direction, assuming u/a
refers to the same module?
#lang racket/base
(require (for-syntax racket/base))
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [#%module-begin+ #%module-begin]))
(define-syntax (#%module-begin+ stx)
(syntax-case stx ()
[(_ body ...)
#'(#%module-begin
(require racket/runtime-path
unlike-assets/resolver)
body ...)]))
(module reader racket/base
(provide (rename-out [read+ read]
[read-syntax+ read-syntax]))
(require racket/port
racket/function)
(define (read+ in)
(syntax->datum (read-syntax+ #f in)))
(define (read-syntax+ src in)
#`(module anonymous u/a
. #,(port->list (curry read-syntax src) in))))

(This produces the same error in any case)

; also, no #%app syntax transformer is bound

Thanks again for your patience, sorry if I’m slow.

Continuing from my earlier thread: I gave up on defining a reader submodule for now. I switched to #lang s-exp syntax/module-reader u/a
, where u/a
is a collection path to this module:
#lang racket/base
(require (for-syntax racket/base))
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [#%module-begin+ #%module-begin]))
(define-syntax (#%module-begin+ stx)
(syntax-case stx ()
[(_ body ...)
#'(#%module-begin
(require racket/runtime-path
unlike-assets/resolver)
body ...)]))
The problem now is that #lang u/a (define-runtime-path here ".")
expands define-runtime-path
as a normal procedure application, and the bindings from my inserted requires
are not visible.
What’s my mistake?

Expanding to require rarely works that well, instead you want to provide define-runtime-path from the language module

Yep, that did it. Here’s u/a
for those wondering.
#lang racket/base
(require (for-syntax racket/base)
racket/runtime-path
unlike-assets/resolver)
(provide (all-from-out racket/base)
(all-from-out racket/runtime-path)
(all-from-out unlike-assets/resolver))

Your guidance is really appreciated. I’m guessing I need to re-read the syntax model in the reference.

You cannot use require
in a macro like that, I think. I vaguely recall syntax-local-introduce
solves the problem.


@sorawee Thanks! Check the thread, I just needed to reprovide bindings from the language module.

Oh yeah, Sam’s approach is much better

I’m starting to think that I’m painfully ignorant about scoping rules with syntax objects. Whenever I try defining a new module language or #lang
it’s pretty easy to follow the conventions and piece syntax objects into a template, but the rules under which syntax objects look for a binding elude me.

I know about phases, scope sets, etc, but it’s hard for me to look at an arbitrary syntax object expression and say “oh yeah, that needs a provide
at this spot and a require
at this spot for phase N.”