p.kushwaha97
2020-1-27 08:03:11

Is there a catch-all type in typed-racket which subsumes both lists and sets? Something like java’s Collection type


deactivateduser60718
2020-1-27 14:14:12

Thank you! Also, here’s a doc preview before the online docs are done. (EDIT: Thread has re-upload of this PDF with fixes)


soegaard2
2020-1-27 14:18:38

> (Remember #NAME? , etc. in Excel?) Nope. Don’t remember #name?.


soegaard2
2020-1-27 14:27:51

Other than that - excellent documentation.


deactivateduser60718
2020-1-27 14:30:25

There’s some minor errors in there to patch up. Appreciate the feedback too, thank you!


deactivateduser60718
2020-1-27 15:11:13

Re-upload with changes:

• Fixed typos • Added clarification that only necessary work is done on a refresh. • Added defproc for discovery-phase? • Changed mention of #NAME? to something clearer


soegaard2
2020-1-27 15:34:43

What’s this character called?


deactivateduser60718
2020-1-27 15:41:39

Reference mark. It’s like an asterisk in the context of footnotes, except you’d find it in Eastern texts. https://en.wikipedia.org/wiki/Reference_mark


florence
2020-1-27 15:42:02

Taking a quick look, you might be able to adapt my continuation make trick from datacell to get (dynamic) cycle detection, instead of having a depth limit: https://github.com/florence/datacell/blob/master/private/cell.rkt#L40\|https://github.com/florence/datacell/blob/master/private/cell.rkt#L40


deactivateduser60718
2020-1-27 15:42:24

@florence I was wondering if there was a better way to do that. Thank you!


florence
2020-1-27 15:45:38

There might actually be a better way to do it, such that you allow cycles if they stabilize. Let me see if i can find the paper…


deactivateduser60718
2020-1-27 15:46:25

I figured it was like a case of the halting problem and that any solution would be empirical. I’d love to see this


deactivateduser60718
2020-1-27 15:48:41

I’ll also put in a link to datacell in the docs for comparison so that others can weigh it when choosing a library.



florence
2020-1-27 15:50:22

There are lots of approximations: if the data forms a semitlatice it should always stabilize.

I wrote datacell in like 30 minutes it probably not very good and missing lots of features :P


deactivateduser60718
2020-1-27 15:52:31

Thank you for the paper! I’m not at post grad reading level, so what are some of these notations called? No need to explain what they are, but I have some homework to do before I can understand this paper


florence
2020-1-27 15:54:44

Oof… not sure what the names of a lot of that is. They have code somewhere let me find it…


florence
2020-1-27 15:57:04

Ug the new DL interface is terrible. @samth is there a convenient gh repo for this paper somewhere?


deactivateduser60718
2020-1-27 15:58:29

If I can add on: @soegaard2 you had actually sent me Martin Erwig’s functional graph paper and I had trouble in some sections there as well. I guess my question is a bit more general: What would you advise a CS student with a Bachelor’s to learn to be able to understand most CS research papers? If I’m going to run into more papers, I’d really love to be able to understand them as intended.



soegaard2
2020-1-27 16:07:03

@deactivateduser60718 You sort of pick up on the notation after a while. (You also learn which sections to skip). For semantics I learned a lot from LiSP by Queinnec. Sometimes it helps to know a little Haskell or SML.


samth
2020-1-27 16:48:16

There’s Sequence


greg
2020-1-27 17:55:48

Hi, all. I’ve been off Slack — generally, not just Racket’s — for what feels like a few months. I’m back, somewhat selfishly because I have a question.


greg
2020-1-27 17:56:23

This is long for a Slack post, so first the TLDR:

Is there an equivalent of namespace-mapped-symbols and identifier-binding for when you don’t have a module->namespace namespace? And instead merely have fully expanded syntax in some namespace?

Given some module with #%require s, I want to be able to enumerate all those imports, and, find where they are defined — without using module->namespace.


greg
2020-1-27 17:57:27

[[Oh great, I heard about the Slack-no-markdown thing. Hunting through the options to fix that…. fixed.]]


greg
2020-1-27 17:58:54

The background:

The last few weeks, I’ve been working on having Racket Mode make better use of drracket/check-syntax.

Before: racket-check-syntax-mode has been a limited read-only thing. You turn it on, and you can navigate defs and uses, and rename things. But you have to disable it to do general editing again.

After: It would work more like background check-syntax in DrRacket. You can just edit, and after some idle timer delay, annotations refresh.

Before: Previously, racket-mode has relied on you having a live module->namesapce — i.e. you did a racket-run of the buffer you’re editing — to supply some feature likes visit-definition and completion.

After: I’d like racket-mode itself to no longer even attempt any of that. Instead, such features would come from racket-check-syntax-mode, and drracket/check-syntax. Benefit: You need not run your file, and side-effects of doing so. (Also benefit: I know some people who use racket-mode only for editing, and do racket in a terminal. They could not enable racket-check-syntax-mode to run alongside racket-mode, and they wouldn’t even need the “back end server” part. It would a simple, passive, Emacs major mode.)

So far so good. Nothing is merged to master yet, and probably won’t be for awhile. The UX seems pretty good to me, modulo various nits that can be fixed.

However. I have noticed one theme. drracket/check-syntax only knows about bindings — about definitions that are actually used. This matters for things like completion candidates — including fancy company-mode that can give you visit-definition for completion candidates. Remember, completion as a feature is to avoid typing the names of things that are available. Very often you want that to work the first time you are going to use something.

  1. You might think that syncheck:add-arrow/name-dup/pxpy would be a great source of completion candidates for module definitions. But those don’t exist for unused definitions, because DrRacket doesn’t draw arrows to something from nothing. :) Instead a better source is syncheck:add-mouse-over-status annotations with a “bound occurrence(s)” text (the “no bound occurrences” ones are the ones that are missing, that don’t need arrows).

  2. Similarly, the syncheck:add-jump-to-definition annotations seems like a great source of completion candidates for imported definitions. But again, they only exist for imported definitions that are already used — not all that could be.

