shu--hung
2018-11-27 20:20:08

At compile-time, maybe syntax parameters can help. Here’s a nice introduction by greg http://www.greghendershott.com/fear-of-macros/Syntax_parameters.html


bkovitz
2018-11-27 20:32:31

Thanks! Now checking it out…


samth
2018-11-27 20:33:27

@bkovitz I think the easiest thing to do is not to do it at compile time


samth
2018-11-27 20:33:44

just have a variable that holds the current graph and update it mutably


bkovitz
2018-11-27 20:33:47

Indeed the version I’ve got working does it at run-time. :wink:


lexi.lambda
2018-11-27 20:34:35

(Or, if you don’t want to mutate, use a state monad. :grimacing:)


bkovitz
2018-11-27 20:35:14

Uh oh. I realize that what I’m asking for is almost a state monad. Whenever I’ve tried to do anything with monads, though (not in Racket), I’ve gotten burned.


bkovitz
2018-11-27 20:35:41

Mostly I just want clean syntax that isn’t error-prone.


bkovitz
2018-11-27 20:36:51

I’ve been avoiding mutating the graph because, with all sorts of intricate variations on a graph floating around, I’m hoping to stay away from bugs resulting from inadvertently referring to the wrong graph.


lexi.lambda
2018-11-27 20:37:03

My comment was a bit of a joke; you probably don’t want to do monads in Racket.


bkovitz
2018-11-27 20:37:10

Ah, good. :slightly_smiling_face:


samth
2018-11-27 20:37:56

@bkovitz I’m not suggesting mutating the graph, just have a variable which you mutate which is the current graph


bkovitz
2018-11-27 20:38:16

Hmm, it looks like syntax-parameters might solve a different problem than what I’m looking for.


bkovitz
2018-11-27 20:38:54

@samth Ah, good. In fact, the thing I’ve been using, a little macro called gdo, does exactly that.


bkovitz
2018-11-27 20:39:37

Ohh, and now I see how syntax-parameters might apply, since then I’d using a sort of anaphoric graph.


bkovitz
2018-11-27 20:42:02

Continuing the original line of thought, though, how can you associate some metadata with an identifier at compile-time?


lexi.lambda
2018-11-27 20:42:52

I think it depends on what you mean. Do you want to associate some metadata with a binding, or literally with an identifier?


shu--hung
2018-11-27 20:44:12

For syntax-parameters, what I’m thinking is that there is a fixed parameter where with-graph could stash the current identifier inside, and define/g could lookup that parameter to decide whether to set! or return new result


shu--hung
2018-11-27 20:44:59

arr, that might be problematic (scope issue)


shu--hung
2018-11-27 20:46:09

maybe not, if define/g expands to (set! g (make-node ... g ...))


lexi.lambda
2018-11-27 20:48:18

If with-graph where to syntax-parameterize g, then (syntax-local-value #'g) from inside the lexical region would, indeed, find the parameterized value for g.


bkovitz
2018-11-27 20:48:19

@lexi.lambda I’m not sure (even about the terminology). I’ve got two ideas for how to use it. First idea: Let (define/g (value-of g node) ...) define value-of to have this bit of metadata added: “I’m a graph function”. Then the (with-graph ...) macro could recognize an application of value-of inside its body and rewrite it with the correct arguments (as in the example above). (The more I think about this, though, the more I think it really wants to be a sort of custom eval.)


bkovitz
2018-11-27 20:49:06

Second idea: You tag functions with the meanings of their arguments and return values (like types), you put all these functions into a set, and a compositor function composes them into a single function in the correct way.


lexi.lambda
2018-11-27 20:49:44

I think you probably don’t want to do that kind of thing, where a macro like with-graph walks its body. (I think those are sometimes called “deep walking macros”, but they are extraordinarily hard to get right.) Instead, make value-of defined as a macro that does the transformation itself, and make with-graph install some static information (via syntax parameters or otherwise) that macros defined with define/g inspect.


bkovitz
2018-11-27 20:50:49

Hmm, defining value-of as a macro rather than a function might make a lot of sense. Thanks. I’ll give this some thought.


bkovitz
2018-11-27 21:03:19

@shu—hung I hadn’t thought of making define/g do the set!. Up until now, I’d been thinking that “g-functions” would only be functions. Thanks—new line of thought.


bkovitz
2018-11-27 21:22:09

Say, where can I find the source code to eval?


lexi.lambda
2018-11-27 21:24:03

Technically, somewhere in the expander, but I don’t imagine looking at it will be very helpful. :)


bkovitz
2018-11-27 21:24:37