soegaard2
2020-6-7 12:07:01

I have an _ that goes missing in the rendering - any ideas? The result:


soegaard2
2020-6-7 12:07:12

@(defstruct flomat ([m natural?] [n natural?] [a _flomat] [lda natural?]))


soegaard2
2020-6-7 12:07:32

The _ in a : _flomat is missing.


mflatt
2020-6-7 12:12:21

Absent a binding, _ at the start of an identifier is treated as a request to typeset in italic. The solution may be a (require (for-label ...)) so that _flomat is bound.


soegaard2
2020-6-7 12:12:52

Thanks!


capfredf
2020-6-7 13:50:45

I kind of wanted something to check the existence of a module without actually loading it.


soegaard2
2020-6-7 16:25:16

I have added a new section to the documentation of flomat in order to describe the representation. Is it clear?

https://docs.racket-lang.org/manual-flomat/index.html?q=flomat#%28part._.Reference%29


soegaard2
2020-6-7 20:01:19

Am I missing something? I can find _float _double and _longdouble in the ffi - but I can’t find _complex .


soegaard2
2020-6-7 20:09:55

Yes - I am missing something - complex numbers in C aren’t handled the same way float, double and longdouble is. https://en.wikipedia.org/wiki/C_mathematical_functions#complex.h



samth
2020-6-7 20:47:37

Haven’t they added _Complex recently?


soegaard2
2020-6-7 20:48:09

Yes. In ’99 but as a type modifier.


soegaard2
2020-6-7 20:48:40

So you can have complex numbers where the real and imaginary parts are singles, doubles or longs.


alexharsanyi
2020-6-7 22:18:20

you can check if the module name can be resolved.


i.am.corpix
2020-6-8 00:17:09

Is there a correct way to clone a namespace? I am building some sort of with operator in racket… so I need to eval code in namespace which contains customized bindings, but as I can see there is no function to clone namespace. I have made my own: (define (namespace-copy! dest base) (begin0 dest (for ((key (in-list (namespace-mapped-symbols base)))) (let ((value (namespace-variable-value key #f void base))) (when (not (void? value)) (namespace-set-variable-value! key value #f dest)))))) But here is a problem, it can not copy macro from source namespace(their (namespace-variable-value <key> #f void namespace is just #<void>), so this method is incomplete. I have found an old discussion which mentions this topic, but no solution was proposed https://groups.google.com/forum/#!msg/racket-users/rRC2rKBAr7c/KHKHq4yBBpcJ

So, is there a correct way to clone a namespace? Thank you :)


i.am.corpix
2020-6-8 00:40:55

Example which illustrates the current namespace-copy! implementation problem http://pasterack.org/pastes/23019


samth
2020-6-8 02:23:43

Probably this is a case where understanding what you want to accomplish is necessary to figure out the right way forward.


i.am.corpix
2020-6-8 02:42:40

My goal is to call code in an environment where some of the bindings could be shadowed.

I want to derive a new namespace from (current-namespace) where I could define any bindings I like(for example shadow some functions), then use it to eval some code and discard namespace after that.

For example: I may have a function which do some job (define (show x) (displayln x)) But I want to make it work in a different way when calling code wrapped into some macro, example: (show "test") ;; -> test (with ((show (lambda (x) (display "[info]: ") (show x)))) (show "test")) ;; -> [info]: test I think the correct solution here is eval, and this is why namespaces’ have come onto my mind. Just copy a namespace and shadow some symbols inside, what could go wrong? :)


rokitna
2020-6-8 03:03:18

What makes with different from let?


i.am.corpix
2020-6-8 03:05:05

In my case body could be provided by user


i.am.corpix
2020-6-8 03:05:39

I mean it’s an argument


rokitna
2020-6-8 03:07:51

How about taking that input, wrapping it in a let form to establish the custom bindings, and the evaluating it (in an uncustomized namespace)?


rokitna
2020-6-8 03:08:08

and then*


i.am.corpix
2020-6-8 03:34:19

Hmmm, thats an interesting point of view. And it is working: #lang racket (require racket/syntax (for-syntax racket/base racket/syntax)) (define-syntax (with stx) (syntax-case stx () ((_ ((k v) ...) body ...) (syntax (eval (quote (let ((k v) ...) body ...))))))) (define-syntax (decorate stx) (syntax-case stx () ((_ v) (syntax (string-append "*" v "*"))))) (define (show x) (displayln x)) (define-namespace-anchor anchor) (parameterize ((current-namespace (namespace-anchor->namespace anchor))) (show (decorate "test")) (with ((show (lambda (x) (display "[info]: ") (show x)))) (show (decorate "test")))) Is this a part of motivation for not doing namespace-copy/clone? Ha-ha, just kidding. I really love this solution, thank you!


rokitna
2020-6-8 03:47:33

Hmm, you said you’re taking user input for the body of the with, but that looks like it’s part of the code. Unless you’re actually inputting the code at run time, you can probably avoid eval. I guess I’m not sure what you’re what you’re trying to do, but congrats on being unstuck.

(Personally, sometimes I’ve wanted to copy namespaces too. I don’t know the reasoning behind the current design.)


rokitna
2020-6-8 04:00:54

(In this case, it seems you can avoid eval by just defining with to do the same thing as let: (define-syntax-rule (with args ...) (let args ...)))


i.am.corpix
2020-6-8 04:04:07

Yes, eval here is useless.

What could also be interesting is to make the scope completely dynamic, but in this case namespace manipulation is the only possible way I could think about