In both cases, the theme is completion candidates is a bigger set — things that could be used, even if they aren’t yet.


greg
2020-1-27 17:59:11

So I’ve been working on supplementing what drracket/check-syntax supplies. (Someday I could propose a PR to that, but for now I’m just trying to figure things out, and, make something that works with older versions of Racket.)

So far, I have been able to get the list of imports by parsing the #%require syntax, using module->exports, and replicating the set logic for prefixes, renames, and except-ins.

So I do have a list of completion candidates. “It works”.

Where I am stumped is, supporting the fancy company-mode feature, where, for each candidate, I could also supply the location. That is, identifier-binding doesn’t seem to work unless there is already a binding for the import. What do I do?

(I started to experiment with making some skeleton module, just inserting uses of each import (i.e. making “dummmy” bindings, so that identifier-binding could find those). But I’m not having luck, initially, plus it seems like a kind of smelly approach, and I must be overlooking some better way.)


soegaard2
2020-1-27 18:07:14

Welcome back! Tricky questions.

What are the rules of the game? We are editing a file in racket-mode and during editing, we like to get a list of completion candidates. Does the “when you don’t have a module->namespace namespace” mean that we can’t run the file we are in (including using symbols from previous runs)?


greg
2020-1-27 18:35:31

Hi @soegaard2! Yes, from a user POV it means you no longer need to racket-run the buffer you’re in. You will get accurate completion candidates and visit-definition will work correctly.


greg
2020-1-27 18:39:23

I have that already working, on my branch. It’s handy when you’re editing. It’s also handy when not editing — when just viewing/exploring some set of code files. I mean, for example, amusingly I’ve found it handy to navigate the source files for drracket/check-syntax itself. :smile: In the old approach, you had to visit a new file, run it, and only then would you get accurate visit-definition. Because the old way depends on having a namespace from module->namespace that’s “in” that file. Whereas the drracket/check-syntax approach depends on merely expand-ing the file. So (if my terminology is correct), the file’s module is merely declared but not instantiated.


greg
2020-1-27 18:41:35

