laurent.orseau
2021-1-4 09:07:43

@greg Excellent, thanks for the pointers!


laurent.orseau
2021-1-4 09:10:33

So the solution is to create a submodule and export (define rkt-define @racket[define]) , that makes sense.


soegaard2
2021-1-4 09:14:01

And then, in your document: @(begin-for-syntax (define rkt:define (make-element-id-transformer (lambda (stx) rkt-define)))) will make the substitution happen automatically.


laurent.orseau
2021-1-4 09:17:43

@soegaard2 I don’t see what you mean. Currently I’m using: @(module def-racket racket/base (require scribble/manual (for-label racket/base)) (define rkt-define @racket[define]) (define rkt-lambda @racket[lambda]) (provide (all-defined-out))) @(require 'def-racket) .... Like @\|rkt-define\| from @racketmodname[racket/base]... which does the trick


soegaard2
2021-1-4 09:19:03

If you use the element-id-transformer, then @racket[rkt:define] will render to the value of @racket[define]. The substitution also happens with racketblock, racketcode etc.


laurent.orseau
2021-1-4 09:20:19

Oh good, thanks. I won’t need that though, but that’s useful to know


pihentagy
2021-1-4 10:06:09

but I have my numbers available as a list (sorry, have just found there is also a #beginners channel)


laurent.orseau
2021-1-4 11:30:59

@notjack write an issue for Rhombus?


notjack
2021-1-4 11:32:53

@laurent.orseau working on a prototype first, I think I need an example to illustrate it well


laurent.orseau
2021-1-4 11:34:47

Can’t wait to see the result :slightly_smiling_face:


popa.bogdanp
2021-1-4 12:42:44

When embedding CS, can I rely on ptrs to Racket functions (retrieved using racket_dynamic_require) to remain static between GCs? The docs mention that Racket values should not be retained between calls to racket_*, but I think this wouldn’t necessarily be true for code. When I use racket_dynamic_require to require a top-level function from a module, do I get back a function pointer or some kind of intermediate value which might get moved?


popa.bogdanp
2021-1-4 12:43:46

To give a concrete example of what I’m doing: https://gist.github.com/Bogdanp/49aac3f4cc4b727323b58c60e105a601\|this seems to work just fine, but I’m wondering if it’ll come back to bite me.


popa.bogdanp
2021-1-4 12:48:21

The intent here being to avoid performing a namespace lookup and the associated allocations inside a tight loop.



popa.bogdanp
2021-1-4 12:59:41

Answering my own question: the app crashed after a while due to a bad memory access so the answer is probably “no”. Is there a better way to refer to functions from a module from C?


mflatt
2021-1-4 13:00:39

As you say, functions generally will not stay in place. You can use lock-object or Slock_object from the Chez Scheme layer to keep it in place.


popa.bogdanp
2021-1-4 13:01:54

Thanks! I’ll try using Slock_object.


laurent.orseau
2021-1-4 13:22:57

Nice. The decorators are mostly tags for now, right? How do you intend them to be used for transforming code?


gknauth
2021-1-4 13:26:31

No worries, everyone’s friendly in the Racket community. The language is great, the people are great.


notjack
2021-1-4 14:01:10

Basically, it depends on what kind of thing you’re decorating. Definitions will support one kind of transformation, structs a different kind, submodules another kind, etc. User macros (like rebellion’s type definition macros in rebellion/type, for example) can implement support for their own kinds of transformations by expanding to #%decoratable-form.


notjack
2021-1-4 14:01:27

Just pushed an implementation of definition decorators https://github.com/jackfirth/decorator/blob/master/main.rkt


notjack
2021-1-4 14:02:08

Example usage: ;; This is a (non-syntax) definition decorator. Definition decorators are macros that receive the list ;; of identifiers to define, and the body expression that produces their values. They expand to a ;; replacement body expression. This definition decorator prints the defined values when the ;; definition is evaluated. (define-simple-macro (@print (id ...) expression) #:with (result ...) (generate-temporaries #'(id ...)) (let-values ([(result ...) expression]) (printf "~a = ~a\n" 'id result) ... (values result ...))) (decorating-block ;; Prints a = 1 (decorate @print) (define a 1) ;; Prints b = 2 (decorate @print) (define b 2) ;; Prints c = 3 (decorate @print) (define c 3) ;; Prints: ;; d = 4 ;; e = 5 ;; f = 6 (decorate @print) (define-values (d e f) (values 4 5 6)))


laurent.orseau
2021-1-4 15:39:01

I see, thanks. That’s a pretty good start!


samdphillips
2021-1-4 17:26:56

Could you do something that runs ffi-callback on the Racket side and save that pointer on the C-side?


laurent.orseau
2021-1-4 18:37:10

In the following code, how do I make sure the error location is call site of foo (or better the s-exp (error ...)) instead of ../../../../../usr/share/racket-7.9.0.9/pkgs/drracket/drracket/private/stack-checkpoint.rkt:115:30: stop? #lang racket (require syntax/parse/define) (define-syntax-parser foo [(foo body ...) #'(let () body ...)]) (foo (error "stop")) I tried various combinations of #:contex and syntax/loc without success


sorawee
2021-1-4 18:38:44

Are you using errortrace?


laurent.orseau
2021-1-4 18:39:16

I was not :face_palm:


laurent.orseau
2021-1-4 18:39:21

Thanks! :slightly_smiling_face:


sorawee
2021-1-4 18:41:58

Well, I think it should work without errortrace enabled


sorawee
2021-1-4 18:42:28

laurent.orseau
2021-1-4 18:48:37

That would be good indeed but there’s a tradeoff between debugging and speed which I’m ready to accept.


sorawee
2021-1-4 18:55:22

I meant, it probably works with errortrace disabled if you use Racket BC


sorawee
2021-1-4 18:55:34

The fact that it doesn’t work for you is due to Racket CS bug


ben.knoble
2021-1-4 21:05:01

I was looking for an idiom make stuff like (cond [test-expr #f] ...) more palatable, and I like (cond [test-expr => not] ...) , but I wonder if there are others?


me1890
2021-1-4 21:19:00

(and (not test-expr) (cond ...)) maybe?


soegaard2
2021-1-4 21:38:44

@ben.knoble Perhaps and-let* from srfi 2 ? https://docs.racket-lang.org/srfi/srfi-std/srfi-2.html


soegaard2
2021-1-4 21:40:16

I haven’t seen it used much. The cond solution seems more popular. Alternatively, use match: (match test-expr [#f <handle-false>] [x <handle-non-false>])


soegaard2
2021-1-4 21:40:30

I like the match solution.


notjack
2021-1-4 21:56:46

The guarded-block macro I made a while ago would work for that


soegaard2
2021-1-4 22:23:20

Is stat-template short for “static template” ?


ben
2021-1-5 01:29:22

What’s a good way to communicate between racket programs and DrRacket plug-ins (“tools”)? (ping @leif and @florence, in case you have ideas)


ben
2021-1-5 01:30:19

I’m asking on behalf of the Forge devs. at Brown https://pkgs.racket-lang.org/package/forge


dan
2021-1-5 01:36:02

I think via syntax properties is the pretty standard way, but I guess it depends a little on what kind of tool you’re writing


ben
2021-1-5 01:38:58

ah! well that’s much better than a logger


notjack
2021-1-5 02:05:10

If you want to communicate information about expressions, use syntax properties. If you want to communicate information about identifiers, store the information in the identifier itself using define-syntax and a struct that implements either prop:procedure or prop:rename-transformer, depending on whether non-tool users of the identifier need to use syntax-local-value on it. In that case, tools can get the stashed information instead of the original binding using syntax-local-value/immediate .


notjack
2021-1-5 02:06:10

Try to avoid global mutable identifier hash tables if you can, but don’t stress too badly if there’s no other way to annotate identifiers you don’t control.


scottclark11
2021-1-5 02:14:48

@scottclark11 has joined the channel


kellysmith12.21
2021-1-5 02:29:48

I have learned that macros don’t behave the same in the REPL as they do in a file.


kellysmith12.21
2021-1-5 02:31:04

Is that part of, “the top level is hopeless”, or is a separate thing?


notjack
2021-1-5 06:26:08

Yup that’s the top level being hopeless