nbtheduke
2021-6-22 14:12:52

hey all, a stack overflow question has me intruiged. is it possible to reference a defined variable inside of a provide block?


nbtheduke
2021-6-22 14:12:57

i’m looking to do (provide (filtered-out (λ (name) (findf (λ (n) (equal? name n)) my-funs)) (all-defined-out)))


nbtheduke
2021-6-22 14:13:16

but i get the error my-funs: unbound identifier


soegaard2
2021-6-22 14:16:26

Does it help to place the definition of my-funs before the provide ?


nbtheduke
2021-6-22 14:16:51

lemme just put the whole snippet in here


nbtheduke
2021-6-22 14:17:15

nbtheduke
2021-6-22 14:18:17

This is useful because I’d be using my-funs elsewhere in the code and I don’t want to have to keep a list of provide calls up to date when I change my-funs


soegaard2
2021-6-22 14:25:33

The my-funs variable needs to be available at compile time. So wrap a begin-for-syntax around it.

#lang racket (require racket/provide) (define (f1 a) (+ a 1)) (define (f2 a) (+ a 2)) (begin-for-syntax (define my-funs '(f1 f2))) (provide (filtered-out (λ (name) (and (member (string->symbol name) my-funs) name)) (all-defined-out)))


samth
2021-6-22 14:25:40

code used in filtered-out is run at expansion time, so if you do (define-for-syntax my-funs ...) it will work


samth
2021-6-22 14:25:48

or what @soegaard2 said


soegaard2
2021-6-22 14:29:44

Oh - and findf is fine to use - I had just forgotten what it did.


nbtheduke
2021-6-22 14:30:49

Awesome thank you


seanbunderwood
2021-6-22 22:55:48

Hi all. Is it possible to package up a DSL so that it can be invoked as a stand-alone utility, without having to explicitly install Racket?


spdegabrielle
2021-6-23 00:12:16

Do you mean create a stand-alone executable that can be called as a command line tool? E.g. mylang -run “test1.mylang”?


seanbunderwood
2021-6-23 00:36:00

Yeah


samth
2021-6-23 01:05:32

Yes, you can create an executable with raco exe and raco distribute.