mark.warren
2020-4-16 10:06:44

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


soegaard2
2020-4-16 10:07:10

Somewhere. I often use for/fold instead.


soegaard2
2020-4-16 10:07:18

I think there is one in srfi–1.


mark.warren
2020-4-16 10:08:34

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


mark.warren
2020-4-16 10:08:54

I’ll have a look ay for/fold.



rokitna
2020-4-16 10:56:49

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


mark.warren
2020-4-16 11:02:12

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


sorawee
2020-4-16 11:36:29

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


samth
2020-4-16 11:41:02

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


greg
2020-4-16 13:06:03

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


deactivateduser60718
2020-4-16 19:02:57

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))))


deactivateduser60718
2020-4-16 19:05:06

(This produces the same error in any case)


deactivateduser60718
2020-4-16 19:05:18

; also, no #%app syntax transformer is bound


deactivateduser60718
2020-4-16 19:10:24

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


deactivateduser60718
2020-4-16 21:38:16

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?


samth
2020-4-16 21:48:29

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


deactivateduser60718
2020-4-16 21:55:22

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))


deactivateduser60718
2020-4-16 21:56:20

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


sorawee
2020-4-16 21:58:42

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



deactivateduser60718
2020-4-16 21:59:27

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


sorawee
2020-4-16 22:00:43

Oh yeah, Sam’s approach is much better


deactivateduser60718
2020-4-16 22:03:13

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.


deactivateduser60718
2020-4-16 22:04:07

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.”