What I would like is for identifier-binding to work with such a namespace, in which a module was merely expanded. (It would be nice if namespace-mapped-symbols also worked in such a namespace, but, I’ve already got its equivalent by walking #%require forms to make a set of imports that is ~= to what that would say, if it worked for such a namespace).


greg
2020-1-27 18:42:11

So the missing piece, for me right now, is really just identifier-binding in a merely-expanded module namespace.


greg
2020-1-27 18:44:34

That way, I can have not just a list of completion candidates, but, a list of tuples — the candidate and where to find it. Which supports a nifty company-mode feature, to visit the definition of a completion candidate. So, I mean, I’m kind of getting into nice-to-have feature territory. But it’s something that worked with the old approach, so I’d like to keep it in the new approach. And also I’m just curious, how really does identifier-binding work — or not — namespaces created in these different ways.


samth
2020-1-27 18:46:51

@greg I think you may want to use some tricks that @mflatt set up for me in Typed Racket.



greg
2020-1-27 18:50:26

Oh wow Quick glance that looks promising (and also unlikely I ever would have figured that out on my own :smile:). Thanks @samth and @mflatt I’ll try working with that!


samdphillips
2020-1-27 18:53:27

@samth is probably a better person to discuss this with (I’m merely a TR user.) From my perspective it makes sense that if a contract cannot be generated then it is unsafe to use in untyped code. And part of the reason to use TR is safety.


mflatt
2020-1-27 18:54:41

For the code that @samth references, syntax-binding-set and syntax-binding-set->syntax is the modern, more-direct solution.


samth
2020-1-27 18:55:11

Should I change TR to use that?


mflatt
2020-1-27 18:55:22

I haven’t yet understood how it’s relevant to the problem that you describe, though, @greg.


mflatt
2020-1-27 18:55:30

@samth: Yes, probably.


samth
2020-1-27 18:56:53

I think a short summary of the problem is that if you have a namespace in which you’ve expanded a module, how do you create an identifier that appears to be inside that module


greg
2020-1-27 18:57:34

That you could give to identifier-binding and it would work.


mflatt
2020-1-27 18:57:46

Ok, good! :slightly_smiling_face:


greg
2020-1-27 19:00:49

I mean I felt like that was a bit of a roundabout hack that I’d come up with, in the first place. “Given some expanded modules, extract its #%require s into a new skeleton module syntax in a fresh namespace, and glom in some uses of all imports, so that identifier-binding will work.” How to “glom in uses”, is what Sam was trying to answer. But @mflatt if my whole strategy is a big smell, of course please don’t hesitate to let me know. :slightly_smiling_face:


greg
2020-1-27 19:03:47

I guess if identifier-binding is really “identifier-actual-binding”, I am trying write “identifier-possible-even-if-not-yet-actual-binding”.


greg
2020-1-27 19:13:08

Really just given some starting point, “I know module-path M provides var or stx ID”, I want to run down the chain of (re)provides until I get to the defining source. identifier-binding the way I know how to do this, with module->namespace. But maybe I should just chase it down myself using say module->exports and module->imports….


notjack
2020-1-27 19:58:20

@greg If you want to chase it down like that, you might get some use out of these module reflection utilities I wrote: https://docs.racket-lang.org/rebellion/Module_Bindings.html



samdphillips
2020-1-27 20:03:54

OK the plot thickens. I was putting together info for an issue, and I found if I use the user scope it works. I was installing using the installation scope when it failed.


samdphillips
2020-1-27 20:04:41

Aha


samdphillips
2020-1-27 20:05:13

It’s because the binary package catalog was setup for the user scope and not the installation scope


greg
2020-1-27 20:11:38

@notjack Thanks, I’m already up-to-speed on using module->exports. But you’ve provided a really clean and well-named wrapping around that!


notjack
2020-1-27 20:29:01

thanks!


notjack
2020-1-27 20:29:18

!


notjack
2020-1-27 20:29:39

Huh, why should the installation scope matter? Weird


notjack
2020-1-27 20:31:43

I’ve never looked into the theory of these kinds of libraries so this might be a naive question but: why allow cycles at all? Even if they’re stable, they seem like they would lead to a great deal of user confusion.


notjack
2020-1-27 20:32:21

Are there important use cases that require cycles?


florence
2020-1-27 20:36:25

Any stabilizing program cycle can be transformed in to an acyclic graph, but that transformation is 1: non-local, and 2: as bad as O(n^2). But youre right in general, most practical implementations rule out cycles either statically or dynamically. (this can be non-trivial though). What you want depends on the problem domain really


florence
2020-1-27 20:37:20

For example in the hardware world, cycles can be very useful for minimizing circuits. In Esterel there are some control problems that are a pain to express with cycles. But AFAIK in the FRP&Dataflow world cycles are usually disallowed.


florence
2020-1-27 20:39:39

(Cycles are also easier to reason about in the hardward and esterel world because your latice of values contains only three elements, meaning you can statically determine if something will stabilize. Not true for general dataflow)


deactivateduser60718
2020-1-27 20:53:11

(+cc @notjack) Alright, so I’m working on a macro as shown here: https://github.com/zyrolasting/kinda-ferpy/issues/2

I’m trying to translate a list of syntax objects a form that I can splice into a template. I’m still learning the various transitions between pattern variables and templates. Here’s some broken code so you can see the direction I’m headed.

(define-syntax (stateful-cell stx) (define stx-e (syntax-e stx)) (define-values (dependency-options unused) (parse-keyword-options (cdr stx-e) (list (list '#:dependency check-identifier check-identifier)) #:context #'stateful-cell)) (with-syntax ([requested-dependency-bindings (map (λ (spec) (drop spec 2)) dependency-options)] [body unused]) (make-stateful-cell (λ () (let (requested-dependency-bindings ...) body ...))))) I know this isn’t valid because with-syntax has bindings to plain lists of syntax objects. What do I have to change to make the ...s as shown in the body make sense?


deactivateduser60718
2020-1-27 21:00:12

Ah, I think I’ve got it. It’s closer than I thought. Don’t help me just yet, I want to see if I got this.


samdphillips
2020-1-27 21:29:56

My guess is that there are different configuration settings for each scope.


samdphillips
2020-1-27 21:30:51

The only reason I was using installation scope was that I figured it’s a docker container there should only be one set of packages, let’s just put them all in one place.


notjack
2020-1-27 21:44:02

@deactivateduser60718 I highly recommend using define-simple-macro for this. Feel free to get something working first before trying that however.


deactivateduser60718
2020-1-27 21:45:52

Yep, I already can tell cleanup is desperately needed. I got something working, and ended up here:

(define-syntax (stateful-cell stx) (syntax-case stx () [(_ code ...) (let-values ([(parsed-options unused) (parse-keyword-options #'(code ...) (list (list '#:dependency check-identifier check-identifier)) #:context #'stateful-cell)]) (with-syntax ([(requested-dependency-bindings ...) (map (λ (spec) (with-syntax ([orig/id (third spec)] [body/id (fourth spec)]) #'(body/id (orig/id)))) parsed-options)] [(body ...) unused]) #'(make-stateful-cell (λ () (let (requested-dependency-bindings ...) body ...)))))]))


deactivateduser60718
2020-1-27 21:47:56

Example expansions: main.rkt> (expand-once #'(stateful-cell 1)) #<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let () 1)))> main.rkt> (expand-once #'(stateful-cell #:dependency a other (if other 1 2))) #<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let ((other (a))) (if other 1 2))))> main.rkt> (expand-once #'(stateful-cell #:dependency a other #:dependency b more (if other 1 2))) #<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let ((other (a)) (more (b))) (if other 1 2))))>


deactivateduser60718
2020-1-27 21:48:58

The only reason I went this far was because I didn’t see a single pattern spec I could use to capture zero or more #:keyword id id followed by one or more of any expression.


deactivateduser60718
2020-1-27 22:10:12

I posted a comment in the GitHub issue thread so I don’t eat up too much space here.


soegaard2
2020-1-27 22:24:50

FWIW syntax-parse has patterns for matching zero or more#:keyword id id`` . Can’t quote chapter and verse though.


deactivateduser60718
2020-1-27 22:42:23

To @notjack’s point, define-simple-macro uses syntax-parse. I didn’t read that part of the manual yet since I’d like time to digest what I already learned.


deactivateduser60718
2020-1-27 22:44:46

This is a pretty amazing, yet information-dense system!


asumu
2020-1-27 23:30:04

So I’ve wanted a function to use with slideshow to draw text sized with a proportion of slide size, but is there a better way to do that than binary search? https://gist.github.com/takikawa/bd1cb0563bdf7a76cb88105b2e354b40


soegaard2
2020-1-27 23:45:33

You can use get-text-width which computes the width of a space to make an initial guess closer to the result than just a huge range from 0 to 1000.


soegaard2
2020-1-27 23:45:53

Not a huge improvement though.


asumu
2020-1-27 23:55:55

Yeah, the initial guess is definitely a bit silly. :stuck_out_tongue: That’s a good idea.


notjack
2020-1-28 00:54:12

Hmm, then to me it definitely sounds like a general purpose library would be better off disallowing cycles and leaving that use case to other, narrower libraries targeted specifically at hardware design


ben
2020-1-28 01:03:56

do fonts come with properties like “here’s the width of one M”?


soegaard2
2020-1-28 01:22:37

The method get-text-extent can be used to find the size of a string (due to ligatures it is not enough to add the width of each character).

Maybe @asumu can use it?

But it seems Asumu also wants to rotate the text, which complicates things further.

https://docs.racket-lang.org/draw/dc___.html?q=get-text#%28meth._%28%28%28lib._racket%2Fdraw..rkt%29._dc~3c~25~3e%29._get-text-extent%29%29


asumu
2020-1-28 01:23:58

The initial version of this that I wrote did a binary search with get-text-extent but it’s easier (though I’m sure less efficient) to use text to support its richer interface.


asumu
2020-1-28 01:24:51

(constructing font% objects is kinda tedious, but you have to do it to vary the sizes with get-text-extent)


philip.mcgrath
2020-1-28 01:31:58

I’ve just now gotten the same error in another file while documenting the removal of my find-executable-path.


greg
2020-1-28 03:04:24

@mflatt @samth I was still struggling with this until I realized that identifier-binding needed to be given a piece of syntax from the expanded syntax. Then I spent some time wrestling with how to parse the expanded syntax to find the bit with the indentifier of interest, that I’d inserted. Given what fully-expanded syntax can do, this was looking pretty gross. Then through some process of free-association, desperation, and luck, I came across: 12.9.1 Information on Expanded Modules and the 'module-body-context syntax property. (identifier-binding (datum->syntax module-body-context 'some-imported-id)) seems to work! That does need you to expand some syntax that you make up on the fly that require s the module exporting some-imported-id, and, the expansion seems to need with-module-reading-parameterization etc. in order for identifier-binding to be happy about instantiating things. But it seems waaaay simpler than I feared. However I will work with it some more to be sure.


greg
2020-1-28 03:07:28

p.s. I had tried things like namespace-syntax-introduce and namespace-symbol->identifier, but neither produced syntax that identifier-binding was able to use to do its magic. So far, only using that 'module-body-context syntax property seems to be the proper lexical context.


greg
2020-1-28 03:12:38

p.p.s. The 'module-direct-requires and 'module-direct-for-syntax-requires syntax properties looked interesting. They seemed like they might be a slightly simpler alternative to using module->exports. But (a) they always seem to be #f for me and (b) I do need to parse the #%require syntax anyway to determine what the “net” imports are, taking into account except-in prefix-in rename-in etc. … and that code is already written and working :slightly_smiling_face:


mflatt
2020-1-28 03:40:29

It looks like those properties got lost in the expander rewrite. At this point, possibly we should just remove them from the documentation; apparently, no one has missed the properties for the couple of years.


greg
2020-1-28 04:17:30

Ah OK. Well, I’m super happy that 'module-body-context did not get lost — that turned out to be just what I needed!